In server administration, ensuring high availability is a crucial task. High availability refers to a system or component that is continuously operational for a desirably long length of time. When it comes to proxy servers, this is no different. Proxy servers like Squid are often used to handle a large amount of traffic, and any downtime can lead to significant issues.
Squid is a popular proxy server for many reasons. It’s open-source, versatile, and highly configurable. But one of its most significant advantages is its ability to be configured for high availability. This means that even if one instance of Squid fails, another can take over, ensuring that your proxy service remains uninterrupted.
In this tutorial, we will guide you through the process of configuring Squid Proxy Server for high availability on CentOS. This setup will ensure that your proxy server remains operational even if one of your Squid instances encounters an issue. The benefits of this configuration include improved reliability, better performance, and increased uptime.
Before we start, make sure you have Squid installed on your server. If you haven’t, you can refer to our previous tutorial on how to install and configure Squid Proxy Server.
Step 1: Install and Configure Keepalived
Keepalived is a routing software written in C that provides simple and robust facilities for load balancing and high availability to Linux hosts and Linux-based infrastructures. The installation is straightforward with the yum package manager.
yum install keepalived -y
Once installed, you need to configure Keepalived. The configuration file is located at /etc/keepalived/keepalived.conf. Open this file in a text editor.
vi /etc/keepalived/keepalived.conf
In the configuration file, you need to define your virtual IP address and the priority of the current server. The server with the highest priority will be the master server, and the other will be the backup server.
vrrp_instance VI_1 { state MASTER interface eth0 virtual_router_id 51 priority 100 advert_int 1 authentication { auth_type PASS auth_pass 123456 } virtual_ipaddress { 192.168.1.100 } }
In the above configuration, replace “eth0” with your network interface name, “192.168.1.100” with your desired virtual IP address, and “123456” with a password of your choice. The priority of the master server should be higher than the backup server.
After you’ve made the changes, save and close the file. Then start and enable Keepalived.
systemctl start keepalived systemctl enable keepalived
Repeat this step on your backup server, making sure to set the state to BACKUP and the priority to a lower number than on your master server.
Step 2: Configure Squid for High Availability
Once you have Keepalived set up, you need to configure Squid to work with it. The main configuration file for Squid is located at /etc/squid/squid.conf. Open this file in a text editor.
vi /etc/squid/squid.conf
In the configuration file, you need to set the http_port directive to your virtual IP address and the desired port number.
http_port 192.168.1.100:3128
Replace “192.168.1.100:3128” with your virtual IP address and the port number you want Squid to listen on.
After you’ve made the changes, save and close the file. Then restart Squid for the changes to take effect.
systemctl restart squid
Repeat this step on your backup server.
Step 3: Test Your Configuration
Now that you have Squid and Keepalived configured, it’s time to test your setup. First, check the status of Keepalived.
systemctl status keepalived
If everything is set up correctly, you should see that Keepalived is running and that one of your servers is the master and the other is the backup.
Next, test your Squid configuration. You can do this by setting your browser’s proxy settings to your virtual IP address and the port number you specified in the Squid configuration file. Then try to access a website. If you can access the website, your Squid proxy server is working correctly.
To test the high availability, you can stop the Squid service on your master server.
systemctl stop squid
Then try to access a website again. If you can still access the website, your high availability setup is working correctly. The traffic should be routed through your backup server.
Don’t forget to start the Squid service on your master server again.
systemctl start squid
Commands Mentioned:
- yum install keepalived -y – This command installs the Keepalived package on your CentOS server. Keepalived provides simple and robust facilities for load balancing and high availability to Linux hosts and Linux-based infrastructures.
- vi /etc/keepalived/keepalived.conf – This command opens the Keepalived configuration file in a text editor.
- systemctl start keepalived – This command starts the Keepalived service.
- systemctl enable keepalived – This command enables the Keepalived service to start on boot.
- vi /etc/squid/squid.conf – This command opens the Squid configuration file in a text editor.
- systemctl restart squid – This command restarts the Squid service, applying any changes made to the configuration file.
- systemctl status keepalived – This command checks the status of the Keepalived service.
- systemctl stop squid – This command stops the Squid service.
- systemctl start squid – This command starts the Squid service.
Conclusion
In this tutorial, you learned how to configure Squid Proxy Server for high availability. This setup ensures that your proxy server remains operational even if one of your Squid instances encounters an issue. While this tutorial focused on CentOS, the same principles apply to other Linux distributions. Just make sure to replace the package manager commands with those of your distribution.
Remember, high availability is crucial for maintaining an uninterrupted service, especially when dealing with high traffic loads. By following this guide, you’ve taken a significant step towards ensuring that your proxy service remains up and running, no matter what happens.
Hope you found this tutorial helpful.
If you have any questions or run into any issues, feel free to leave a comment below.
FAQ
-
What is Squid Proxy Server?
Squid is a popular, open-source proxy server and web cache daemon. It has a wide variety of uses, from speeding up a web server by caching repeated requests, to caching web, DNS, and other network lookups for a group of people sharing network resources. It is primarily designed to run on Unix-like systems.
-
What is high availability?
High availability refers to a system or component that is continuously operational for a desirably long length of time. Availability can be measured relative to “100% operational” or “never failing”. A widely-held but difficult-to-achieve standard of availability for a system or product is known as “five 9s” (99.999 percent) availability.
-
What is Keepalived?
Keepalived is a routing software written in C that provides simple and robust facilities for load balancing and high availability to Linux hosts and Linux-based infrastructures. It uses the Virtual Router Redundancy Protocol (VRRP) to achieve high availability and load balancing.
-
What is redundancy in computing?
In computing, redundancy refers to the duplication of critical components or functions of a system with the intention of increasing reliability of the system, usually in the form of a backup or fail-safe. In the context of network engineering, this comes in the form of redundant network devices and network paths for rerouting of network traffic in the case of device or path failures or congestion.
-
Why is high availability important?
High availability is important because it ensures that your services remain available even when certain components fail. In today’s digital world, any downtime can lead to significant losses, both in terms of revenue and reputation. By implementing a high availability setup, you can provide a seamless experience to your users, regardless of any issues that may occur behind the scenes.