{"id":11711,"date":"2019-03-15T23:14:28","date_gmt":"2019-03-15T23:14:28","guid":{"rendered":"http:\/\/www.appservgrid.com\/paw92\/?p=11711"},"modified":"2019-03-15T23:14:28","modified_gmt":"2019-03-15T23:14:28","slug":"setting-up-web-servers-load-balancing-using-pound-on-rhel-centos","status":"publish","type":"post","link":"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/setting-up-web-servers-load-balancing-using-pound-on-rhel-centos\/","title":{"rendered":"Setting Up Web Servers Load Balancing Using \u2018POUND\u2019 on RHEL\/CentOS"},"content":{"rendered":"<p><strong>POUND<\/strong>\u00a0is a load balancing program developed by ITSECURITY Company. It is a lightweight open source reverse proxy tool which can be used as a web-server load balancer to distribute load among several servers. There are several advantages POUND gives to end user which are very convenient and does the job right.<\/p>\n<ol>\n<li>Supports virtual hosts.<\/li>\n<li>Configurable.<\/li>\n<li>When a backend server is failed or recovered from a failure, it detects it automatically and bases its load balancing decisions according to that.<\/li>\n<li>It rejects incorrect requests.<\/li>\n<li>No specified browser or webservers.<\/li>\n<\/ol>\n<p>Let\u2019s have a look at how can get this hack done.<\/p>\n<p>First of all you will need a scenario for better understanding about getting this done. So I will use a scenario where there are two webservers and one gateway server which needs to balance the requests comes to gateway server to webservers.<\/p>\n<pre><strong>Pound Gateway Server<\/strong> : 172.16.1.222\r\n<strong>Web Server 01<\/strong> : 172.16.1.204\r\n<strong>Web Server 02<\/strong> : 192.168.1.161\r\n<\/pre>\n<div id=\"attachment_14577\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14577\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound-620x297.png\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound-620x297.png 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound.png 720w\" alt=\"Install Pound Load Balancer in Linux\" width=\"620\" height=\"297\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Pound Web Server Load Balancer<\/p>\n<\/div>\n<h3>Step1: Install Pound Load Balancer on Gateway Server<\/h3>\n<p><strong>1.<\/strong>\u00a0The easiest way to install\u00a0<strong>Pound<\/strong>\u00a0is using pre-compiled RPM packages, you can find RPMs for RedHat based distributions at:<\/p>\n<ol>\n<li><a href=\"http:\/\/www.invoca.ch\/pub\/packages\/pound\/\" target=\"_blank\" rel=\"nofollow noopener\">http:\/\/www.invoca.ch\/pub\/packages\/pound\/<\/a><\/li>\n<\/ol>\n<p>Alternatively, Pound can be easily installed from the\u00a0<a href=\"https:\/\/www.tecmint.com\/how-to-enable-epel-repository-for-rhel-centos-6-5\/\" target=\"_blank\" rel=\"noopener\">EPEL repository<\/a>\u00a0as shown below.<\/p>\n<pre># yum install epel-release\r\n# yum install Pound\r\n<\/pre>\n<p>After Pound installed, you can verify whether it is installed by issuing this command.<\/p>\n<pre># rpm \u2013qa |grep Pound\r\n<\/pre>\n<div id=\"attachment_14562\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound-Load-Balancer.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14562\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Install-Pound-Load-Balancer.jpg\" alt=\"Install Pound Load Balancer\" width=\"295\" height=\"115\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Install Pound Load Balancer<\/p>\n<\/div>\n<p><strong>2.<\/strong>\u00a0Secondly, you need\u00a0<strong>two web-servers<\/strong>\u00a0to balance the load and make sure you have clear identifiers in order to test the pound configuration works fine.<\/p>\n<p>Here I have two servers bearing IP addresses\u00a0<strong>172.16.1.204<\/strong>\u00a0and\u00a0<strong>192.168.1.161<\/strong>.<\/p>\n<p>For ease of use, I have created python SimpleHTTPServer to create an instant webserver on both servers. Read about\u00a0<a href=\"https:\/\/www.tecmint.com\/python-simplehttpserver-to-create-webserver-or-serve-files-instantly\/\" target=\"_blank\" rel=\"noopener\">python SimpleHTTPServer<\/a><\/p>\n<p>In my scenario, I have my\u00a0<strong>webserver01<\/strong>\u00a0running on\u00a0<strong>172.16.1.204<\/strong>\u00a0through port\u00a0<strong>8888<\/strong>\u00a0and\u00a0<strong>webserver02<\/strong>\u00a0running on\u00a0<strong>192.168.1.161<\/strong>\u00a0through port\u00a0<strong>5555<\/strong>.<\/p>\n<div id=\"attachment_14564\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Webserver-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14564\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Webserver-2.jpg\" alt=\"Pound Webserver 1\" width=\"420\" height=\"37\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Pound Webserver 1<\/p>\n<\/div>\n<div id=\"attachment_14570\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Webserver.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-14570\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Webserver.jpg\" alt=\"Pound Webserver 2\" width=\"442\" height=\"37\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Pound Webserver 2<\/p>\n<\/div>\n<h3>Step 2: Configure Pound Load Balancer<\/h3>\n<p><strong>3.<\/strong>\u00a0Now it\u2019s time to make the configurations done. Once you have installed pound successfully, it creates the pound\u2019s config file in\u00a0<strong>\/etc<\/strong>, namely\u00a0<code>pound.cfg<\/code>.<\/p>\n<p>We have to edit the server and backend details in order to balance the load among the webservers. Go to\u00a0<strong>\/etc<\/strong>and open\u00a0<code>pound.cfg<\/code>\u00a0file for editing.<\/p>\n<pre># vi \/etc\/pound.cfg\r\n<\/pre>\n<p>Make the changes as suggested below.<\/p>\n<pre>ListenHTTP\r\n    Address <strong>172.16.1.222<\/strong>\r\n    Port 80\r\nEnd\r\n\r\nListenHTTPS\r\n    Address <strong>172.16.1.222<\/strong>\r\n    Port    443\r\n    Cert    \"\/etc\/pki\/tls\/certs\/pound.pem\"\r\nEnd\r\n\r\nService\r\n    BackEnd\r\n        Address <strong>172.16.1.204<\/strong>\r\n        Port    <strong>8888<\/strong>\r\n    End\r\n\r\n    BackEnd\r\n        Address <strong>192.168.1.161<\/strong>\r\n        Port    <strong>5555<\/strong>\r\n    End\r\nEnd\r\n<\/pre>\n<p>This is how my\u00a0<strong>pound.cfg<\/strong>\u00a0file looks like.<\/p>\n<div id=\"attachment_14568\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Configure-Pound.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14568\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Configure-Pound-347x450.png\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Configure-Pound-347x450.png 347w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Configure-Pound.png 596w\" alt=\"Configure Pound Load Balancer\" width=\"347\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Configure Pound Load Balancer<\/p>\n<\/div>\n<p>Under the \u201c<strong>ListenHTTP<\/strong>\u201d and \u201c<strong>ListenHTTPS<\/strong>\u201d tags, you have to enter the\u00a0<strong>IP address<\/strong>\u00a0of the server you have installed POUND.<\/p>\n<p>By default a server handles HTTP requests though port\u00a0<strong>80<\/strong>\u00a0and HTTPS requests through port\u00a0<strong>443<\/strong>. Under the \u201c<strong>Service<\/strong>\u201d tag, you can add any amount of sub tags called \u201c<strong>BackEnd<\/strong>\u201d. BackEnd tags bears the IP addresses and the port numbers which the webservers are running on.<\/p>\n<p>Now save the file after editing it correctly and restart the\u00a0<strong>POUND<\/strong>\u00a0service by issuing one of below commands.<\/p>\n<pre># \/etc\/init.d\/pound restart \r\nOR\r\n# service pound restart\r\nOR\r\n# systemctl restart pound.service\r\n<\/pre>\n<div id=\"attachment_14569\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Start-Pound-Load-Balancer.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14569\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Start-Pound-Load-Balancer-620x114.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Start-Pound-Load-Balancer-620x114.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Start-Pound-Load-Balancer.jpg 741w\" alt=\"Start Pound Load Balancer\" width=\"620\" height=\"114\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Start Pound Load Balancer<\/p>\n<\/div>\n<p><strong>4.<\/strong>\u00a0Now it\u2019s time to check. Open two web browsers to check whether our configurations work fine. In the address bar type your\u00a0<strong>POUND<\/strong>\u00a0gateway\u2019s IP address and see what appears.<\/p>\n<p>First request should load the first\u00a0<strong>webserver01<\/strong>\u00a0and second request from the other web browser should load the second\u00a0<strong>webserver02<\/strong>.<\/p>\n<div id=\"attachment_14572\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Pound-Load-Balancing.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14572\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Pound-Load-Balancing-620x395.jpg\" sizes=\"auto, (max-width: 620px) 100vw, 620px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Pound-Load-Balancing-620x395.jpg 620w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Pound-Load-Balancing-1024x653.jpg 1024w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Check-Pound-Load-Balancing.jpg 1200w\" alt=\"Check Pound Load Balancing\" width=\"620\" height=\"395\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Check Pound Load Balancing<\/p>\n<\/div>\n<p>Furthermore, think of a scenario like if you have\u00a0<strong>two webservers<\/strong>\u00a0to load balance and one of the server\u2019s performance is good and other\u2019s performance is not so good.<\/p>\n<p>So when load balancing among them, you will have to consider for which server you have to put more weight on. Obviously for the server with good performance specs.<\/p>\n<p>To balance the load like that, you just have to add a single parameter inside the\u00a0<code>pound.cfg<\/code>\u00a0file. Let\u2019s have a look at it.<\/p>\n<p>Think server\u00a0<strong>192.168.1.161:5555<\/strong>\u00a0is the better server. Then you need put more requests flow to that server. Under the \u201c<strong>BackEnd<\/strong>\u201d tag which is configured for\u00a0<strong>192.168.1.161<\/strong>\u00a0server, add the parameter \u201c<strong>Priority<\/strong>\u201d before the End tag.<\/p>\n<p>Look at below example.<\/p>\n<div id=\"attachment_14573\" class=\"wp-caption aligncenter\">\n<p><a href=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Pound-Load-Balancing-Priority.png\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-14573\" src=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Pound-Load-Balancing-Priority-347x450.png\" sizes=\"auto, (max-width: 347px) 100vw, 347px\" srcset=\"https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Pound-Load-Balancing-Priority-347x450.png 347w, https:\/\/www.tecmint.com\/wp-content\/uploads\/2015\/07\/Pound-Load-Balancing-Priority.png 596w\" alt=\"Pound Load Balancing Priority\" width=\"347\" height=\"450\" data-lazy-loaded=\"true\" \/><\/a><\/p>\n<p class=\"wp-caption-text\">Pound Load Balancing Priority<\/p>\n<\/div>\n<p>The range we can use for the \u201c<strong>Priority<\/strong>\u201d parameter is between\u00a0<strong>1-9<\/strong>. If we do not define it, default value of\u00a0<strong>5<\/strong>\u00a0will be assigned.<\/p>\n<p>Then load will be balanced equally. If we define the Priority number,\u00a0<strong>POUND<\/strong>\u00a0will load the server with higher priority number more oftenly. So in this case,\u00a0<strong>192.168.1.161:5555<\/strong>\u00a0will be loaded more often than the server\u00a0<strong>172.16.1.204:8888<\/strong>.<\/p>\n<h3>Step 3: Planning Emergency Breakdowns<\/h3>\n<p><strong>Emergency Tag<\/strong>: This tag is used to load a server in case of all the back end servers are dead. You can add it before the last End tag of\u00a0<strong>pound.cfg<\/strong>\u00a0as follows.<\/p>\n<pre>\u201cEmergency\r\n           Address 192.168.5.10\r\n           Port        8080\r\n   End\u201d\r\n<\/pre>\n<p><strong>6.<\/strong>\u00a0POUND always keep track of which backend servers are alive and which are not. We can define after how many seconds POUND should checkout the backend servers by adding \u201c<strong>Alive<\/strong>\u201d parameter in\u00a0<strong>pound.cfg<\/strong>.<\/p>\n<p>You can use the parameter as \u201c<strong>Alive 30<\/strong>\u201d for set it to\u00a0<strong>30<\/strong>\u00a0seconds. Pound will temporarily disable the backend servers which are not responding. When we say not responding server may be dead or cannot establish a connection at that moment.<\/p>\n<p>POUND will check the disabled backend server after every time period you have defined in the\u00a0<strong>pound.cfg<\/strong>\u00a0file in case if the server could establish a connection, then POUND can get back to work with the server.<\/p>\n<p><strong>7.<\/strong>\u00a0POUND daemon will be handled by\u00a0<strong>poundctl<\/strong>\u00a0command. By having that we don\u2019t need to edit the\u00a0<strong>pound.cfg<\/strong>file and we can issue\u00a0<strong>Listner Server<\/strong>,\u00a0<strong>BackEnd<\/strong>\u00a0servers and sessions etc. via a single command.<\/p>\n<pre><strong>Syntax<\/strong>: poundctl -c \/path\/to\/socket [-L\/-l] [-S\/-s] [-B\/-b] [-N\/-n] [-H] [-X]\r\n<\/pre>\n<ol>\n<li><strong>-c<\/strong>\u00a0defines path to your socket.<\/li>\n<li><strong>-L<\/strong>\u00a0\/\u00a0<strong>-l<\/strong>\u00a0defines the listener of your architecture.<\/li>\n<li><strong>-S<\/strong>\u00a0\/\u00a0<strong>-s<\/strong>\u00a0defines the service.<\/li>\n<li><strong>-B<\/strong>\u00a0\/\u00a0<strong>-b<\/strong>\u00a0defines the backend servers.<\/li>\n<\/ol>\n<p>See\u00a0<strong>poundctl<\/strong>\u00a0man pages for more information.<\/p>\n<p>Hope you enjoy this hack and discover more options regarding this. Feel free to comment below for any suggestions and ideas. Keep connected with Tecmint for handy and latest How To\u2019s.<\/p>\n<p><strong>Read Also<\/strong>:\u00a0<a href=\"https:\/\/www.tecmint.com\/setting-up-xr-crossroads-load-balancer-for-web-servers-on-rhel-centos\/\" target=\"_blank\" rel=\"noopener\">Installing XR Crossroads Load Balancer for Web Servers<\/a><\/p>\n<p><a href=\"https:\/\/www.tecmint.com\/setting-up-pound-web-server-load-balancing-in-linux\/\" target=\"_blank\" rel=\"noopener\">Source<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>POUND\u00a0is a load balancing program developed by ITSECURITY Company. It is a lightweight open source reverse proxy tool which can be used as a web-server load balancer to distribute load among several servers. There are several advantages POUND gives to end user which are very convenient and does the job right. Supports virtual hosts. Configurable. &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/www.appservgrid.com\/paw92\/index.php\/2019\/03\/15\/setting-up-web-servers-load-balancing-using-pound-on-rhel-centos\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Setting Up Web Servers Load Balancing Using \u2018POUND\u2019 on RHEL\/CentOS&#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-11711","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\/11711","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=11711"}],"version-history":[{"count":1,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11711\/revisions"}],"predecessor-version":[{"id":11712,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/posts\/11711\/revisions\/11712"}],"wp:attachment":[{"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/media?parent=11711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/categories?post=11711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.appservgrid.com\/paw92\/index.php\/wp-json\/wp\/v2\/tags?post=11711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}