Debian 12 bookworm
Sponsored Link

Keepalived : Monitor processes2023/08/25

 

Monitoring processes with Keepalived.

This example is based on the environment like follows.

                            VIP:10.0.0.30
+----------------------+          |          +----------------------+
|  [node01.srv.world]  |10.0.0.51 | 10.0.0.52|  [node02.srv.world]  |
|     Keepalived#1     +----------+----------+     Keepalived#2     |
|                      |                     |                      |
+----------------------+                     +----------------------+

[1]

Configure basic Keepalived settings, refer to here.

[2] For example, in addition to basic Keepalived settings, add settings to monitor sshd process.
root@node01:~#
vi /etc/keepalived/keepalived.conf
global_defs {
    router_id node01
    notification_email {
        root@localhost
    }
    notification_email_from root@node01.srv.world
    smtp_server localhost
    smtp_connect_timeout 30
}

# add monitoring setting for sshd process
vrrp_track_process track_sshd {
    process sshd
    delay 1
}

vrrp_instance VRRP1 {
    state MASTER
    # nopreempt
    interface enp1s0
    virtual_router_id 101
    priority 200
    advert_int 1
    virtual_ipaddress {
        10.0.0.30/24
    }
    # add
    track_process {
        track_sshd
    }
    smtp_alert
}

root@node01:~#
systemctl restart keepalived
[3] That's OK. Verify failover and failback when sshd would be down.
# primary node

root@node01:~#
ip address show enp1s0

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:5b:6d:b6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.51/24 brd 10.0.0.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet 10.0.0.30/24 scope global secondary enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe5b:6db6/64 scope link
       valid_lft forever preferred_lft forever

root@node01:~#
systemctl stop sshd

root@node01:~#
ip address show enp1s0

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:5b:6d:b6 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.51/24 brd 10.0.0.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe5b:6db6/64 scope link
       valid_lft forever preferred_lft forever

root@node01:~#
ssh debian@node02 "ip address show enp1s0"

debian@node02's password:
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:17:b6:c0 brd ff:ff:ff:ff:ff:ff
    inet 10.0.0.52/24 brd 10.0.0.255 scope global enp1s0
       valid_lft forever preferred_lft forever
    inet 10.0.0.30/24 scope global secondary enp1s0
       valid_lft forever preferred_lft forever
    inet6 fe80::5054:ff:fe17:b6c0/64 scope link
       valid_lft forever preferred_lft forever
Matched Content