{"id":17322,"date":"2023-07-15T14:24:04","date_gmt":"2023-07-15T14:24:04","guid":{"rendered":"https:\/\/webhostinggeeks.com\/howto\/?p=17322"},"modified":"2023-07-20T09:03:40","modified_gmt":"2023-07-20T09:03:40","slug":"how-to-configure-squid-proxy-server-for-high-availability-with-keepalived","status":"publish","type":"post","link":"https:\/\/webhostinggeeks.com\/howto\/how-to-configure-squid-proxy-server-for-high-availability-with-keepalived\/","title":{"rendered":"How to Configure Squid Proxy Server for High Availability (with Keepalived)"},"content":{"rendered":"<p><img decoding=\"async\" data-src=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1024x768.jpg\" alt=\"How to Configure Squid Proxy Server for High Availability (with Keepalived)\" width=\"1024\" height=\"768\" class=\"alignnone size-large wp-image-17323 lazyload\" data-srcset=\"https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1024x768.jpg 1024w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-300x225.jpg 300w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1536x1152.jpg 1536w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-2048x1536.jpg 2048w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-128x96.jpg 128w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-420x315.jpg 420w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-540x405.jpg 540w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-720x540.jpg 720w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-960x720.jpg 960w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1140x855.jpg 1140w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1320x990.jpg 1320w, https:\/\/webhostinggeeks.com\/howto\/wp-content\/uploads\/2023\/07\/How-to-Configure-Squid-Proxy-Server-for-High-Availability-with-Keepalived-1440x1080.jpg 1440w\" data-sizes=\"(max-width: 1024px) 100vw, 1024px\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 1024px; --smush-placeholder-aspect-ratio: 1024\/768;\" \/><\/p>\n<p>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 <a href=\"https:\/\/webhostinggeeks.com\/blog\/proxy-server-definition-functionality-types\/\">proxy servers<\/a>, this is no different. Proxy servers like <a href=\"https:\/\/webhostinggeeks.com\/blog\/squid-proxy-server-features-functions-benefits\/\">Squid<\/a> are often used to handle a large amount of traffic, and any downtime can lead to significant issues.<\/p>\n<p>Squid is a <a href=\"https:\/\/webhostinggeeks.com\/best\/proxy-servers\/\">popular proxy server<\/a> for many reasons. It&#8217;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.<\/p>\n<p>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.<\/p>\n<p>Before we start, make sure you have Squid installed on your server. If you haven&#8217;t, you can refer to our previous tutorial on <a href=\"https:\/\/webhostinggeeks.com\/howto\/how-to-install-and-configure-squid-proxy-server-for-private-connections-on-centos\/\">how to install and configure Squid Proxy Server<\/a>.<\/p>\n<h2>Step 1: Install and Configure Keepalived<\/h2>\n<p><a href=\"https:\/\/www.keepalived.org\/\" rel=\"noopener\" target=\"_blank\">Keepalived<\/a> is a routing software written in C that provides simple and robust facilities for <a href=\"https:\/\/webhostinggeeks.com\/blog\/what-is-load-balancing\/\">load balancing<\/a> and high availability to Linux hosts and Linux-based infrastructures. The installation is straightforward with the yum package manager.<\/p>\n<pre>\r\nyum install keepalived -y\r\n<\/pre>\n<p>Once installed, you need to configure Keepalived. The configuration file is located at \/etc\/keepalived\/keepalived.conf. Open this file in a text editor.<\/p>\n<pre>\r\nvi \/etc\/keepalived\/keepalived.conf\r\n<\/pre>\n<p>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.<\/p>\n<pre>\r\nvrrp_instance VI_1 {\r\n    state MASTER\r\n    interface eth0\r\n    virtual_router_id 51\r\n    priority 100\r\n    advert_int 1\r\n    authentication {\r\n        auth_type PASS\r\n        auth_pass 123456\r\n    }\r\n    virtual_ipaddress {\r\n        192.168.1.100\r\n    }\r\n}\r\n<\/pre>\n<p>In the above configuration, replace &#8220;eth0&#8221; with your network interface name, &#8220;192.168.1.100&#8221; with your desired virtual IP address, and &#8220;123456&#8221; with a password of your choice. The priority of the master server should be higher than the backup server.<\/p>\n<p>After you&#8217;ve made the changes, save and close the file. Then start and enable Keepalived.<\/p>\n<pre>\r\nsystemctl start keepalived\r\nsystemctl enable keepalived\r\n<\/pre>\n<p>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.<\/p>\n<h2>Step 2: Configure Squid for High Availability<\/h2>\n<p>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.<\/p>\n<pre>\r\nvi \/etc\/squid\/squid.conf\r\n<\/pre>\n<p>In the configuration file, you need to set the http_port directive to your virtual IP address and the desired port number.<\/p>\n<pre>\r\nhttp_port 192.168.1.100:3128\r\n<\/pre>\n<p>Replace &#8220;192.168.1.100:3128&#8221; with your virtual IP address and the port number you want Squid to listen on.<\/p>\n<p>After you&#8217;ve made the changes, save and close the file. Then restart Squid for the changes to take effect.<\/p>\n<pre>\r\nsystemctl restart squid\r\n<\/pre>\n<p>Repeat this step on your backup server.<\/p>\n<h2>Step 3: Test Your Configuration<\/h2>\n<p>Now that you have Squid and Keepalived configured, it&#8217;s time to test your setup. First, check the status of Keepalived.<\/p>\n<pre>\r\nsystemctl status keepalived\r\n<\/pre>\n<p>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.<\/p>\n<p>Next, test your Squid configuration. You can do this by setting your browser&#8217;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.<\/p>\n<p>To test the high availability, you can stop the Squid service on your master server.<\/p>\n<pre>\r\nsystemctl stop squid\r\n<\/pre>\n<p>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.<\/p>\n<p>Don&#8217;t forget to start the Squid service on your master server again.<\/p>\n<pre>\r\nsystemctl start squid\r\n<\/pre>\n<h2>Commands Mentioned:<\/h2>\n<ul>\n<li><span class=\"fw-bold\">yum install keepalived -y<\/span> \u2013 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.<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/keepalived\/keepalived.conf<\/span> \u2013 This command opens the Keepalived configuration file in a text editor.<\/li>\n<li><span class=\"fw-bold\">systemctl start keepalived<\/span> \u2013 This command starts the Keepalived service.<\/li>\n<li><span class=\"fw-bold\">systemctl enable keepalived<\/span> \u2013 This command enables the Keepalived service to start on boot.<\/li>\n<li><span class=\"fw-bold\">vi \/etc\/squid\/squid.conf<\/span> \u2013 This command opens the Squid configuration file in a text editor.<\/li>\n<li><span class=\"fw-bold\">systemctl restart squid<\/span> \u2013 This command restarts the Squid service, applying any changes made to the configuration file.<\/li>\n<li><span class=\"fw-bold\">systemctl status keepalived<\/span> \u2013 This command checks the status of the Keepalived service.<\/li>\n<li><span class=\"fw-bold\">systemctl stop squid<\/span> \u2013 This command stops the Squid service.<\/li>\n<li><span class=\"fw-bold\">systemctl start squid<\/span> \u2013 This command starts the Squid service.<\/li>\n<\/ul>\n<h2>Conclusion<\/h2>\n<p>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.<\/p>\n<p>Remember, high availability is crucial for maintaining an uninterrupted service, especially when dealing with high traffic loads. By following this guide, you&#8217;ve taken a significant step towards ensuring that your proxy service remains up and running, no matter what happens.<\/p>\n<p>Hope you found this tutorial helpful.<\/p>\n<p>If you have any questions or run into any issues, feel free to leave a comment below.<\/p>\n<h2>FAQ<\/h2>\n<ol itemscope itemtype=\"https:\/\/schema.org\/FAQPage\">\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is Squid Proxy Server?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">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.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is high availability?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">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 &#8220;100% operational&#8221; or &#8220;never failing&#8221;. A widely-held but difficult-to-achieve standard of availability for a system or product is known as &#8220;five 9s&#8221; (99.999 percent) availability.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is Keepalived?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">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.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">What is redundancy in computing?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">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.<\/span>\n<\/p>\n<\/li>\n<li itemscope itemprop=\"mainEntity\" itemtype=\"https:\/\/schema.org\/Question\">\n<p class=\"fw-bold\" itemprop=\"name\">Why is high availability important?<\/p>\n<p itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<span itemprop=\"text\">High availability is important because it ensures that your services remain available even when certain components fail. In today&#8217;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.<\/span>\n<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>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&#8230;<\/p>\n","protected":false},"author":6,"featured_media":17323,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"wds_primary_category":0,"footnotes":""},"categories":[1057],"tags":[2089,2103,1678,1793],"class_list":["post-17322","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-squid-server","tag-configuration","tag-keepalived","tag-proxy","tag-squid"],"_links":{"self":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/17322","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/comments?post=17322"}],"version-history":[{"count":0,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/posts\/17322\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media\/17323"}],"wp:attachment":[{"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/media?parent=17322"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/categories?post=17322"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webhostinggeeks.com\/howto\/wp-json\/wp\/v2\/tags?post=17322"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}