Make a virtual IP fail over between two nodes with keepalived
Task
Give two Linux nodes a shared virtual IP address with keepalived, so that the address lives on one node and moves to the other if that node stops. Run a continuous ping to the virtual address, stop the active node, and count how long the address was unreachable. That gap is the failover time the lesson says a cluster reduces but never removes.
Steps
- Configure keepalived on lin-srv as
MASTERwith priority 150 and on lin-b asBACKUPwith priority 100, both with the same virtual router ID and the virtual IP 192.168.56.100/24. Save both configuration files tolab/cluster/master.confandlab/cluster/backup.conf. - Start keepalived on both and save
ip -br addrfrom each tolab/cluster/before.txt, showing which node holds the virtual IP. - From win-srv or the host, start a continuous ping to 192.168.56.100 with a timestamp on each reply if your ping supports it.
- Stop keepalived on lin-srv (or shut the VM down). Wait until pings resume, then save
ip -br addrfrom lin-b tolab/cluster/after.txt. - Stop the ping, save its summary to
lab/cluster/ping.txt, and record inlab/cluster/failover.txthow many replies were lost and what that means in seconds. - Start keepalived on lin-srv again and record in
lab/cluster/failback.txtwhether the address moved back automatically, and why (look upnopreempt).
Verify
These checks run in a POSIX shell: Terminal on macOS or Linux, and on Windows Git Bash (it comes with Git for Windows) or WSL. A stock Windows PowerShell or Command Prompt has no awk or grep, so there the first line fails.
grep -c 'MASTER' lab/cluster/master.conf
grep -c 'BACKUP' lab/cluster/backup.conf
grep -c '192.168.56.100' lab/cluster/before.txt lab/cluster/after.txt
grep -Eo '[0-9]+% (packet )?loss' lab/cluster/ping.txt
grep -Ec '[0-9]' lab/cluster/failover.txt
grep -Eic 'preempt|priority' lab/cluster/failback.txt
The virtual IP appears once before the failure and once after it, on the other node. A few replies are lost -- the failover time -- but not all of them. By default the higher-priority node takes the address back when it returns, which is automatic failback; nopreempt turns that off, which is what most production clusters prefer -- but keepalived honours it only when both nodes start in state BACKUP, so added to this lab's MASTER it changes nothing.
Notes
keepalived moves an address, not an application. Real clusters also start the service on the surviving node, check its health, and fence the failed node, which Pacemaker on Linux and Windows Server Failover Clustering both do.
This is an independent study companion for CompTIA Server+ SK0-005 and is not produced by or endorsed by CompTIA.