Bandwidth-Limiting-HOWTO(1).pdf

(53 KB) Pobierz
Bandwidth Limiting HOWTO
Bandwidth Limiting HOWTO
Tomasz Chmielewski
tch@metalab.unc.edu
Revision History
Revision 0.9
2001−11−20
Revised by: tc
This document describes how to set up your Linux server to limit download bandwidth or incoming traffic
and how to use your internet link more efficiently.
Bandwidth Limiting HOWTO
Table of Contents
1. Introduction. ....................................................................................................................................................1
1.1. New versions of this documen. ........................................................................................................1
1.2. Disclaimer. ........................................................................................................................................1
1.3. Copyright and License. .....................................................................................................................1
1.4. Feedback and corrections. .................................................................................................................1
1.5. Thanks. ..............................................................................................................................................1
2. Before We Start. ..............................................................................................................................................2
2.1. What do we need. ..............................................................................................................................2
2.2. How does it work?. ...........................................................................................................................2
3. Installing and Configuring Necessary Software. ..........................................................................................3
3.1. Installing Squid with the delay pools feature. ...................................................................................3
3.2. Configuring Squid to use the delay pools feature. ............................................................................3
3.3. Solving remaining problems. ............................................................................................................7
3.3.1. Linux 2.2.x kernels (ipchains). .........................................................................................7
3.3.2. Linux 2.4.x kernels (iptables). ..........................................................................................8
4. Dealing with Other Bandwidth−consuming Protocols Using CBQ. ...........................................................9
4.1. FTP. ...................................................................................................................................................9
4.2. Napster, Realaudio, Windows Media and other issues. ..................................................................10
5. Frequently Asked Questions. .......................................................................................................................12
5.2. How do I make wget work with Squid?.. ........................................................................................12
any irc server. ........................................................................................................................................12
5.5. My outgoing mail server is eating up all my bandwidth. ...............................................................13
above?. ...................................................................................................................................................13
5.8. Whenever I start cbq.init, it says sch_cbq is missing.. ...................................................................14
5.9. CBQ sometimes doesn't work for no reason. .................................................................................14
used only by me? ...................................................................................................................................14
something about it?. ..............................................................................................................................15
5.12. Squid's logs grow and grow very fast, what can I do about it?. ....................................................15
only be me?. ...........................................................................................................................................15
6. Miscellaneous. ................................................................................................................................................17
6.1. Useful resources. .............................................................................................................................17
i
184432296.001.png
1. Introduction
The purpose of this guide is to provide an easy solution for limiting incoming traffic, thus preventing our
LAN users from consuming all the bandwidth of our internet link.
This is useful when our internet link is slow or our LAN users download tons of mp3s and the newest Linux
distro's *.iso files.
1.1. New versions of this document
You can always view the latest version of this document on the World Wide Web at the URL
New versions of this document will also be uploaded to various Linux WWW and FTP sites, including the
LDP home page at http://www.linuxdoc.org .
1.2. Disclaimer
Neither the author nor the distributors, or any other contributor of this HOWTO are in any way responsible
for physical, financial, moral or any other type of damage incurred by following the suggestions in this text.
1.3. Copyright and License
This document is copyright 2001 by Tomasz Chmielewski, and is released under the terms of the GNU Free
Documentation License, which is hereby incorporated by reference.
1.4. Feedback and corrections
If you have questions or comments about this document, please feel free to mail Tomasz Chmielewski at
tch@metalab.unc.edu . I welcome any suggestions or criticisms. If you find a mistake or a typo in this
document (and you will find a lot of them, as English is not my native language), please let me know so I can
correct it in the next version. Thanks.
1.5. Thanks
I would like to thank Ami M. Echeverri lula@pollywog.com who helped me to convert the HOWTO into
SGML format and corrected some mistakes. I also want to thank Ryszard Prosowicz prosowicz@poczta.fm
for useful suggestions.
1. Introduction
1
184432296.002.png
2. Before We Start
Let's imagine the following situation:
·
We have 115,2 kbits/s ppp (modem) internet link (115,2/10 = 11,5 kbytes/s). Note: with eth
connections (network card) we would divide 115,2 by 8; with ppp we divide by 10, because of
start/stop bits (8 + 1 + 1 = 10).
· We want web pages to open fast, no matter how many dowloads are happening.
We have some LAN stations and their users are doing bulk downloads all the time.
· Our internet interface is ppp0 .
· Our LAN interface is eth0 .
· Our network is 192.168.1.0/24
·
2.1. What do we need
Believe it or not, shaping the incoming traffic is an easy task and you don't have to read tons of books about
routing or queuing algorithms.
To make it work, we need at least Squid proxy; if we want to fine tune it, we will have to get familiar with
ipchains or iptables and CBQ.
To test our efforts, we can install IPTraf.
2.2. How does it work?
Squid is probably the most advanced HTTP proxy server available for Linux. It can help us save bandwidth
in two ways:
·
The first is a main characteristic of proxy servers −− they keep downloaded web pages, pictures, and
other objects in memory or on a disk. So, if two people are requesting the same web page, it isn't
downloaded from the internet, but from the local proxy.
·
Apart from normal caching, Squid has a special feature called delay pools. Thanks to delay pools, it
is possible to limit internet traffic in a reasonable way, depending on so−called 'magic words',
existing in any given URL. For example, a magic word could be '.mp3', '.exe' or '.avi', etc. Any
distinct part of a URL (such as .avi) can be defined as a magic word.
With that, we can tell the Squid to download these kinds of files at a specified speed (in our example, it will
be about 5 kbytes/s). If our LAN users download files at the same time, they will be downloaded at about 5
kbytes/s altogether, leaving remaining bandwidth for web pages, e−mail, news, irc, etc.
Of course, the Internet is not only used for downloading files via web pages (http or ftp). Later on, we will
deal with limiting bandwidth for Napster, Realaudio, and other possibilities.
2. Before We Start
2
184432296.003.png
3. Installing and Configuring Necessary Software
Here, I will explain how to install the necessary software so that we can limit and test the bandwidth usage.
3.1. Installing Squid with the delay pools feature
As I mentioned before, Squid has a feature called delay pools, which allows us to control download
bandwidth. Unfortunately, in most distributions, Squid is shipped without that feature.
So if you have Squid already installed, I must disappoint you −− you need to uninstall it and do it once again
with delay pools enabled in the way I explain below.
1.
To get maximum performance from our Squid proxy, it's best to create a separate partition for its
cache, called /cache/. Its size should be about 300 megabytes, depending on our needs.
If you don't know how to make a separate partition, you can create the /cache/ directory on a main
partition, but Squid performance can suffer a bit.
2.
We add a safe 'squid' user:
# useradd −d /cache/ −r −s /dev/null squid >/dev/null 2>&1
No one can log in as squid, including root.
3.
We download Squid sources from http://www.squid−cache.org
When I was writing this HOWTO, the latest version was Squid 2.4 stable 1:
4.
We unpack everything to /var/tmp :
5.
# tar xzpf squid−2.4.STABLE1−src.tar.gz
6.
We compile and install Squid (everthing is in one line):
# ./configure −−prefix=/opt/squid −−exec−prefix=/opt/squid
−−enable−delay−pools −−enable−cache−digests −−enable−poll
−−disable−ident−lookups −−enable−truncate −−enable−removal−policies
# make all
# make install
3.2. Configuring Squid to use the delay pools feature
1.
Configure our squid.conf file (located under /opt/squid/etc/squid.conf):
#squid.conf
#Every option in this file is very well documented in the original squid.conf file
3. Installing and Configuring Necessary Software
3
184432296.004.png
Zgłoś jeśli naruszono regulamin