Task Requirements :
There is a static website running in the Datacenter. They have already configured the app servers and the code is already deployed there. To make it work properly, they need to configure the LBR server. There are several options for that, but the team has decided to go with HAproxy. FYI, apache is running on port 8083 on all app servers. Complete this task as per the below details.
Install and configure HAproxy on the LBR server using yum only and make sure all app servers are added to the HAproxy load balancer. HAproxy must serve on the default HTTP port (Note: Please do not remove stats socket /var/lib/haproxy/stats entry from haproxy default config.).
Once done, you can access the website using the StaticApp button on the top bar
Execution :
Navigate into the LBR server using the ssh command.
ssh username@server-ip-addr
Step 1 - Install HAproxy
sudo yum install haproxy -y
Step 2 - Configure HAproxy
sudo vi /etc/haproxy/haproxy.cfg
Add the following configuration. Make sure to replace app_server_ip1, app_server_ip2, etc., with the actual IP addresses of your application servers.
global
log /dev/log local0
log /dev/log local1 notice
chroot /var/lib/haproxy
stats socket /var/lib/haproxy/stats
defaults
log global
mode http
option httplog
option dontlognull
timeout connect 5000
timeout client 50000
timeout server 50000
frontend
main bind *:80
acl url_static path_beg -i /static /images /javascript /stylesheets
acl url_static path_end -i .jpg .gif .png .css .js
use_backend static if url_static
default_backend app_servers
backend app_servers
balance roundrobin
server app1 app_server_ip1:8083 check
server app2 app_server_ip2:8083 check
server app3 app_server_ip3:8083 check
# Add more servers as needed
Step 3 - Check HAProxy Configuration
haproxy -c -f /etc/haproxy/haproxy.cfg
Step 4 - Restart, Check Status and enable HAProxy to start on boot
sudo systemctl restart haproxy
sudo systemctl status haproxy
sudo systemctl enable haproxy
Accessing the Website