Keepalived
Virtual IPs, Heartbeat and more.
Configuration
Server1: /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state MASTER
interface vmbr1
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
notify_master /etc/keepalived/notify_master.sh
notify_backup /etc/keepalived/notify_backup.sh
notify_stop /etc/keepalived/notify_stop.sh
virtual_ipaddress {
10.0.0.1/24
}
}
Server2: /etc/keepalived/keepalived.conf
vrrp_instance VI_1 {
state BACKUP
interface vmbr1
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass password
}
notify_master /etc/keepalived/notify_master.sh
notify_backup /etc/keepalived/notify_backup.sh
notify_stop /etc/keepalived/notify_stop.sh
virtual_ipaddress {
10.0.0.1/24
}
}
Scripts
For /etc/keepalived/notify_master.sh
:
#!/bin/bash
drbdadm primary r0
mount /dev/drbd0 /srv/nfspoint
systemctl start nfs-kernel-server.service
For /etc/keepalived/notify_backup.sh
:
#!/bin/bash
systemctl stop nfs-kernel-server.service
umount /srv/nfspoint
drbdadm secondary r0
For /etc/keepalived/notify_stop.sh
:
#!/bin/bash
systemctl stop nfs-kernel-server.service
umount /srv/nfspoint
drbdadm secondary r0
systemctl restart nfs-kernel-server.service
Testing it out
Make sure the scripts run. By default they run as root
which is fine for now - keepalived attempts to run the scripts as some keepalived_script
user which I tried to create, but just haven’t figured out permissions on yet.
Nothing crazy going on with the keepalive configuration. Showing the ip addresses informs you of the primary node running.
ip -brief address show
Starting the service and testing it out is as simple as: Spinning up keepalived on both servers and then grabbing ip information and then stopping the service on the primary server to confirm failover works.
#both servers
systemctl start keepalived.service
#confirm the vip is on p1, should show up in the list under the device
ip -brief address show
#stop the keepalived service on the primary node
systemctl stop keepalived.service
Links
- Redhat - Setting up Keepalived
- Redhat - Advanced HA
- Redhat - basic keepalived
- Setup DRBD Storage Replication on Centos7
- SO - Unmounting a busy Device
- SO - Files that cant be stat’d
- How to mount an NFS share
- Running VRRP as a non-root user
- Keepalived+drbd+nfs
- Simple Keepalived
- Linuxjournal Keepalived