Goal:

Have multiple squid proxy instances running on the same CENTOS/RHEL 6 host with different configurations, and have them start automatically on boot.

Motivation:

Running multiple squid instances is useful to avoid unnecessarily complex configuration files for a single instance, or to segregate traffic, for example if you wish to route development and lab traffic via two different proxy instances.

Prerequisites:

A squid instance already configured and running using default settings on a CENTOS/RHEL 6 host.

Method:

Here we run another instance of squid on the same IP but a different port than the default one, namely 3128; in this how-to I will use XX to designate the port number of any the extra squid instance.

Modifying the squid.conf file

Copy the original squid.conf file and open the copy in a text editor:

ssh <SQUID_HOST>
cp /etc/squid/squid.conf /etc/squid/<SQUIDINSTANCENAME>.conf
chown root:squid /etc/squid/<SQUIDINSTANCENAME>.conf
vi /etc/squid/<SQUIDINSTANCENAME>.conf

Modify or add the following directives in the file:

http_port XX
visible_hostname SQUIDINSTANCENAME #Optional, useful if adding the proxy to DNS as a CNAME
pid_filename /var/run/SQUIDINSTANCENAME.pid
access_log /var/log/squid/SQUIDINSTANCENAME.log squid
cache_log /var/log/squid/SQUIDINSTANCENAME.log

Modifying the sysconfig file

Copy the default sysconfig file and open it up in a text editor:

cp /etc/sysconfig/squid /etc/sysconfig/SQUIDINSTANCENAME
vi /etc/sysconfig/SQUIDINSTANCENAME

Modify the following line to point at the config file created above:

SQUID_CONF="/etc/squid/SQUIDINSTANCENAME.conf"

Modifying the startup script

Copy the original startup script and modify it, so the second instance can be started and stopped:

cp /etc/rc.d/init.d/squid /etc/rc.d/init.d/SQUIDINSTANCENAME
vi /etc/rc.d/init.d/SQUIDINSTANCENAME

Add the following lines to point at the sysconfig file created above:

if [ -f /etc/sysconfig/SQUIDINSTANCENAME]; then
 ./etc/sysconfig/SQUIDINSTANCENAME
fi

Add the following line to point at the configuration file created above:

SQUID_CONF=${SQUID_CONF:-"/etc/squid/SQUIDINSTANCENAME.conf"}

Use chkconfig to add the script to boot up process and confirm it was successfully added:

chkconfig --add SQUIDINSTANCENAME
chkconfig --list #look for SQUIDINSTANCENAME in the list

Testing the new instance runs as expected:

service SQUIDINSTANCE start

If “Starting squid …… OK” appears, you have successfully modified the startup script and are now running a second squid instance on your host.

This procedure can be repeated to run as many squid proxies as desired on a host.