Master‑Backup High Availability with Keepalived: Step‑by‑Step Guide
This tutorial walks you through configuring Keepalived for single‑instance master‑backup failover and dual‑instance dual‑master high‑availability setups, covering preparation, installation, configuration file edits, service startup, verification of virtual IP migration, and practical verification commands.
Preface
In previous sections we covered Keepalived overview, principles, and detailed config file analysis; now we use several configuration examples to help you master Keepalived high availability.
Single‑Instance Master‑Backup Mode
Configure Keepalived to achieve automatic IP failover for a single instance.
1. Prepare two machines
2. Install Keepalived
yum -y install keepalivedInstall on both qll251 and qll252.
3. Modify configuration file
3.1 qll251 as MASTER
vim /etc/keepalived/keepalived.confInstance VI_1 on qll251 is MASTER, ID 60, priority 150, floating IP 10.43.187.201.
Only note: server qll251 is master for instance VI_1 with ID 60, priority 150, floating IP 10.43.187.201.
3.2 qll252 as BACKUP
vim /etc/keepalived/keepalived.conf4. Start Keepalived service
systemctl start keepalivedBoth MASTER and BACKUP nodes must start the service.
5. Verify VIP automatic failover
Because qll251 priority > qll252, qll251 becomes MASTER and holds VIP 10.43.187.201.
qll252 as BACKUP has no floating IP.
High‑availability switch experiment
(1) Stop Keepalived on qll251 to simulate MASTER failure.
(2) Backup node takes over the VIP.
(3) Check logs for master‑backup transition.
Logs show backup node qll252 has taken over VIP 10.43.187.201, sending ARP broadcasts so clients update their ARP tables.
When the original master is restarted, it re‑claims the VIP because its priority is higher.
Result: single‑instance Keepalived provides IP automatic failover.
Dual‑Instance Dual‑Master Mode
In this mode, business A is master on qll251 and backup on qll252, while business B is opposite.
1. Prepare two machines
IP and VIP planning diagram:
2. Install Keepalived
yum -y install keepalivedInstall on both servers.
3. Modify configuration files
3.1 qll251 configuration
[root@qll251 ~]# vim /etc/keepalived/keepalived.conf<br/>14 state MASTER<br/>15 interface eth0<br/>16 virtual_router_id 60<br/>17 priority 150<br/>18 advert_int 1<br/>19 authentication {<br/>20 auth_type PASS<br/>21 auth_pass 1111<br/>22 }<br/>23 virtual_ipaddress {<br/>24 10.43.187.201/24 dev eth0 label eth0:1<br/>25 }<br/>26 }<br/>27<br/>28 vrrp_instance VI_2 {<br/>29 state BACKUP<br/>30 interface eth0<br/>31 virtual_router_id 61<br/>32 priority 100<br/>33 advert_int 1<br/>34 authentication {<br/>35 auth_type PASS<br/>36 auth_pass 1111<br/>37 }<br/>38 virtual_ipaddress {<br/>39 10.43.187.202/24 dev eth0 label eth0:2<br/>40 }<br/>41 }Instance VI_1 is master on qll251, VI_2 is backup.
3.2 qll252 configuration
[root@qll252 ~]# vim /etc/keepalived/keepalived.conf<br/>14 state BACKUP<br/>15 interface eth0<br/>16 virtual_router_id 60<br/>17 priority 100<br/>18 advert_int 1<br/>19 authentication {<br/>20 auth_type PASS<br/>21 auth_pass 1111<br/>22 }<br/>23 virtual_ipaddress {<br/>24 10.43.187.201/24 dev eth0 label eth0:1<br/>25 }<br/>26 }<br/>27<br/>28 vrrp_instance VI_2 {<br/>29 state MASTER<br/>30 interface eth0<br/>31 virtual_router_id 61<br/>32 priority 150<br/>33 advert_int 1<br/>34 authentication {<br/>35 auth_type PASS<br/>36 auth_pass 1111<br/>37 }<br/>38 virtual_ipaddress {<br/>39 10.43.187.202/24 dev eth0 label eth0:2<br/>40 }<br/>41 }Instance VI_1 is backup, VI_2 is master on qll252.
The key differences are the state and priority values.
4. Verification
Stop Keepalived on both nodes, then start them sequentially and check IP bindings.
// On qll251<br/>systemctl start keepalived<br/>ip a | egrep "10.43.187.201|10.43.187.202"<br/># shows 10.43.187.201 and 10.43.187.202 on eth0:1 and eth0:2<br>// On qll252<br/>systemctl start keepalived<br/>ip a | egrep "10.43.187.201|10.43.187.202"<br/># shows 10.43.187.202 only<br/>When either node fails, the VIPs switch to the other node, enabling separate services (e.g., www.cloud.com on 10.43.187.201, bbs.cloud.com on 10.43.187.202).
Conclusion
If you found this guide useful, please like or share.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Open Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
