You are on page 1of 4

Using Squid as a Load Balancer

This article helps you to understand how you can use Squid as a load balancer. It explains the configuration changes required for load balancing on SXDE (Solaris Express Developer Edition).

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 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. 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

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 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 2

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.

Using Squid as a Load Balancer

Copyright 2008 Sun Microsystems, Inc. All rights reserved. Sun Microsystems, Inc. has intellectual property rights relating to technology embodied in the product that is described in this document. In particular, and without limitation, these intellectual property rights may include one or more U.S. patents or pending patent applications in the U.S. and in other countries. U.S. Government Rights Commercial software. Government users are subject to the Sun Microsystems, Inc. standard license agreement and applicable provisions of the FAR and its supplements. This distribution may include materials developed by third parties. Parts of the product may be derived from Berkeley BSD systems, licensed from the University of California. UNIX is a registered trademark in the U.S. and other countries, exclusively licensed through X/Open Company, Ltd. Sun, Sun Microsystems, the Sun logo, the Solaris logo, the Java Coffee Cup logo, docs.sun.com, Java, and Solaris are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. All SPARC trademarks are used under license and are trademarks or registered trademarks of SPARC International, Inc. in the U.S. and other countries. Products bearing SPARC trademarks are based upon an architecture developed by Sun Microsystems, Inc. The OPEN LOOK and SunTM Graphical User Interface was developed by Sun Microsystems, Inc. for its users and licensees. Sun acknowledges the pioneering efforts of Xerox in researching and developing the concept of visual or graphical user interfaces for the computer industry. Sun holds a non-exclusive license from Xerox to the Xerox Graphical User Interface, which license also covers Sun's licensees who implement OPEN LOOK GUIs and otherwise comply with Sun's written license agreements. Products covered by and information contained in this publication are controlled by U.S. Export Control laws and may be subject to the export or import laws in other countries. Nuclear, missile, chemical or biological weapons or nuclear maritime end uses or end users, whether direct or indirect, are strictly prohibited. Export or reexport to countries subject to U.S. embargo or to entities identified on U.S. export exclusion lists, including, but not limited to, the denied persons and specially designated nationals lists is strictly prohibited. DOCUMENTATION IS PROVIDED AS IS AND ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD TO BE LEGALLY INVALID.

Sun Microsystems, Inc. 4150 Network Circle, Santa Clara, CA 95054 U.S.A.

You might also like