{"id":11717,"date":"2019-03-15T23:56:50","date_gmt":"2019-03-15T23:56:50","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11717"},"modified":"2019-03-15T23:56:50","modified_gmt":"2019-03-15T23:56:50","slug":"how-to-setup-high-availability-load-balancer-with-haproxy-to-control-web-server-traffic","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/how-to-setup-high-availability-load-balancer-with-haproxy-to-control-web-server-traffic\/","title":{"rendered":"How to Setup High-Availability Load Balancer with \u2018HAProxy\u2019 to Control Web Server Traffic"},"content":{"rendered":"<p><strong>HAProxy<\/strong>\u00a0stands for High Availability proxy. It is a Free and open source application written in C programming Language. HAProxy application is used as TCP\/HTTP Load Balancer and for proxy Solutions. The most common use of the HAProxy application is to distribute the workload across multiple servers e.g., web server, database server, etc thus improving the overall performance and reliability of server environment.<\/p>\n<p>The highly efficient and fast application is used by many of the world\u2019s reputed organization which includes but not limited to \u2013 Twitter, Reddit, GitHub and Amazon. It is available for Linux, BSD, Solaris and AIX platform.<\/p>\n<div id=\"attachment_11214\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Install-HAProxy-in-Linux.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11214\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Install-HAProxy-in-Linux-620x293.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Install-HAProxy-in-Linux-620x293.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Install-HAProxy-in-Linux-520x245.jpg 520w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Install-HAProxy-in-Linux.jpg 720w\" alt=\"Install HAProxy in Linux\" width=\"620\" height=\"293\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install HAProxy Load Balancer in Linux<\/p>\n<\/div>\n<p>In this tutorial, we will discuss the process of setting up a high availability load balancer using\u00a0<strong>HAProxy<\/strong>\u00a0to control the traffic of HTTP-based applications (web servers) by separating requests across multiple servers.<\/p>\n<p>For this article, we\u2019re using the most recent stable release of HAProxy version i.e.\u00a0<strong>1.5.10<\/strong>\u00a0released on December 31st 2014. And also we\u2019re using\u00a0<strong>CentOS 6.5<\/strong>\u00a0for this setup, but the below given instructions also works on CentOS\/RHEL\/Fedora and Ubuntu\/Debian distributions.<\/p>\n<h4>My Environment Setup<\/h4>\n<p>Here our load-balancer HAProxy server having hostname as\u00a0<b>websrv.tecmintlocal.com<\/b>\u00a0with IP address\u00a0<strong>192.168.0.125<\/strong>.<\/p>\n<h5>HAProxy Server Setup<\/h5>\n<pre><strong>Operating System<\/strong>\t:\tCentOS 6.5\r\n<strong>IP Address<\/strong>\t\t: \t192.168.0.125\r\n<strong>Hostname<\/strong>\t\t: \twebsrv.tecmintlocal.com\r\n<\/pre>\n<h5>Client Web Servers Setup<\/h5>\n<p>The other four machines are up and running with web servers such as Apache.<\/p>\n<pre><strong>Web Server #1<\/strong> :\tCentOS 6.5 [IP: 192.168.0.121] - [hostname: web1srv.tecmintlocal.com]\r\n<strong>Web Server #2<\/strong> :\tCentOS 6.5 [IP: 192.168.0.122] - [hostname: web2srv.tecmintlocal.com]\r\n<strong>Web Server #3<\/strong> :\tCentOS 6.5 [IP: 192.168.0.123] - [hostname: web3srv.tecmintlocal.com]\r\n<strong>Web Server #4<\/strong> :\tCentOS 6.5 [IP: 192.168.0.124] - [hostname: web4srv.tecmintlocal.com]\r\n<\/pre>\n<h3>Step 1: Installing Apache on Client Machines<\/h3>\n<p><strong>1.<\/strong>\u00a0First we have to install Apache in all four server\u2019s and share any one of site, for installing Apache in all four server\u2019s here we going to use following command.<\/p>\n<pre># yum install httpd\t\t[On <strong>RedHat<\/strong> based Systems]\r\n# apt-get install apache2\t[On <strong>Debian<\/strong> based Systems]\r\n<\/pre>\n<p><strong>2.<\/strong>\u00a0After installing Apache web server on all four client machines, you can verify anyone of the server whether Apache is running by accessing it via IP address in browser.<\/p>\n<pre>http:\/\/192.168.0.121\r\n<\/pre>\n<div id=\"attachment_11189\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-Apache-Status.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11189\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-Apache-Status-607x450.png\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-Apache-Status-607x450.png 607w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-Apache-Status.png 826w\" alt=\"Check Apache Status\" width=\"607\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Apache Status<\/p>\n<\/div>\n<h3>Step 2: Installing HAProxy Server<\/h3>\n<p><strong>3.<\/strong>\u00a0In most of the today\u2019s modern Linux distributions, HAPRoxy can be easily installed from the default base repository using default package manager\u00a0<strong>yum<\/strong>\u00a0or\u00a0<strong>apt-get<\/strong>.<\/p>\n<p>For example, to install HAProxy on RHEL\/CentOS\/Fedora and Debian\/Ubuntu versions, run the following command. Here I\u2019ve included\u00a0<strong>openssl<\/strong>\u00a0package too, because we\u2019re going to setup HAProxy with SSL and NON-SSL support.<\/p>\n<pre># yum install haproxy openssl-devel\t[On <strong>RedHat<\/strong> based Systems]\r\n# apt-get install haproxy\t\t[On <strong>Debian<\/strong> based Systems]\r\n<\/pre>\n<p><strong>Note<\/strong>: On\u00a0<strong>Debian Whezzy 7.0<\/strong>, we need to enable the backports repository by adding a new file\u00a0<strong><a>backports.list<\/a><\/strong>under \u201c<strong>\/etc\/apt\/sources.list.d\/<\/strong>\u201d directory with the following content.<\/p>\n<pre># echo \"deb http:\/\/cdn.debian.net\/debian wheezy-backports main\" &gt;&gt; \/etc\/apt\/sources.list.d\/backports.list\r\n<\/pre>\n<p>Next, update the repository database and install HAProxy.<\/p>\n<pre># apt-get update\r\n# apt-get install haproxy -t wheezy-backports\r\n<\/pre>\n<h3>Step 3: Configure HAProxy Logs<\/h3>\n<p><strong>4.<\/strong>\u00a0Next, we need to enable logging feature in HAProxy for future debugging. Open the main HAProxy configuration file \u2018<strong>\/etc\/haproxy\/haproxy.cfg<\/strong>\u2018 with your choice of editor.<\/p>\n<pre># vim \/etc\/haproxy\/haproxy.cfg\r\n<\/pre>\n<p>Next, follow the distro-specific instructions to configure logging feature in HAProxy.<\/p>\n<h5>On RHEL\/CentOS\/Fedora<\/h5>\n<p>Under\u00a0<b>#Global settings<\/b>, enable the following line.<\/p>\n<pre>log         127.0.0.1 local2\r\n<\/pre>\n<h5>On Ubuntu\/Debian<\/h5>\n<p>Under\u00a0<b>#Global settings<\/b>, replace the following lines,<\/p>\n<pre>log \/dev\/log        local0\r\nlog \/dev\/log        local1 notice \r\n<\/pre>\n<p>With,<\/p>\n<pre>log         127.0.0.1 local2\r\n<\/pre>\n<div id=\"attachment_11190\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-HAProxy-Logging.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11190\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-HAProxy-Logging.png\" alt=\"Enable HAProxy Logging\" width=\"576\" height=\"226\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Enable HAProxy Logging<\/p>\n<\/div>\n<p><strong>5.<\/strong>\u00a0Next, we need to enable UDP syslog reception in \u2018<strong>\/etc\/rsyslog.conf<\/strong>\u2018 configuration file to separate log files for HAProxy under\u00a0<b>\/var\/log<\/b>\u00a0directory. Open your your \u2018<strong>rsyslog.conf<\/strong>\u2018 file with your choice of editor.<\/p>\n<pre># vim \/etc\/rsyslog.conf\r\n<\/pre>\n<p>Uncommnet\u00a0<strong>ModLoad<\/strong>\u00a0and\u00a0<strong>UDPServerRun<\/strong>, Here our Server will listen to\u00a0<strong>Port 514<\/strong>\u00a0to collect the logs into syslog.<\/p>\n<pre># Provides UDP syslog reception\r\n$ModLoad imudp\r\n$UDPServerRun 514\r\n<\/pre>\n<div id=\"attachment_11191\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Configure-HAProxy-Logging.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11191\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Configure-HAProxy-Logging-620x339.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Configure-HAProxy-Logging-620x339.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Configure-HAProxy-Logging.png 658w\" alt=\"Configure HAProxy Logging\" width=\"620\" height=\"339\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Configure HAProxy Logging<\/p>\n<\/div>\n<p><strong>6.<\/strong>\u00a0Next, we need to create a separate file \u2018<strong>haproxy.conf<\/strong>\u2018 under \u2018<strong>\/etc\/rsyslog.d\/<\/strong>\u2018 directory to configure separate log files.<\/p>\n<pre># vim \/etc\/rsyslog.d\/haproxy.conf\r\n<\/pre>\n<p>Append following line to the newly create file.<\/p>\n<pre>local2.*\t\/var\/log\/haproxy.log\r\n<\/pre>\n<div id=\"attachment_11192\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11192\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Logs.png\" alt=\"HAProxy Logs\" width=\"371\" height=\"78\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">HAProxy Logs<\/p>\n<\/div>\n<p>Finally, restart the rsyslog service to update the new changes.<\/p>\n<pre># service rsyslog restart<\/pre>\n<h3>Step 4: Configuring HAProxy Global Settings<\/h3>\n<p><strong>7.<\/strong>\u00a0Now, here we need to set default variables in \u2018<strong>\/etc\/haproxy\/haproxy.cfg<\/strong>\u2018 for HAProxy. The changes needs to make for default under default section as follows, Here some of the changes like timeout for queue, connect, client, server and max connections need to be defined.<\/p>\n<p>In this case, I suggest you to go through the HAProxy man pages and tweak it as per your requirements.<\/p>\n<pre>#---------------------------------------------------------------------\r\ndefaults\r\n    mode                    http\r\n    log                     global\r\n    option                  httplog\r\n    option                  dontlognull\r\n    option http-server-close\r\n    option forwardfor       except 127.0.0.0\/8\r\n    option                  redispatch\r\n    retries                 3\r\n    timeout http-request    20\r\n    timeout queue           86400\r\n    timeout connect         86400\r\n    timeout client          86400\r\n    timeout server          86400\r\n    timeout http-keep-alive 30\r\n    timeout check           20\r\n    maxconn                 50000\r\n<\/pre>\n<div id=\"attachment_11193\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Default-Settings.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11193\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Default-Settings.png\" alt=\"HAProxy Default Settings\" width=\"569\" height=\"420\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">HAProxy Default Settings<\/p>\n<\/div>\n<p><strong>8.<\/strong>\u00a0Then we need to define\u00a0<strong>front-end<\/strong>\u00a0and\u00a0<strong>back-end<\/strong>\u00a0as shown below for Balancer in \u2018<strong>\/etc\/haproxy\/haproxy.cfg<\/strong>\u2018 global configuration file. Make sure to replace the IP addresses, hostnames and HAProxy login credentials as per your requirements.<\/p>\n<pre>frontend LB\r\n   bind <b>192.168.0.125<\/b>:80\r\n   reqadd X-Forwarded-Proto:\\ http\r\n   default_backend LB\r\n\r\nbackend LB <b>192.168.0.125<\/b>:80\r\n   mode http\r\n   stats enable\r\n   stats hide-version\r\n   stats uri \/stats\r\n   stats realm Haproxy\\ Statistics\r\n   stats auth <b>haproxy:redhat<\/b>\t\t# Credentials for HAProxy Statistic report page.\r\n   balance roundrobin\t\t\t# Load balancing will work in round-robin process.\r\n   option httpchk\r\n   option  httpclose\r\n   option forwardfor\r\n   cookie LB insert\r\n   server <b>web1-srv 192.168.0.121:80 cookie web1-srv<\/b> check\t\t# backend server.\r\n   server <b>web2-srv 192.168.0.122:80 cookie web2-srv<\/b> check\t\t# backend server.\r\n   server <b>web3-srv 192.168.0.123:80 cookie web3-srv<\/b> check\t\t# backend server.\r\n   server <b>web4-srv 192.168.0.124:80 check backup<\/b>\t\t\t# backup fail-over Server, If three of the above fails this will be activated.\r\n<\/pre>\n<div id=\"attachment_11194\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Global-Configuration.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11194\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Global-Configuration.png\" alt=\"HAProxy Global Configuration\" width=\"572\" height=\"426\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">HAProxy Global Configuration<\/p>\n<\/div>\n<p><strong>9.<\/strong>\u00a0After adding above settings, our load balancer can be accessed at \u2018<strong>http:\/\/192.168.0.125\/stats<\/strong>\u2018 with HTTP authentication using login name as \u2018<strong>haproxy<\/strong>\u2018 and password \u2018<strong>redhat<\/strong>\u2018 as mentioned in the above settings, but you can replace them with your own credentials.<\/p>\n<p><center><strong>10.<\/strong>\u00a0After you\u2019ve done with the configuration, make sure to restrat the HAProxy and make it persistent at system startup on RedHat based systems.<\/center><\/p>\n<pre># service haproxy restart\r\n# chkconfig haproxy on\r\n# chkconfig --list haproxy\r\n<\/pre>\n<div id=\"attachment_11195\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Start-HAProxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11195\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Start-HAProxy.png\" alt=\"Start HAProxy\" width=\"586\" height=\"210\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start HAProxy<\/p>\n<\/div>\n<p>For Ubuntu\/Debian users to need to set \u201c<strong>ENABLED<\/strong>\u201d option to \u201c<strong>1<\/strong>\u201d in \u2018<strong>\/etc\/default\/haproxy<\/strong>\u2018 file.<\/p>\n<pre>ENABLED=1\r\n<\/pre>\n<h3>Step 5: Verify HAProxy Load Balancer<\/h3>\n<p><strong>11.<\/strong>\u00a0Now it\u2019s time to access our Load balancer URL\/IP and verify for the site whether loading. Let me put one HTML file in all four servers. Create a file\u00a0<b>index.html<\/b>\u00a0in all four servers in web servers document root directory and add the following content to it.<\/p>\n<pre>&lt;html&gt;\r\n&lt;head&gt;\r\n  &lt;title&gt;Tecmint HAProxy Test Page&lt;\/title&gt;\r\n&lt;\/head&gt;\r\n\r\n&lt;body&gt;\r\n&lt;!-- Main content --&gt;\r\n&lt;h1&gt;My HAProxy Test Page&lt;\/h1&gt;\r\n\r\n&lt;p&gt;Welcome to HA Proxy test page!\r\n\r\n&lt;p&gt;There should be more here, but I don't know\r\nwhat to be write :p.\r\n\r\n&lt;address&gt;Made 11 January 2015&lt;br&gt;\r\n  by Babin Lonston.&lt;\/address&gt;\r\n\r\n&lt;\/body&gt;\r\n&lt;\/html&gt;\r\n<\/pre>\n<p><strong>12.<\/strong>\u00a0After creating \u2018<strong>index.html<\/strong>\u2018 file, now try to access the site and see whether I can able access the copied html file.<\/p>\n<pre>http:\/\/192.168.0.125\/\r\n<\/pre>\n<div id=\"attachment_11196\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Verify-HAProxy-Load-Balancer.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11196\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Verify-HAProxy-Load-Balancer.png\" alt=\"Verify HAProxy Load Balancer\" width=\"475\" height=\"290\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify HAProxy Load Balancer<\/p>\n<\/div>\n<p>Site has been successfully accessed.<\/p>\n<h3>Step 6: Verify Statistic of Load Balancer<\/h3>\n<p><strong>13.<\/strong>\u00a0To get the statistic page of HAProxy, you can use the following link. While asking for Username and password we have to provide the\u00a0<strong>haproxy<\/strong>\/<strong>redhat<\/strong>.<\/p>\n<pre>http:\/\/192.168.0.125\/stats\r\n<\/pre>\n<div id=\"attachment_11197\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Login.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11197\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Login-620x450.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Login-620x450.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Login.png 632w\" alt=\"HAProxy Statistics Login\" width=\"620\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">HAProxy Statistics Login<\/p>\n<\/div>\n<div id=\"attachment_11198\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Page.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11198\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Page-620x222.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Page-620x222.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Page-1024x366.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/HAProxy-Statistics-Page.png 1596w\" alt=\"HAProxy Statistics\" width=\"620\" height=\"222\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">HAProxy Statistics<\/p>\n<\/div>\n<h3>Step 7: Enabling SSL in HAProxy<\/h3>\n<p><strong>14.<\/strong>\u00a0To enable SSL in HAProxy, you need to install\u00a0<strong>mod_ssl<\/strong>\u00a0package for creating SSL Certificate for HAProxy.<\/p>\n<h5>On RHEL\/CentOS\/Fedora<\/h5>\n<p>To install\u00a0<strong>mod_ssl<\/strong>\u00a0run the following command<\/p>\n<p># yum install mod_ssl -y<\/p>\n<h5>On Ubuntu\/Debian<\/h5>\n<p>By default under Ubuntu\/Debian SSL support comes standard with Apache package. We just need to enable it..<\/p>\n<pre># a2enmod ssl\r\n<\/pre>\n<p>After you\u2019ve enabled SSL, restart the Apache server for the change to be recognized.<\/p>\n<pre># service apache2 restart\r\n<\/pre>\n<p><strong>15.<\/strong>\u00a0After restarting, Navigate to the SSL directory and create SSL certificate using following commands.<\/p>\n<pre># cd \/etc\/ssl\/\r\n# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout \/etc\/ssl\/tecmint.key -out \/etc\/ssl\/tecmint.crt\r\n# cat tecmint.crt tecmint.key &gt; tecmint.pem\r\n<\/pre>\n<div id=\"attachment_11199\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Create-SSL-for-HAProxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11199\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Create-SSL-for-HAProxy-620x350.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Create-SSL-for-HAProxy-620x350.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Create-SSL-for-HAProxy.png 857w\" alt=\"Create SSL for HAProxy\" width=\"620\" height=\"350\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Create SSL for HAProxy<\/p>\n<\/div>\n<div id=\"attachment_11200\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Certificate.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11200\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Certificate.png\" alt=\"SSL Certificate for HAProxy\" width=\"557\" height=\"198\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">SSL Certificate for HAProxy<\/p>\n<\/div>\n<p><strong>16.<\/strong>\u00a0Open and edit the haproxy configuration and add the SSL front-end as below.<\/p>\n<pre># vim \/etc\/haproxy\/haproxy.cfg \r\n<\/pre>\n<p>Add the following configuration as frontend.<\/p>\n<pre>frontend LBS\r\n   bind 192.168.0.125:443 ssl crt \/etc\/ssl\/tecmint.pem\r\n   reqadd X-Forwarded-Proto:\\ https\r\n   default_backend LB\r\n<\/pre>\n<p><strong>17.<\/strong>\u00a0Next, add the redirect rule in backend configuration.<\/p>\n<pre>redirect scheme https if !{ ssl_fc }\r\n<\/pre>\n<div id=\"attachment_11201\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-SSL-on-HAProxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11201\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-SSL-on-HAProxy-429x450.png\" sizes=\"auto, (max-width: 429px) 100vw, 429px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-SSL-on-HAProxy-429x450.png 429w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Enable-SSL-on-HAProxy.png 559w\" alt=\"Enable SSL on HAProxy\" width=\"429\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Enable SSL on HAProxy<\/p>\n<\/div>\n<p><strong>18.<\/strong>\u00a0After making above changes, make sure to restart the haproxy service.<\/p>\n<pre># service haproxy restart\r\n<\/pre>\n<p>While restarting if we get the below warning, we can fix it by adding a parameter in Global Section of\u00a0 haproxy.<\/p>\n<div id=\"attachment_11202\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-HAProxy-Error.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11202\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-HAProxy-Error-620x80.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-HAProxy-Error-620x80.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-HAProxy-Error.png 849w\" alt=\"SSL HAProxy Error\" width=\"620\" height=\"80\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">SSL HAProxy Error<\/p>\n<\/div>\n<pre>tune.ssl.default-dh-param 2048\r\n<\/pre>\n<p><strong>19.<\/strong>\u00a0After restarting, try to access the site 192.168.0.125, Now it will forward to https.<\/p>\n<pre>http:\/\/192.168.0.25\r\n<\/pre>\n<div id=\"attachment_11203\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Verify-SSL-HAProxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-11203\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Verify-SSL-HAProxy.png\" alt=\"Verify SSL HAProxy\" width=\"443\" height=\"257\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Verify SSL HAProxy<\/p>\n<\/div>\n<div id=\"attachment_11204\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Enabled-HAProxy.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11204\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Enabled-HAProxy-620x212.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Enabled-HAProxy-620x212.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Enabled-HAProxy-1024x351.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/SSL-Enabled-HAProxy.png 1598w\" alt=\"SSL Enabled HAProxy\" width=\"620\" height=\"212\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">SSL Enabled HAProxy<\/p>\n<\/div>\n<p><strong>20.<\/strong>\u00a0Next, verify the<strong>\u00a0haproxy.log<\/strong>\u00a0under \u2018<strong>\/var\/log\/<\/strong>\u2018 directory.<\/p>\n<pre># tail -f \/var\/log\/haproxy.log\r\n<\/pre>\n<div id=\"attachment_11205\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-HAProxy-Logs.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-11205\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-HAProxy-Logs-620x241.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-HAProxy-Logs-620x241.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-HAProxy-Logs-1024x399.png 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/02\/Check-HAProxy-Logs.png 1079w\" alt=\"Check HAProxy Logs\" width=\"620\" height=\"241\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check HAProxy Logs<\/p>\n<\/div>\n<h3>Step 8: Open HAProxy Ports on Firewall<\/h3>\n<p><strong>21.<\/strong>\u00a0Open the port\u2019s for web service and Log reception UDP port using below rules.<\/p>\n<h5>On CentOS\/RHEL 6<\/h5>\n<pre>iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT\r\niptables -A INPUT -i eth0 -p udp --dport 514 -j ACCEPT\r\niptables -A INPUT -i eth0 -p tcp --dport 80 -m state --state NEW,ESTABLISHED -j ACCEPT\r\niptables -A INPUT -i eth0 -p tcp --dport 443 -m state --state NEW,ESTABLISHED -j ACCEPT\r\n<\/pre>\n<h5>On CentOS\/RHEL 7 and Fedora 21<\/h5>\n<pre># firewall\u00adcmd \u00ad\u00adpermanent \u00ad\u00adzone=public \u00ad\u00adadd\u00adport=514\/tcp\r\n# firewall\u00adcmd \u00ad\u00adpermanent \u00ad\u00adzone=public \u00ad\u00adadd\u00adport=80\/tcp\r\n# firewall\u00adcmd \u00ad\u00adpermanent \u00ad\u00adzone=public \u00ad\u00adadd\u00adport=443\/tcp\r\n# firewall\u00adcmd \u00ad\u00adreload \r\n<\/pre>\n<h5>On Debian\/Ubuntu<\/h5>\n<p>Add the following line to \u2018\/<strong>etc\/iptables.up.rules<\/strong>\u2018 to enable ports on firewall.<\/p>\n<pre>A INPUT \u00adp tcp \u00ad\u00addport 514 \u00adj ACCEPT \r\nA INPUT \u00adp tcp \u00ad\u00addport 80 \u00adj ACCEPT \r\nA INPUT \u00adp tcp \u00ad\u00addport 443 \u00adj ACCEPT \r\n<\/pre>\n<h3>Conclusion<\/h3>\n<p>In this article, we\u2019ve installed Apache in 4 server\u2019s and shared a website for reducing the traffic load. I Hope this article will help you to setup a Load Balancer for web server\u2019s using HAProxy and make your applications more stable and available<\/p>\n<p>If you have any questions regarding the article, feel free to post your comments or suggestions, I will love to help you out in whatever the best way I can.<\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/install-haproxy-load-balancer-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>HAProxy\u00a0stands for High Availability proxy. It is a Free and open source application written in C programming Language. HAProxy application is used as TCP\/HTTP Load Balancer and for proxy Solutions. The most common use of the HAProxy application is to distribute the workload across multiple servers e.g., web server, database server, etc thus improving the &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/how-to-setup-high-availability-load-balancer-with-haproxy-to-control-web-server-traffic\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;How to Setup High-Availability Load Balancer with \u2018HAProxy\u2019 to Control Web Server Traffic&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-11717","post","type-post","status-publish","format-standard","hentry","category-linux"],"_links":{"self":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11717","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/comments?post=11717"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11717\/revisions"}],"predecessor-version":[{"id":11718,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11717\/revisions\/11718"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11717"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11717"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11717"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}