Random ...
 
December 2017
S M T W T F S
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Tags ...
Links



Linux++:::: HA + Load balancer with keepalived
Posted at 21.Oct,2005 11:51  Comments 0 / Trackbacks 0 / Like this post!
Technorati tag(s):

I've setup load balancing for sites I look after with piranha and keepalived. I've also succeeded in using piranha to also do HA. I haven't tried with keepalived.

Why not stick with piranha? Well, I intend to check out other alternatives for comparison. Also, piranha is not that actively maintained, unlike keepalived.

Get the keepalived tarball at keepalived.org and do the necessary (./configure&&make&&make install). Once installed, we need to edit keepalived.conf. We need to tell keepalived to do vrrp and lvs.:

    ! Configuration File for keepalived

     global_defs {
     notification_email {
     me@domain.com
    }
     notification_email_from me@domain.com #notify failure
     smtp_server 192.168.1.1
     smtp_connect_timeout 30
     lvs_id LVS_DEVEL
     }

     vrrp_sync_group VG_1 {  #our vrrp group
     group {          #has
     VI_1           #our vrrp instance
    }
     }

     vrrp_instance VI_1 {   #our vrrp instance is
     state BACKUP     #a backup
     interface eth0     #on eth0
     virtual_router_id 1  #with the same id as our master
     priority 50      #this needs to be 50 less than the master
     advert_int 1     #don't change this
     virtual_ipaddress { #this is our virt ip
     10.100.100.1/24 brd 10.100.100.255 dev eth0 #web/service add
     192.168.100.100/24 brd 192.168.100.255 dev eth1 #gw for the NATed real servers
    }
     }

     virtual_server 10.100.100.1 80 { #web/service ip
     delay_loop 6
     lb_algo wlc  #we're doing weighted lease conn
     lb_kind NAT   #we're doing NAT
     ! persistence_timeout 15  #whether we want persistence ie to particular server
     protocol TCP

   real_server 192.168.10.1 80 {  #our real server(s)
   weight 1     #weight - depends on box, process, etc
   inhibit_on_failure 0 #take it out if unavailable
    HTTP_GET {   #do a service check
    url {
    path /something
    status_code 200
      }
    connect_timeout 3
    nb_get_retry 3
    delay_before_retry 2
     }
     }

     }

Copy the same config to the other keepalived box, but change state, to MASTER.

Once started, you'd get something like this, (substitute x.x.x.x with the right IP address):

    #master
    Oct 21 10:54:30 keepalivedserver Keepalived: Starting Keepalived v1.1.11 (10/19,2005)
    Oct 21 10:54:30 keepalivedserver Keepalived: Starting Healthcheck child process, pid=30322
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Using LinkWatch kernel netlink reflector...
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Registering Kernel netlink reflector
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Registering Kernel netlink command channel
    Oct 21 10:54:30 keepalivedserver Keepalived_vrrp: Registering gratutious ARP shared channel
    Oct 21 10:54:30 keepalivedserver Keepalived: Starting VRRP child process, pid=30323
    Oct 21 10:54:30 keepalivedserver Keepalived_healthcheckers: Using LinkWatch kernel netlink reflector...
    Oct 21 10:54:30 keepalivedserver Keepalived_healthcheckers: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:30 keepalivedserver Keepalived_healthcheckers: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:30 keepalivedserver Keepalived_healthcheckers: Registering Kernel netlink reflector
    Oct 21 10:54:30 keepalivedserver Keepalived_healthcheckers: Registering Kernel netlink command channel
    Oct 21 10:54:33 keepalivedserver Keepalived_vrrp: Configuration is using : 36939 Bytes
    Oct 21 10:54:33 keepalivedserver Keepalived_vrrp: VRRP sockpool: [ifindex(4), proto(112), fd(8,9)]
    Oct 21 10:54:33 keepalivedserver Keepalived_healthcheckers: Configuration is using : 17006 Bytes
    Oct 21 10:54:33 keepalivedserver Keepalived_healthcheckers: Activating healtchecker for service [x.x.x.x:80]
    Oct 21 10:54:33 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for x.x.x.x
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1 for x.x.x.x
    Oct 21 10:54:34 keepalivedserver Keepalived_healthcheckers: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:34 keepalivedserver Keepalived_healthcheckers: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: VRRP_Group(VG_1) Syncing instances to MASTER state
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:34 keepalivedserver Keepalived_vrrp: Netlink reflector reports IP x.x.x.x added
    Oct 21 10:54:39 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0 for x.x.x.x 
    Oct 21 10:54:39 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1

And if we stop the master keepalived, the backup will take over.:

  Oct 19 11:51:28 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Transition to MASTER STATE
  Oct 19 11:51:28 keepalivedserver Keepalived_vrrp: VRRP_Group(VG_1) Syncing instances to MASTER state
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Entering MASTER STATE
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) setting protocol VIPs.
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: Netlink: error: File exists, type=(20), seq=11296938
  86, pid=0
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: Netlink: error: File exists, type=(20), seq=11296938
  87, pid=0
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0
  for x.x.x.x 
  Oct 19 11:51:29 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1
  for x.x.x.x
  Oct 19 11:51:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth0
  for x.x.x.x 
  Oct 19 11:51:34 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Sending gratuitous ARPs on eth1
  for x.x.x.x
  Oct 19 11:53:21 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Received higher prio advert
  Oct 19 11:53:21 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) Entering BACKUP STATE
  Oct 19 11:53:21 keepalivedserver Keepalived_vrrp: VRRP_Instance(VI_1) removing protocol VIPs.
  Oct 19 11:53:21 keepalivedserver Keepalived_vrrp: VRRP_Group(VG_1) Syncing instances to BACKUP state

And when the MASTER returns from the dead, the state will change, and the BACKUP will be backup.

It's that simple.

/Note: be sure to set ip_forward to 1, else lvs won't work/


Bookmark and Share

Is this entry helpful? Comments/Donate/Click some google ads.  
Trackback is http://myzope.kedai.com.my/blogs/kedai/52/tbping 

Comments
Post a comment