keepalived+ip组播



开启ip组播

centos7

centos6

keepalived安装配置

2台主机

server hostname ip
keepalived ka1 192.168.99.103
keepalived ka2 192.168.99.104

1、2台分别安装keepalived

1
2
[ka1]$ yum -y install keepalived
[ka2]$ yum -y install keepalived

2、修改ka1的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
[ka1]# vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived

global_defs {
notification_email {
root@localhost
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka1
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_iptables
vrrp_mcast_group4 224.100.100.100 #不写默认是224.0.0.18
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 11
priority 100
advert_int 1
#nopreempt #非抢占模式,当优先级更高的主机上线时,不会抢占为主服务器
authentication {
auth_type PASS
auth_pass 123
}
virtual_ipaddress {
192.168.0.100 dev eth0 label eth0:1
}
}

3、修改ka2的配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
! Configuration File for keepalived

global_defs {
notification_email {
root@localhost
}
notification_email_from root@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id ka2
vrrp_skip_check_adv_addr
vrrp_strict
vrrp_iptables
vrrp_mcast_group4 224.100.100.100 #不写默认是224.0.0.18
vrrp_garp_interval 0
vrrp_gna_interval 0
}

vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 11
priority 80
advert_int 1
#nopreempt #非抢占模式,当优先级更高的主机上线时,不会抢占为主服务器
authentication {
auth_type PASS
auth_pass 123
}
virtual_ipaddress {
192.168.0.100 dev eth0 label eth0:1
}
}

4、在ka1或ka2新开个终端准备抓包

1
2
3
4
[ka1]$ tcpdump -i eth0 -nn net 224.100.100.100

tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes

5、启动ka2的keepalived(先启动backup)

1
[ka2]$ systemctl restart keepalived

抓到包了。

VIP绑定上了

6、再启动ka1的keepalived(注意看抓包)

1
[ka1]$ systemctl start keepalived

可以看到,宣告的IP变成了ka1的了

VIP漂移到ka1了,因为ka1的优先级比ka2高