Speeding Up the Web
One thing everyone wants is faster access to their Web sites. Popular sites can slow down to a crawl during high-traffic times, and nothing is more frustrating than having people on your LAN telling you they pulled the site up without problems a few minutes earlier.
Code listing 12.8. Installing Squid on Fedora Core.
[root@dhcppc1 ~]# up2date --install squid
http://fedora.redhat.com/download/
up2date-mirrors/fedora-core-3
using mirror: http://fr.rpmfind.net/
linux/fedora/core/3/i386/os
http://fedora.redhat.com/download/up2date-mirrors/updates-released-fc3
using mirror: http://sunsite.informatik.
rwth-aachen.de/ftp/pub/linux/fedora-core/
updates/3/i386/
...
[root@dhcppc1 ~]# chkconfig squid on
[root@dhcppc1 ~]# service squid start
One way to reduce traffic to popular sites but still give access to the information is to run a cache, like Squid. Then people can configure their Web browsers to use the cache as a proxy, and it stores the pages they visit. The next person who requests a cached page gets it right away from the cache, instead of having to download it across the Internet. Although Cygwin has a Squid package, it doesn't work with the current versions of the Cygwin core shared libraries.
To install Squid (Fedora Core)
The up2date command will provide us with a binary distribution of Squid.
1. | Log in as root, or use su to become root. | 2. | up2date --install squid Install Squid (Code Listing 12.8) from the binary repository. | 3. | chkconfig squid on Add Squid to the list of services to start at boot time. | 4. | service squid start Start the Squid server. |
To install Squid (FreeBSD)
FreeBSD's excellent ports system includes Squid, so we'll have no trouble installing it on this OS.
Code listing 12.9. Installing Squid on FreeBSD.
bsd# cd /usr/ports/www/squid
bsd# make install clean
...
===> Vulnerability check disabled, database not found
===> Found saved configuration for squid-2.5.7_3
>> squid-2.5.STABLE7.tar.bz2 doesn't seem to exist in /usr/ports/dist/image/library/english/13776_squid2.5.
>> Attempting to fetch from ftp:// ftp.squid-cache.org/pub/squid-2/STABLE/.
...
bsd# rehash
bsd# squid -z
1. | Log in as root, or use su to become root. | 2. | cd /usr/ports/www/squid Change to the Squid directory in the ports system (Code Listing 12.9). | 3. | make install clean Tell the ports system to build and install Squid, and then clean up after itself. The ports system displays the "Options for squid 2.5.7_3" dialog (Figure 12.6).
Figure 12.6. Squid options on FreeBSD.
| 4. | Press the up and down arrow keys to move the cursor, then press the spacebar to select (or deselect) the highlighted item. Unless you know you need one of these options, go with the defaults. | 5. | Press Tab and then Enter to exit the "Options for squid 2.5.7_3" dialog and continue. | 6. | squid -z Initialize the Squid cache directories. | 7. | Use your favorite text editor to add the following line to /etc/rc.conf:
squid_enable="YES"
| 8. | /usr/local/etc/rc.d/squid.sh start Start the Squid server. |
To install Squid (Mac OS X)
On Mac OS X, Fink includes a Squid port.
Code listing 12.10. Installing Squid on Mac OS X.
bender:~ chrish$ fink install squid
Password:
Information about 4201 packages read in 5 seconds.
...
Setting up squid (2.5.stable5-1) ...
2004/12/09 23:14:01| Creating Swap Directories
bender:~ chrish$ cd /Library/StartupItems
bender:~ chrish$ sudo mkdir Squid
bender:~ chrish$ cd Squid
bender:~ chrish$ sudo vi Squid
...
bender:~ chrish$ sudo chmod +x Squid
bender:~ chrish$ sudo vi StartupParameters.plist
...
bender:~ chrish$ ./Squid start
1. | Open a Terminal. | 2. | fink install squid Tell Fink to install Squid (Code Listing 12.10). | 3. | Enter your password at the Password prompt, then press Enter to continue.Fink downloads and installs Squid. | 4. | cd /Library/StartupItems Change to the startup-items directory so that we can create a startup script for Squid. | 5. | sudo mkdir Squid Create a directory for Squid's startup files.
Code listing 12.11. A Squid startup script for Mac OS X.
#!/bin/sh
. /etc/rc.common
case $1 in
start)
/sw/sbin/squid
;;
restart)
/sw/sbin/squid -k reconfigure
;;
stop)
/sw/sbin/squid -k shutdown
;;
*)
# Unknown command.
;;
esac
| 6. | cd Squid Change to the Squid startup directory. | 7. | Use your favorite text editor to create the Squid startup script (Code Listing 12.11). If you use a GUI editor, you'll need to create this file somewhere else, and then use sudo cp to copy it here. | 8. | Use your favorite text editor to create the StartupParameters.plist file (Code Listing 12.12). Again, you may need to create it somewhere else and sudo cp it here. | 9. | ./Squid start Start the Squid cache. |
To configure Squid as a Web cache
Despite Squid's many options, a basic Web cache configuration requires only a few settings.
Code listing 12.12. A StartupParameters.list file for Squid on Mac OS X.
{
Description = "Squid web cache";
Provides = ("Web Cache");
Requires = ("DirectoryServices");
Uses = ("Disks", "NFS");
OrderPreference = "None";
}
1. | Log in as root, or use su to become root. | 2. | cd /etc/squid on Fedora Core, or cd /usr/local/etc/squid on FreeBSD, or cd /sw/etc on Mac OS X. Switch to the Squid configuration directory.
Code listing 12.13. A basic Squid configuration file.
# squid.conf file for a web cache
# Define an access control list that
# includes all IP addresses.
acl all src 0.0.0.0/0.0.0.0
# Allow all attempts to access the cache.
http_access allow all
# Run Squid as nobody in the group
# nogroup for improved security.
cache_effective_user nobody nogroup
| 3. | Use your favorite text editor to create the squid.conf file (Code Listing 12.13). | 4. | service squid restart on Fedora Core, or /usr/local/etc/rc.d/squid.sh ] restart on FreeBSD, or /Library/StartupItems/Squid/Squid restart on Mac OS X. Restart Squid to apply your configuration changes. |
|