Keepalived

From wiki.techunit.org
Jump to: navigation, search

Installation and configuration

Install keepalived

  • On all nodes
aptitude install keepalived -y

Minimal failover configuration

  • On both nodes, edit edit /etc/keepalived/keepalived.conf
#master node
vrrp_instance VI_1 
{
#debug
 interface eth0
 state MASTER
 virtual_router_id 51 # Must be the same as Slave
 priority 150 # Stronger than 100
 advert_int 1
#garp_master_delay 1
#lvs_sync_daemon_interface eth0   # Can specify another interface to control the cluster status
 virtual_ipaddress 
 {
  10.0.0.1/24 dev eth0 # Virtual IP is 10.0.0.1
 #10.0.0.13/24 dev eth0 # Can add multiple VIP
 }
#Can be in bash, python, perl, php ...
 notify_master "/path/to/the/script arg1 arg2"
 notify_backup "/path/to/the/script arg1 arg2"
 notify_fault "/path/to/the/script arg1 arg2"
 notify_stop "/path/to/the/script arg1 arg2"
}
#slave node
vrrp_instance VI_1
{
 interface eth0
 state BACKUP
 virtual_router_id 51
 priority 100
 advert_int 1
#garp_master_delay 1
#lvs_sync_daemon_interface eth0
 virtual_ipaddress 
 {
  10.0.0.1/24 dev eth0 # Virtual IP is 10.0.0.1
 }
 notify_master "/path/to/the/script arg1 arg2"
 notify_backup "/path/to/the/script arg1 arg2"
 notify_fault "/path/to/the/script arg1 arg2"
 notify_stop "/path/to/the/script arg1 arg2"
}
  • Restart service
/etc/init.d/keepalived restart

Global definitions

Email notifications

  • Add this section and adapt to /etc/keepalived/keepalived.conf
global_defs 
{
 notification_email 
 {
  sysadmin@example.com
  technical@example.com
  rd@example.com
 }
 notification_email_from keepalived_server@example.com
 smtp_server 10.0.0.69
 smtp_connect_timeout 30
 router_id LVS_DEVEL
}
  • Add this line to the vrrp instance (or sync_group) : smtp_alert

VRRP synchronization groups

  • Group of IPs that failover together
vrrp_sync_group VG_1 
{
#Group of IPs that failover together
 group 
 {
  VI_1
  VI_2
  VI_3
 }
 # notify scripts and alerts are optional
 notify_master "/path/to/the/script arg1 arg2"
 notify_backup "/path/to/the/script arg1 arg2"
 notify_fault "/path/to/the/script arg1 arg2"
 notify_stop "/path/to/the/script arg1 arg2"
 smtp_alert
}

Monitore services

  • Example for squid Proxy, add and adapt this section in /etc/keepalived/keepalived.conf
virtual_server 10.0.0.1 3128 
{
 delay_loop 30
 lb_algo wrr
 lb_kind DR
 persistence_timeout 50
 protocol TCP

 real_server 10.0.0.2 3128 
 {
  weight 1
  inhibit_on_failure
  TCP_CHECK 
  {
   connect_port 3128
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 1
  }
 }
 real_server 10.0.0.3 3128 
 {
  weight 1
  inhibit_on_failure
  TCP_CHECK 
  {
   connect_port 3128
   connect_timeout 3
   nb_get_retry 3
   delay_before_retry 1
  }
 }
}

Elliot
techUnit's cofounder