Make Apache High Available

Simple!

----------

Install Httpd
Install Haproxy
install keepalived
chkconfig allabove on

----------
Haproxy

cat /etc/haproxy/haproxy.cfg

global
#        log 127.0.0.1   local0
#        log 127.0.0.1   local1 notice
#        chroot /var/lib/haproxy
        user haproxy
        group haproxy

defaults
        log     global
        mode    http
        option  httplog
        option  dontlognull
        timeout connect 5000
        timeout client 50000
        timeout server 50000

frontend httpd-80-in
    bind 192.168.254.100:80 --> Virtual IP (try command ip addr)
    option forwardfor
    default_backend httpd

backend httpd
    server s1 192.168.254.139:80 check
    server s2 192.168.254.140:80 check
-----------
Keepalived

cat /etc/keepalived/keepalived.conf

vrrp_script chk_haproxy {
   script "killall -0 haproxy"   # verify the pid existance
   interval 2                    # check every 2 seconds
   weight 2                      # add 2 points of prio if OK
}

vrrp_instance VI_1 {
   interface ens33                # interface to monitor
   state MASTER
   virtual_router_id 51          # Assign one ID for this route
   priority 101                  # 101 on master, 100 on backup
   virtual_ipaddress {
       192.168.254.100            # the virtual IP
   }
   track_script {
       chk_haproxy
   }
}

It will work like simple LB distributing traffic using Round Robin Algorithm. Try to Stop/Restart one of the Httpd server it will not cause any service disruption.

You can make tomcat, jboss, or any application or webserver high available just change the port.

0 comments :

Post a Comment