环境概览
master:192.168.46.26 slave1:192.168.46.27 测试机:192.168.46.22(用于ping机器)
安装keepalived
yum install -y keepalived
修改master keepalived.conf 配置文件
vim /etc/keepalived/keepalived.conf
interface 修改为自己的网卡(使用 ip addr 查看) priority 修改其参数为188 设置为主节点 virtual_ipaddress 配置虚拟ip
重启 keepalive 服务
systemctl restart keepalived.service
查看 虚ip是否启动成功
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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 qlen 1000
link/ether 00:0c:29:f5:3d:f3 brd ff:ff:ff:ff:ff:ff
inet 192.168.46.26/18 brd 192.168.63.255 scope global ens33
valid_lft forever preferred_lft forever
`inet 192.168.46.88/32 scope global ens33`
valid_lft forever preferred_lft forever
inet6 fe80::345:1d44:e755:79c2/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.46.88/32 scope global ens33 表示成功启动虚拟ip
修改slave1 keepalived.conf 配置文件
vim /etc/keepalived/keepalived.conf
interface 修改为自己的网卡(使用 ip addr 查看) priority 默认即可 virtual_ipaddress 配置虚拟ip
重启 keepalive 服务
systemctl restart keepalived.service
查看 虚ip是否启动成功
ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
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 qlen 1000
link/ether 00:0c:29:63:37:39 brd ff:ff:ff:ff:ff:ff
inet 192.168.46.27/18 brd 192.168.63.255 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::34aa:c1e2:dc99:6721/64 scope link
valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN qlen 1000
link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc pfifo_fast master virbr0 state DOWN qlen 1000
link/ether 52:54:00:63:02:0a brd ff:ff:ff:ff:ff:ff
此节点作为从节点使用当主节点挂掉后,会使用此节点
使用测试机器ping 虚拟ip 看是否可以ping通
PING 192.168.46.88 (192.168.46.88) 56(84) bytes of data.
64 bytes from 192.168.46.88: icmp_seq=1 ttl=64 time=0.149 ms
64 bytes from 192.168.46.88: icmp_seq=2 ttl=64 time=0.303 ms
64 bytes from 192.168.46.88: icmp_seq=3 ttl=64 time=0.380 ms
64 bytes from 192.168.46.88: icmp_seq=4 ttl=64 time=0.239 ms
64 bytes from 192.168.46.88: icmp_seq=5 ttl=64 time=0.324 ms
|