安装keepalived
yum -y install keepalived
启动与自启keepalived
systemctl start keepalived
systemctl enable keepalived
修改配置文件
vim /etc/keepalived/keepalived.conf
主节点
! Configuration File for keepalived
vrrp_instance VI_1 {
state MASTER # 指定初始状态(由priority高低决定)
interface ens33 # VIP绑定的网卡
virtual_router_id 51 # 相同的 VRID 为一个组
priority 100 # 设置优先级,优先级高的为 master
advert_int 1 # 检查间隔,默认为 1 秒
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.144 # VIP
}
}
从节点
! Configuration File for keepalived
vrrp_instance VI_1 {
state BACKUP
interface ens33
virtual_router_id 51
priority 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
192.168.0.144
}
}
两个节点修改完配置文件后,重启keepalived服务。
systemctl restart keepalived
效果
VIP 出现在主节点上
主节点上出现VIP。当停止主节点上的keepalived时,从节点出现 VIP;当停止从节点上的 keepalived 并恢复主节点的 keepalived 时,主节点出现VIP。即VIP在两个节点之间会浮动。
VIP可以ping通
注意点
virtual_router_id必须设置,否则keepalived会异常退出。
参考资料
标签:配置,keepalived,VIP,virtual,id,vip,auth,节点 From: https://www.cnblogs.com/WJQ2017/p/17207719.html