说明
关于 Keepalived 的用途和目的请自行搜索相关信息, 本文只使用最小化配置使 Keepalived 跑起来, 达到故障时漂移 ip 的目的, 避免单点故障。
安装
yum install keepalived -y
常用命令
# 查看状态
sudo systemctl status keepalived
# 启动
sudo systemctl start keepalived
# 停止
sudo systemctl stop keepalived
默认配置在 /etc/keepalived/keepalived.conf
配置
实例一
vrrp_instance VI_1 {
state MASTER
interface ens33
virtual_router_id 51
priority 100
advert_int 2
virtual_ipaddress {
10.4.82.48
}
}
实例二
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 101
advert_int 2
virtual_ipaddress {
10.4.82.48
}
}
配置说明
interface 网卡
priority 优先级
virtual_router_id 保持一致
virtual_ipaddress 虚拟 ip
advert_int 检查频率 单位 秒
实例一
[junbaor@wkfg-1 sbin]$ 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:a7:cd:93 brd ff:ff:ff:ff:ff:ff
inet 10.4.82.141/24 brd 10.4.82.255 scope global dynamic ens33
valid_lft 171585sec preferred_lft 171585sec
inet 10.4.82.48/32 scope global ens33
valid_lft forever preferred_lft forever
inet6 fe80::ce43:fb82:c450:c422/64 scope link
valid_lft forever preferred_lft forever
实例二
[junbaor@wkfg-2 sbin]$ 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:81:c5:4d brd ff:ff:ff:ff:ff:ff
inet 10.4.82.47/24 brd 10.4.82.255 scope global dynamic ens33
valid_lft 172728sec preferred_lft 172728sec
inet6 fe80::40b2:61cf:9620:a5f3/64 scope link
valid_lft forever preferred_lft forever
inet6 fe80::ce43:fb82:c450:c422/64 scope link tentative dadfailed
valid_lft forever preferred_lft forever
可以看到虚拟的ip 10.4.82.48 已经漂移到实例一
这时我们关闭实例一或者停止 keepalived 进程, ip 就会和实例二绑定
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。