Difference between revisions of "Keepalived"

From UVOO Tech Wiki
Jump to navigation Jump to search
Line 13: Line 13:
 
```
 
```
 
global_defs {
 
global_defs {
  notification_email {
+
    notification_email {
    myuser@example.com
+
        sysadmin@example.com
    failover@example.com
+
        failover@example.com
    sysadmin@example.com
+
    }
  }
+
    # notification_email_from no-reply@example.com
  # notification_email_from Alexandre.Cassen@example.com
+
    # smtp_server 192.168.200.1
  # smtp_server 192.168.200.1
+
    # smtp_connect_timeout 30
  # smtp_connect_timeout 30
+
    router_id ADC_DEV
  router_id LVS_DEVEL
+
    vrrp_skip_check_adv_addr
  vrrp_skip_check_adv_addr
+
    vrrp_garp_interval .001
  # vrrp_strict  # Breaks using auth_type PASS - https://askubuntu.com/questions/1312333/keepalived-not-working-on-20-04
+
    vrrp_gna_interval .001
  vrrp_garp_interval 0
+
    enable_script_security
  vrrp_gna_interval 0
+
    script_user nobody
 
}
 
}
 +
 +
 +
vrrp_script chk_ipaddr {
 +
    script "/usr/bin/ping -c 1 172.16.0.1"
 +
    interval 2
 +
    weight 2
 +
}
 +
 +
 +
vrrp_script chk_nginx {
 +
    script "/usr/bin/pgrep '^nginx$'"
 +
    interval 2
 +
    weight 2
 +
}
 +
  
 
vrrp_instance VI_1 {
 
vrrp_instance VI_1 {
Line 42: Line 57:
 
         192.168.200.17
 
         192.168.200.17
 
         192.168.200.18
 
         192.168.200.18
 +
    }
 +
    track_script {
 +
        chk_ipaddr
 +
        chk_nginx
 
     }
 
     }
 
}
 
}

Revision as of 17:22, 2 June 2021

Refs

apt update && apt install keepalived
sudo useradd -r -s /bin/false keepalived_script

/etc/keepalived/keepalived.conf

global_defs {
    notification_email {
        sysadmin@example.com
        failover@example.com
    }
    # notification_email_from no-reply@example.com
    # smtp_server 192.168.200.1
    # smtp_connect_timeout 30
    router_id ADC_DEV
    vrrp_skip_check_adv_addr
    vrrp_garp_interval .001
    vrrp_gna_interval .001
    enable_script_security
    script_user nobody
}


vrrp_script chk_ipaddr {
    script "/usr/bin/ping -c 1 172.16.0.1"
    interval 2
    weight 2
}


vrrp_script chk_nginx {
    script "/usr/bin/pgrep '^nginx$'"
    interval 2
    weight 2
}


vrrp_instance VI_1 {
    state MASTER
    interface eth0
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.200.16
        192.168.200.17
        192.168.200.18
    }
    track_script {
        chk_ipaddr
        chk_nginx
    }
}

Logs

systemctl status keepalived
journalctl -f

capture multicast traffic

sudo tcpdump -npi eth0 net 224
16:10:05.472897 IP 172.16.0.167 > 224.0.0.18: VRRPv2, Advertisement, vrid 51, prio 100, authtype none, intvl 1s, length 28

```