In this learning activity, you will install and configure a load balancer to be the front end for two pre-built Apache nodes. The load balancer should be configured to run in the best-effort stickiness mode.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Install HAProxy on `Server1`
Now, we’ll start off by installing HAProxy:
[root@Server1]# yum -y install haproxy
Enable and start the service:
[root@Server1]# systemctl enable haproxy [root@Server1]# systemctl start haproxy
Then verify that incoming port 80 traffic is permitted through the firewall. Running
firewall-cmd --list-all
should showhttp
in the list of allowed services.- Configure HAProxy on `Server1`
We need to configure the HAProxy’s frontend and backend. HAProxy should listen on port 80, and use
node1
andnode2
as the backend nodes. Let’s edit/etc/haproxy/haproxy.cfg
and add the configuration code:timeout check 10s maxconn 3000 # Our code starts here: frontend app1 bind *:80 mode http default_backend apache_nodes backend apache_nodes mode http balance source server node1 10.0.1.20:8080 check server node2 10.0.1.30:8080 check # End of our code #------------------------------------------------------- # main frontend which proxys to the backends #-------------------------------------------------------
We’ll have to restart the daemon so that our changes take effect, then check with
ss
:[root@Server1]# systemctl restart haproxy [root@Server1]# ss -lntp
- Configure the `node1` and `node2` Firewalls
We need to permit incoming port 8080/TCP traffic on
node1
andnode2
. On each node (after logging in, then becomingroot
), perform the following:[root@node]# firewall-cmd --permanent --add-port=8080/tcp
Then reload the firewall configuration:
[root@node]# firewall-cmd --reload
- From `Client1`, Validate That Settings Are Correct
On
Client1
, we can run acurl
on theServer1
private IP address:[cloud_user@Client1]$ curl <Server1_IP_ADDRESS>