1.备份原配置文件
[root@lb01 ~]
[root@lb01 keepalived]
2.参数解释
[root@lb01 keepalived]
1 ! Configuration File for keepalived
2
3 global_defs {
4 notification_email {
5 acassen@firewall.loc
6 failover@firewall.loc
7 sysadmin@firewall.loc
8 }
9 notification_email_from Alexandre.Cassen@firewall.loc
10 smtp_server 192.168.200.1
11 smtp_connect_timeout 30
12 router_id LVS_DEVEL
13 }
14
15 vrrp_instance VI_1 {
16 state MASTER
17 interface eth0
18 virtual_router_id 51
19 priority 100
20 advert_int 1
21 authentication {
22 auth_type PASS
23 auth_pass 1111
24 }
25 virtual_ipaddress {
26 192.168.200.16
27 192.168.200.17
28 192.168.200.18
29 }
30 }
3.配置
3.1 lb-01主节点配置
[root@lb01 keepalived]
[root@lb01 ~]
global_defs {
notification_email {
123456-@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_01
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24
}
3.1 lb-02备节点配置
[root@lb02 ~]
global_defs {
notification_email {
123456-@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id LVS_02
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 51
priority 150
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.0.0.100/24
}
4.启动keepalived
[root@lb01 ~]
5.验证
[root@lb01 ~]# ansible lb -m shell -a "ip add|grep 10.0.0.100"
10.0.0.10 | SUCCESS | rc=0 >>
inet 10.0.0.100/24 scope global secondary eth0
10.0.0.11 | FAILED | rc=1 >>
non-zero return code
===》只有主节点10有100的IP,备节点是没有的。
5.1关掉主节点的keepalived后,查看备节点是否接管
[root@lb01 ~]
10.0.0.10 | SUCCESS => {
"changed": true,
"name": "keepalived",
"state": "stopped"
}
[root@lb01 ~]
10.0.0.10 | FAILED | rc=1 >>
non-zero return code
10.0.0.11 | SUCCESS | rc=0 >>
inet 10.0.0.100/24 scope global secondary eth0
5.2开启主节点,查看备节点是否释放
[root@lb01 ~]
10.0.0.10 | SUCCESS => {
"changed": true,
"name": "keepalived",
"state": "started"
}
[root@lb01 ~]
10.0.0.11 | SUCCESS | rc=0 >>
inet 10.0.0.100/24 scope global secondary eth0
10.0.0.10 | FAILED | rc=1 >>
non-zero return code