一、实现keepalived主主模型
1、环境:
node01:192.168.32.131
node02:192.168.32.133
2、在node01上安装keepalived并且配置
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node01
vrrp_mcast_group4 224.1.101.33
}
vrrp_instance VI_1 {
state MASTER
priority 100
interface ens33
virtual_router_id 51
advert_int 1
authentication {
auth_type PASS
auth_pass IGsPtR1X3w
}
virtual_ipaddress {
192.168.32.188/16 dev ens33
}
}
vrrp_instance VI_2 {
state BACKUP
priority 96
interface ens33
virtual_router_id 50
advert_int 1
authentication {
auth_type PASS
auth_pass IGtR1x3w
}
virtual_ipaddress {
192.168.32.166/16 dev ens33
}
}
3、在node02上安装keepalived并且配置
[root@node02 ~]# vim /etc/hosts
192.168.32.132 node01 node01.hehe.com
192.168.32.128 node02 node02.hehe.com
192.168.32.131 node03 node03.hehe.com
[root@node02 ~]# yum install -y keepalived
[root@node02 ~]# cd /etc/keepalived/
[root@node02 ~]# vim keepalived.conf
! Configuration File for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from keepalived@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id node02
vrrp_mcast_group4 224.1.101.33
}
vrrp_instance VI_1 {
state BACKUP
priority 96
interface ens33
virtual_router_id 51
advert_int 1
authentication {
auth_type PASS
auth_pass IGsPtR1X3w
}
virtual_ipaddress {
192.168.32.188/16 dev ens33
}
}
vrrp_instance VI_2 {
state MATSER
priority 100
interface ens33
virtual_router_id 50
advert_int 1
authentication {
auth_type PASS
auth_pass IGtR1x3w
}
virtual_ipaddress {
192.168.32.166/16 dev ens33
}
}
4、启动node01、node02的keepalived服务并进行查看
[root@node01 ~]# systemctl start keepalived
[root@node02 ~]# systemctl start keepalived
[root@node01 keepalived]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:58:06:b3 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.132/24 brd 192.168.32.255 scope global noprefixroute dynamic ens33
valid_lft 1601sec preferred_lft 1601sec
inet 192.168.32.188/16 scope global ens33:0
valid_lft forever preferred_lft forever
inet6 fe80::3a3f:7950:1d71:a442/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@node02 keepalived]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:7d:4f:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.32.128/24 brd 192.168.32.255 scope global noprefixroute dynamic ens33
valid_lft 1265sec preferred_lft 1265sec
inet 192.168.32.166/16 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::5063:794d:5146:ef79/64 scope link noprefixroute
valid_lft forever preferred_lft forever
可以看到,node01和node02的网卡上面各有一个vip。
5、验证
关闭node02的keepalived服务
[root@node02 keepalived]# systemctl stop keepalived.service
[root@node01 keepalived]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:58:06:b3 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.132/24 brd 192.168.32.255 scope global noprefixroute dynamic ens33
valid_lft 1397sec preferred_lft 1397sec
inet 192.168.32.188/16 scope global ens33:0
valid_lft forever preferred_lft forever
inet 192.168.32.166/16 scope global secondary ens33
valid_lft forever preferred_lft forever
inet6 fe80::3a3f:7950:1d71:a442/64 scope link noprefixroute
valid_lft forever preferred_lft forever
可以看到node01,上面同时有两个vip
当node02keepalived服务启动时,node02的vip又回切到node02的网卡上面
[root@node02 keepalived]# systemctl start keepalived.service
[root@node02 keepalived]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:7d:4f:4b brd ff:ff:ff:ff:ff:ff
inet 192.168.32.128/24 brd 192.168.32.255 scope global noprefixroute dynamic ens33
valid_lft 1244sec preferred_lft 1244sec
inet 192.168.32.166/16 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::5063:794d:5146:ef79/64 scope link noprefixroute
valid_lft forever preferred_lft forever
[root@node01 keepalived]# ip a l
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: ens33: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 00:0c:29:58:06:b3 brd ff:ff:ff:ff:ff:ff
inet 192.168.32.132/24 brd 192.168.32.255 scope global noprefixroute dynamic ens33
valid_lft 1237sec preferred_lft 1237sec
inet 192.168.32.188/16 scope global ens33:0
valid_lft forever preferred_lft forever
inet6 fe80::3a3f:7950:1d71:a442/64 scope link noprefixroute
valid_lft forever preferred_lft forever
网友评论