{"id":2207,"date":"2016-07-13T14:19:26","date_gmt":"2016-07-13T18:19:26","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2207"},"modified":"2017-11-24T17:57:08","modified_gmt":"2017-11-24T22:57:08","slug":"install-haproxy-centos-7","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/","title":{"rendered":"How to install HAProxy on CentOS 7"},"content":{"rendered":"<h1>How to install HAProxy on CentOS 7<\/h1>\n<p>HAProxy is a free HTTP\/TCP high availability load balancer and proxy server. It spreads requests among multiple servers to mitigate issues resulting from single server failure. It is used by many well known highly trafficked websites such as Github, Stack Overflow and Reddit to improve uptime statistics.<\/p>\n<h2>Getting Started<\/h2>\n<p>In order to install HAProxy, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\"><b>Cloud Server<\/b><\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\"><b>Dedicated Server<\/b><\/a>) running a clean installation of CentOS 7.<br \/>\n\u2022 All commands should be run as the root user<\/p>\n<h2>Tutorial<\/h2>\n<p>Make sure that your CentOS 7 distribution is fully up to date.<\/p>\n<p><code>yum -y update<\/code><\/p>\n<p>You can install HAProxy from the default repositories.<\/p>\n<p><code>yum -y install haproxy<\/code><\/p>\n<p>Open the configuration file in a text editor.<\/p>\n<p><code>nano \/etc\/haproxy\/haproxy.conf<\/code><\/p>\n<p>The following is an example of a basic configuration for HTTP and HTTPS on two backend servers which are using the addresses 192.168.1.10 and 192.168.1.11. The &#8220;stats page&#8221; section is enabled in this example, which will allow you to better monitor the status of each individual proxy port.<\/p>\n<p><code class=\"gris\">global<br \/>\n    log         127.0.0.1 local2<br \/>\n    chroot      \/var\/lib\/haproxy<br \/>\n    pidfile     \/var\/run\/haproxy.pid<br \/>\n    maxconn     16384<br \/>\n    user        haproxy<br \/>\n    group       haproxy<br \/>\n    daemon<br \/>\n    # turn on stats unix socket<br \/>\n    stats socket \/var\/run\/haproxy.cmd<\/code><\/p>\n<p><code class=\"gris\">defaults<br \/>\n    mode                    http<br \/>\n    log                     global<br \/>\n    option                  httplog<br \/>\n    option                  dontlognull<br \/>\n    option                  httpclose<br \/>\n    option forwardfor       except 127.0.0.0\/8<br \/>\n    option                  redispatch<br \/>\n    retries                 3<br \/>\n    timeout http-request    10s<br \/>\n    timeout queue           1m<br \/>\n    timeout connect         10s<br \/>\n    timeout client          45s<br \/>\n    timeout server          45s<br \/>\n    timeout check           10s<br \/>\n    maxconn                 16384<\/code><\/p>\n<p><code class=\"gris\">listen stats :9000<br \/>\n    mode http<br \/>\n    stats enable<br \/>\n    stats uri \/haproxy<br \/>\n    stats realm HAProxy\\ Statistics<br \/>\n    stats auth haproxy:password<br \/>\n    stats admin if TRUE<\/code><\/p>\n<p><code class=\"gris\">listen http :80<br \/>\n        balance leastconn<br \/>\n        option http-server-close<br \/>\n        option forwardfor<br \/>\n        server web1 192.168.1.10:80 check inter 3000 rise 2 fall 3<br \/>\n        server web2 192.168.1.11:80 check inter 3000 rise 2 fall 3<\/code><\/p>\n<p><code class=\"gris\">listen https :443<br \/>\n        balance leastconn<br \/>\n        option http-server-close<br \/>\n        option forwardfor<br \/>\n        server web1 192.168.1.10:443 check inter 3000 rise 2 fall 3<br \/>\n        server web2 192.168.1.11:443 check inter 3000 rise 2 fall 3<\/code><\/p>\n<p>With the basic configuration above, you will be able to send traffic through ports 80 and 443 of both back-end web servers.<\/p>\n<p>It will be necessary to restart HAProxy instance in order for it to reflect the changes made to the configuration file.<\/p>\n<p><code>service haproxy restart<\/code><\/p>\n<p>After restarting, visit the statistics URL to confirm that ports 80 and 443 are opened and traffic can flow through. Navigate to your proxy IP on port 9000 (for example, http:\/\/67.215.1.1:9000).<\/p>\n<p>Once you&#8217;ve ensured that HAproxy is operating as intended, set it to start automatically on boot:<\/p>\n<p><code>systemctl enable haproxy<\/code><\/p>\n<p>If you wish to monitor your proxy status from the command line, you can install and open hatop.<\/p>\n<p><code>wget http:\/\/hatop.googlecode.com\/files\/hatop-0.7.7.tar.gz<br \/>\ntar xvf hatop-0.7.7.tar.gz<br \/>\ncd hatop-0.7.7<br \/>\ninstall -m 755 bin\/hatop \/usr\/local\/bin<br \/>\nhatop -s \/var\/run\/haproxy.cmd<\/code><\/p>\n<p>To avoid having to enter the -s parameter when calling hatop, insert the following line in your ~\/.bashrc file:<\/p>\n<p><code>echo \"alias hatop='hatop -s \/var\/run\/haproxy.cmd'\" >> ~\/.bashrc<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>Now that HAProxy is successfully installed and configured, you should notice improved performance and responsiveness in your web application. With careful monitoring and experimentation, you may discover ways to further adjust the load balancing in response to changed conditions in the future. If this guide was helpful to you, kindly share it with others who may also be interested. <\/p>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>How to install HAProxy on CentOS 7 HAProxy is a free HTTP\/TCP high availability load balancer and proxy server. It spreads requests among multiple servers to mitigate issues resulting from single server failure. It is used by many well known highly trafficked websites such as Github, Stack Overflow and Reddit to improve uptime statistics. Getting<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[70],"tags":[],"class_list":["post-2207","post","type-post","status-publish","format-standard","hentry","category-web-hosting","operating_system-centos-7"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.1 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to install HAProxy on CentOS 7 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now &amp; Enjoy this free HTTP\/TCP high availability load balancer!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to install HAProxy on CentOS 7 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now &amp; Enjoy this free HTTP\/TCP high availability load balancer!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-13T18:19:26+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-11-24T22:57:08+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1920\" \/>\n\t<meta property=\"og:image:height\" content=\"963\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"GloboTech Communications\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"GloboTech Communications\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/\"},\"author\":{\"name\":\"GloboTech Communications\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"headline\":\"How to install HAProxy on CentOS 7\",\"datePublished\":\"2016-07-13T18:19:26+00:00\",\"dateModified\":\"2017-11-24T22:57:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/\"},\"wordCount\":350,\"commentCount\":3,\"articleSection\":[\"Web Hosting\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/\",\"name\":\"How to install HAProxy on CentOS 7 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\"},\"datePublished\":\"2016-07-13T18:19:26+00:00\",\"dateModified\":\"2017-11-24T22:57:08+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\"},\"description\":\"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now & Enjoy this free HTTP\\\/TCP high availability load balancer!\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/install-haproxy-centos-7\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to install HAProxy on CentOS 7\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#website\",\"url\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/\",\"name\":\"Globo.Tech\",\"description\":\"Welcome to the Official Globo.Tech Learning Center\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.globo.tech\\\/learning-center\\\/#\\\/schema\\\/person\\\/e17784b37f4a4f49b7bc611847912e87\",\"name\":\"GloboTech Communications\",\"sameAs\":[\"http:\\\/\\\/www.gtcomm.net\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to install HAProxy on CentOS 7 - Globo.Tech","description":"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/","og_locale":"en_US","og_type":"article","og_title":"How to install HAProxy on CentOS 7 - Globo.Tech","og_description":"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!","og_url":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/","og_site_name":"Globo.Tech","article_published_time":"2016-07-13T18:19:26+00:00","article_modified_time":"2017-11-24T22:57:08+00:00","og_image":[{"width":1920,"height":963,"url":"https:\/\/www.globo.tech\/learning-center\/wp-content\/uploads\/2016\/09\/GloboTech-Logo.png","type":"image\/png"}],"author":"GloboTech Communications","twitter_misc":{"Written by":"GloboTech Communications","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/#article","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/"},"author":{"name":"GloboTech Communications","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"headline":"How to install HAProxy on CentOS 7","datePublished":"2016-07-13T18:19:26+00:00","dateModified":"2017-11-24T22:57:08+00:00","mainEntityOfPage":{"@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/"},"wordCount":350,"commentCount":3,"articleSection":["Web Hosting"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/","url":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/","name":"How to install HAProxy on CentOS 7 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-07-13T18:19:26+00:00","dateModified":"2017-11-24T22:57:08+00:00","author":{"@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87"},"description":"This tutorial will show you how to install HAProxy on your CentOS 7 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-centos-7\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.globo.tech\/learning-center\/"},{"@type":"ListItem","position":2,"name":"How to install HAProxy on CentOS 7"}]},{"@type":"WebSite","@id":"https:\/\/www.globo.tech\/learning-center\/#website","url":"https:\/\/www.globo.tech\/learning-center\/","name":"Globo.Tech","description":"Welcome to the Official Globo.Tech Learning Center","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.globo.tech\/learning-center\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.globo.tech\/learning-center\/#\/schema\/person\/e17784b37f4a4f49b7bc611847912e87","name":"GloboTech Communications","sameAs":["http:\/\/www.gtcomm.net"]}]}},"_links":{"self":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2207","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/comments?post=2207"}],"version-history":[{"count":6,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2207\/revisions"}],"predecessor-version":[{"id":3892,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2207\/revisions\/3892"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}