12 July 2012

Using Squid as a Load Balancer

What is Squid?
Squid is a proxy-server that caches internet data. Squid supports the HTTP, HTTPS, and FTP protocols.
Using Squid, you can improve the server response time by caching and reusing frequently-requested web
pages. It improves performance without the need for greater bandwidth. Squid is generally used as a server
accelerator.
You can configure Squid to act as a caching HTTP accelerator. It improves the server performance, network
performance, and security as Squid overcomes disadvantages related with performance. For example, when
the original web server and the original network might be slow and prone to attacks, you can use Squid to
serve traffic requests.
Squid is suited for any operating system including Digital UNIX, IRIX, Solaris, AIX, HP-UX, Linux, FreeBSD,
NetBSD and even OS/2. You can also use it on Windows platform.
What Is Load Balancing?
Load balancing shares the network traffic between two or more servers so that a single server does not get
loaded with requests. Load balancing increases performance and reliability. You can use multiple processors
or multiple threads in a single processor for load balancing.
Load balancing does not require dedicated software and hardware nodes.DNS servers can run the
round-robin algorithm against multiple IP Addresses associated with a single domain name.
Squid is generally used to act as a caching proxy server. It sends client HTTP requests to the proxy server. The
proxy server fetches web pages in accordance with the cache setup, and returns them to the client.
Squid can be used to perform basic round-robin load balancing, and to cache results based on your cache
configuration.
Configuring Squid as a Load Balancer
Squid is integrated with the SXDE (Solaris ExpressDeveloper 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
useDNS servers as their default name resolution servers. If the server uses NIS instead ofDNS, it can lead to
conflict with Squid, as Squid also uses theDNS by default. Squid can be configured for NIS. The following
sample error message appears, when Squid configured forDNS 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.
Change to the directory /etc/squid.
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
1
2
Using Squid as a Load Balancer 2
acl sites_server_1 dstdomain www.foo.com
http_access allow sites_server_1
Create a cache directory by typing the following command.
% /usr/local/squid/sbin/squid -z
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.
Change to the directory /etc/squid.
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.

No comments:

Post a Comment