Using Squid as a Load Balancer
Previous

Configuring Squid as a Load Balancer

Squid is integrated with the SXDE (Solaris Express Developer Edition) release. You do not need to install Squid separately. Perform the following steps to configure Squid as load balancer.


Note - DNS servers are name resolution servers that translate host names to IP addresses. Most web servers use DNS servers as their default name resolution servers. If the server uses NIS instead of DNS, it can lead to conflict with Squid, as Squid also uses the DNS by default. Squid can be configured for NIS. The following sample error message appears, when Squid configured for DNS and runs server that uses NIS.

2008/06/11 11:53:08| /etc/resolv.conf: (2) No such file or directory
2008/06/11 11:53:08| Warning: Could not find any nameservers. Trying to use localhost

To Configure Squid

Configure Squid for a site www.foo.com on a web server.

  1. Change to the directory /etc/squid.
  2. Open the squid.conf file in a text editor

    Make the following changes to specify the port for the web site, and to specify the IP address for the web server. By default squid listens to HTTP port 80. Also, specify access controls to allow access to your web site.

    http_port 80 accel defaultsite=www.foo.com

    cache_peer ip.of.server1 parent 80 0 no-query

    acl sites_server_1 dstdomain www.foo.com

    http_access allow sites_server_1

  3. Create a cache directory by typing the following command.

    % /usr/local/squid/sbin/squid -z

  4. Start Squid by typing the following command.

    % /usr/local/squid/sbin/squid -NCd1


    Note - See the logs at /var/squid/logs (especially in the cache.log file) to verify if there are any errors in configuring Squid.


To Configure Squid as a Load Balancer

Restart Squid before you configure it as a load balancer.

This example uses two web servers . Each web server has two web sites. www.foo.com and www.foo.net are on Server 1, and www.test.foo.com and www.test.foo.net are on Server 2. This procedure explains how to configure Squid as a load balancer for each site.

  1. Change to the directory /etc/squid.
  2. Open the squid.conf file in a text editor and make changes as follows.

    cache_peer ip.of.server1 parent 80 0 no-query originserver name=server_1

    acl sites_server_1 dstdomain www.foo.com www.foo.net

    cache_peer_access server_1 allow sites_server_1

    cache_peer ip.of.server2 parent 80 0 no-query originserver name=server_2

    acl sites_server_2 dstdomain www.test.foo.com www.test.foo.net

    cache_peer_access server_2 allow sites_server_2

    cache_peer ip.of.server1 parent 80 0 no-query originserver round-robin

    cache_peer ip.of.server2 parent 80 0 no-query originserver round-robin


    Note - Round-robin algorithm does simple load balancing. The round-robin algorithm places all the jobs in a circular queue with a processing time slot for each job. The processor saves the status of a job after its time slot and resumes processing on its saved state in its next round of processing. This achieves virtual parallel-processing and load-balancing.


Previous