{"id":2209,"date":"2016-07-18T10:14:43","date_gmt":"2016-07-18T14:14:43","guid":{"rendered":"https:\/\/www.globo.tech\/learning-center\/?p=2209"},"modified":"2020-02-06T17:33:53","modified_gmt":"2020-02-06T22:33:53","slug":"install-haproxy-ubuntu-16","status":"publish","type":"post","link":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/","title":{"rendered":"How to install HAProxy on Ubuntu 16"},"content":{"rendered":"<h1>How to install HAProxy on Ubuntu 16<\/h1>\n<p>HAProxy is an open-source Linux tool that provides high availability load balancing and proxy services for TCP and HTTP-based network applications. Fue to its easy integration into existing architectures, suitability for high-traffic websites, extreme reliability, and focus on upwards compatibility, it is shipped by default by most mainstream Linux distros.<\/p>\n<p>One of the most basic yet useful features of HAProxy is its proxy service, which is the focus of this tutorial. The proxy service allows for server-side protection against client-side attacks or defects, transparent connections, server offloading, enforcement of policies, protocols, and timeouts, as well as the ability to limit connections in and out to particular namespaces. These abilities of HAProxy make it a powerful tool for any Ubuntu user.<\/p>\n<h2>Getting Started<\/h2>\n<p>To complete this guide, you will need the following:<br \/>\n\u2022 1 Node (<a href=\"https:\/\/www.globo.tech\/cloud-server-pricing\" target=\"_blank\" rel=\"noopener noreferrer\"><b>Cloud Server<\/b><\/a> or <a href=\"http:\/\/www.globo.tech\/dedicated-server-hosting\" target=\"_blank\" rel=\"noopener noreferrer\"><b>Dedicated Server<\/b><\/a>) running a clean installation of Ubuntu 16.<br \/>\n\u2022 All commands should be run as the root user or with sudo capabilities<\/p>\n<p><strong>Prepare Your System<\/strong><\/p>\n<p>Before you can install HAProxy on your system, you must update your Ubuntu instance. First, execute the following command as root or using sudo to update your system with information about the latest versions of packages from the Ubuntu base repositories.<\/p>\n<p><code>sudo apt-get update<\/code><\/p>\n<p>Next, you can update packages on your system with the information fetched above to get the latest releases of installed packages:<\/p>\n<p><code>sudo apt-get upgrade<\/code><\/p>\n<p><strong>Setup HAProxy<\/strong><br \/>\nHAProxy can be installed directly from Ubuntu&#8217;s provided package repositories using this command. Enter yes when prompted and wait for the installation to complete:<\/p>\n<p><code>sudo apt-get install haproxy<\/code><\/p>\n<p>Because HAProxy is disabled initially, use the command sed to set HAProxy&#8217;s status to enabled:<\/p>\n<p><code>sed -i \"s\/ENABLED=0\/ENABLED=1\/g\" \/etc\/default\/haproxy<\/code><\/p>\n<p>Start up the HAProxy service:<\/p>\n<p><code>\/etc\/init.d\/haproxy start<\/code><\/p>\n<p>HAProxy must be configured with basic information for ports to use in order to begin using its services. The configuration file located in \/etc\/haproxy\/haproxy.cfg has two sections, global, which sets process-wide parameters, and proxies, which consists of the defaults, listen, front-end, and back-end sections.<\/p>\n<p>To begin configuration, open the configuration file with the text editor vi:<\/p>\n<p><code>sudo vi \/etc\/haproxy\/haproxy.cfg<\/code><\/p>\n<p>The default configuration file will look something like the following. The front-end defines how requests should be handled and sent to the backend server:<\/p>\n<p><code class=\"gris\"># This is an example of the default configuration file.<br \/>\nglobal<br \/>\nlog \/dev\/log daemon<br \/>\nmaxconn 32768<br \/>\nchroot \/var\/lib\/haproxy<br \/>\nuser haproxy<br \/>\ngroup haproxy<br \/>\ndaemon<br \/>\nstats socket \/run\/haproxy\/admin.sock mode 660 level admin<\/code><\/p>\n<p><code class=\"gris\">defaults<br \/>\nlog global<br \/>\noption logs-health-checks<br \/>\noption log-separate-errors<br \/>\noption dontlog-normal<br \/>\noption socket-stats<br \/>\nretries 3<br \/>\nmaxconn 10000<br \/>\ntimeout connect 5s<br \/>\ntimeout client 50s<br \/>\ntimeout server 450s<\/code><\/p>\n<p>To add a listener on port 80 on localhost for our http proxy, add the following lines to the bottom of the configuration file. The port is configured with <em>bind<\/em>:<\/p>\n<p><code>frontend my-http-frontend<br \/>\nbind :80<br \/>\nmode http<br \/>\ndefault_backend my-http-backend<\/code><\/p>\n<p>Below is an example of a basic configuration file for HAProxy including two back-end servers (192.168.1.10 and 192.168.1.11) for HTTP and HTTPS. A back-end server is a machine that handles forwarded requests from the front-end and is defined by its servers and ports as well as which load algorithm to use.<\/p>\n<p>For HTTPS, we must use the TCP mode unless the haproxy-devel package is installed, which allows https with ssl offloading and certificate configuration. Note that we also enable the &#8220;stats page&#8221; section to allow you to better monitor the status of each proxy port:<\/p>\n<p><code class=\"gris\"># This is an example of the default configuration file that has been modified for two back-end servers and to use stats.<br \/>\nglobal<br \/>\nlog \/dev\/log daemon<br \/>\nmaxconn 32768<br \/>\nchroot \/var\/lib\/haproxy<br \/>\nuser haproxy<br \/>\ngroup haproxy<br \/>\ndaemon<br \/>\nstats socket \/run\/haproxy\/admin.sock mode 660 level admin<\/code><\/p>\n<p><code class=\"gris\">defaults<br \/>\nlog global<br \/>\noption log-health-checks<br \/>\noption log-separate-errors<br \/>\noption dontlog-normal<br \/>\noption socket-stats<br \/>\nretries 3<br \/>\nmaxconn 10000<br \/>\ntimeout connect 5s<br \/>\ntimeout client 50s<br \/>\ntimeout server 450s<\/code><\/p>\n<p><code class=\"gris\">frontend my-http-frontend<br \/>\nbind :80<br \/>\nmode http<br \/>\ndefault_backend my-http-backend<\/code><\/p>\n<p><code class=\"gris\">frontend my-https-frontend<br \/>\nbind :443<br \/>\nmode tcp<br \/>\ndefault_backend my-https-backend<\/code><\/p>\n<p><code class=\"gris\">backend my-http-backend<br \/>\nmode http<br \/>\nserver s1 192.168.1.10 check<br \/>\nserver s2 192.168.1.11 check<\/code><\/p>\n<p><code class=\"gris\">backend my-https-backend<br \/>\nmode tcp<br \/>\nserver s1 192.168.1.10 check<br \/>\nserver s2 192.168.1.11 check<\/code><\/p>\n<p><code class=\"gris\">listen stats<br \/>\nbind :9000<br \/>\nstats enable<br \/>\nstats hide-version<br \/>\nstats refresh 20s<br \/>\nstats show-node<br \/>\nstats uri \/stats<\/code><\/p>\n<p>The basic configuration above will allow you to send traffic on port 80 and 443 of your two back-end web servers. Restart your HAProxy instance to activate the changes performed in the configuration file:<\/p>\n<p><code>\/etc\/init.d\/haproxy restart<\/code><\/p>\n<p><strong>Confirm HAProxy is Running<\/strong><\/p>\n<p>You can check the status quickly on the command line to see if HAProxy is currently running:<\/p>\n<p><code>sudo service haproxy status<\/code><\/p>\n<p>You can also visit the stats url we configured above to confirm that the ports are opened and traffic can flow through. Simply navigate to your proxy IP on port 9000. For example, go to http:\/\/localhost:9000<\/p>\n<p>Enable your HAProxy instance to load on boot. Simply execute the following command:<\/p>\n<p><code>update-rc.d haproxy defaults<\/code><\/p>\n<p>You can also monitor the status of your proxy from the command line using HATOP. HATOP is a third-party application that extracts the statistics from a socket file created by HAProxy. Download the HATOP package and confirm with y for yes when prompted:<\/p>\n<p><code>sudo apt-get install hatop<\/code><\/p>\n<p>Normally when calling HATOP, you must use the -s parameter with the command sudo hatop -s \/var\/run\/haproxy.sock. To avoid having to enter the -s parameter when calling HATOP, you may insert the following line in your ~\/.bashrc file:<\/p>\n<p><code>export unix-socket=SOCKET<\/code><\/p>\n<h2>Conclusion<\/h2>\n<p>After completing this tutorial, you will have a running HAProxy-style proxy service that redirects requests to your desired back-end servers that you can monitor with HATOP. 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 Ubuntu 16 HAProxy is an open-source Linux tool that provides high availability load balancing and proxy services for TCP and HTTP-based network applications. Fue to its easy integration into existing architectures, suitability for high-traffic websites, extreme reliability, and focus on upwards compatibility, it is shipped by default by most mainstream<!-- 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":[75],"tags":[],"class_list":["post-2209","post","type-post","status-publish","format-standard","hentry","category-ha-clustering"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to install HAProxy on Ubuntu 16 - Globo.Tech<\/title>\n<meta name=\"description\" content=\"This tutorial will show you how to install HAProxy on your Ubuntu 16 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-ubuntu-16\/\" \/>\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 Ubuntu 16 - Globo.Tech\" \/>\n<meta property=\"og:description\" content=\"This tutorial will show you how to install HAProxy on your Ubuntu 16 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-ubuntu-16\/\" \/>\n<meta property=\"og:site_name\" content=\"Globo.Tech\" \/>\n<meta property=\"article:published_time\" content=\"2016-07-18T14:14:43+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-02-06T22:33:53+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=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/\",\"url\":\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/\",\"name\":\"How to install HAProxy on Ubuntu 16 - Globo.Tech\",\"isPartOf\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/#website\"},\"datePublished\":\"2016-07-18T14:14:43+00:00\",\"dateModified\":\"2020-02-06T22:33:53+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 Ubuntu 16 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!\",\"breadcrumb\":{\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/#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 Ubuntu 16\"}]},{\"@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 Ubuntu 16 - Globo.Tech","description":"This tutorial will show you how to install HAProxy on your Ubuntu 16 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-ubuntu-16\/","og_locale":"en_US","og_type":"article","og_title":"How to install HAProxy on Ubuntu 16 - Globo.Tech","og_description":"This tutorial will show you how to install HAProxy on your Ubuntu 16 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!","og_url":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/","og_site_name":"Globo.Tech","article_published_time":"2016-07-18T14:14:43+00:00","article_modified_time":"2020-02-06T22:33:53+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":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/","url":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/","name":"How to install HAProxy on Ubuntu 16 - Globo.Tech","isPartOf":{"@id":"https:\/\/www.globo.tech\/learning-center\/#website"},"datePublished":"2016-07-18T14:14:43+00:00","dateModified":"2020-02-06T22:33:53+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 Ubuntu 16 server. Read now & Enjoy this free HTTP\/TCP high availability load balancer!","breadcrumb":{"@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.globo.tech\/learning-center\/install-haproxy-ubuntu-16\/#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 Ubuntu 16"}]},{"@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\/2209","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=2209"}],"version-history":[{"count":9,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2209\/revisions"}],"predecessor-version":[{"id":4711,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/posts\/2209\/revisions\/4711"}],"wp:attachment":[{"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/media?parent=2209"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/categories?post=2209"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.globo.tech\/learning-center\/wp-json\/wp\/v2\/tags?post=2209"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}