Answer for KodeKloud Question -Install and Configure HaProxy LBR

 There is a static website of Nautilus project running in Stratos Datacenter. Based on the infrastructure, they have already configured app servers and code is already deployed there. To make it work properly, they need to configure LBR server. There are number of options for that, but team has decided to go with HAproxy.

a. So install and configure HAproxy on LBR server using yum only and make sure all app servers are added to HAproxy load balancer. HAproxy must serve on default http port (Note: Please do not remove stats socket /var/lib/haproxy/stats entry from haproxy default config.).

b. You can access the website on LBR link—to do so click on the + button on top of your terminal, select option Select port to view on Host 1, and after adding port 80 click on Display Port.

Sample Answer:

#first you need to log in to all the app servers and find the Listen port ( as per the question app servers are already configured ) also need to start the httpd services too.
    
#login to a server
    ssh <user><server>

#switch to root user
    sudo su

#run below 
    cat /etc/httpd/conf/httpd.conf | grep Listen

  *the output look likes as below ( your port might be different make a note of it we need to use in our haproxy conf file)
    
    Listen 8084

#now start the httpd service ( make sure you started in all the app servers)

    systemctl enable httpd

    systemctl start httpd
    
    systemctl status httpd

* do the above steps in all the app servers 


# now login to LBR server 
    
    ssh <user>@<server>

#switch to root user 
    
    sudo su 

# install the haproxy using yum 
    
    yum -y install haproxy

#copy eixting conf file before making any changes 

    
cp /etc/haproxy/haproxy.cfg /etc/haproxy/haproxy.cfg.backup 

#make sure that you do not change the below entry in the haproxy conf file (mentioned in the question)

    cat /etc/haproxy/haproxy.cfg | grep haproxy/stats

 #now let's add the configuration 
    
    vi /etc/haproxy/haproxy.cfg

frontend  main *: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

backend  app
        balance roundrobin
        server stapp01 172.16.238.10:8084 check
        server stapp02 172.16.238.11:8084 check
        server stapp03 172.16.238.12:8084 check
    
   save the conf file 

* make sure that your configuration as above but (port should be as per your app servers port)

#now validate the haproxy configuration file by running the below command(if there is any error it will show you otherwise its fine)

    haproxy -f /etc/haproxy/haproxy.cfg

#now enable and start the haproxy service 
    
    systemctl enable haproxy

    systemctl start haproxy

#let's verify, run below command from jump server ( port as per your app servers)

    curl 172.16.238.10:8084
    curl 172.16.238.11:8084
    curl 172.16.238.12:8084
    curl 172.16.238.14:80

#also verify as below 

    Click on the + button on top of your terminal, select the option Select port to view on Host 1, and after adding port 80 clicks on Display Port.

Note: **The Question copied it for learning purposes.** Commands are correct but based on your question the server, user name, and other details might differ, so please do check.

No comments:

Post a Comment

Featured Post

Answer for Kodekloud DEVOPS Questions - Init container in Kubernetes

Question: 1. Create a Deployment named as ic-deploy-devops. 2. Configure spec as replicas should be 1 , labels app should be ic-devops , ...