A quote from the HAProxy's official website:
"HAProxy is a free, very fast and reliable solution offering high availability, load balancing, and proxying for TCP and HTTP-based applications." [1]
At the time of writing, the latest available HAProxy version in the default CentOS 7 repository is 1.5. What I want to do here is to use the Software Collections repository to obtain the latest available version instead. Software Collections is a project aimed at providing the possibility to install multiple versions of software. [2]
To enable software collections, install the following package:
# yum install centos-release-scl
Then, to install HAProxy:
# yum install rh-haproxy18
# scl enable rh-haproxy18 bash
# systemctl enable rh-haproxy18-haproxy
# systemctl start rh-haproxy18-haproxy
Note: Some info on how paths are different for software installed from SCL:
…
Let's edit configuration to setup our first app that haproxy will handle for us:
vim /etc/opt/rh/rh-haproxy18/haproxy/haproxy.cfg
This file itself provides lots of useful information on how to configure the proxy. For one, let's change the configuration such that we only redirect all requests from port 5000 to port 80, where we already have an apache application. The first thing to do would be to find frontend main section and change default_backend's value to web. web will be our new backend app that needs to be defined like so:
backend web
server default 127.0.0.1:80 check
Now, let's configure HAProxy so that it logs all incoming requests. We'd need to start by making rsyslog start listening for incoming connections:
… [3]
Sep 23 21:16:52 localhost.localdomain haproxy[29883]: 109.41.2.109:26831 [23/Sep/2018:21:16:52.573] main web/default 0/0/0/1/1 304 163 - - ---- 2/2/0/0/0 0/0 "GET / HTTP/1.1"
…