# cd /etc/keepalived/
# touch down
在备用节点node2上查看
访问虚拟IP
现在把down文件删除,MASTER节点会夺回资源,因为在node1上的优先级(101)比nod2上的优先级(100)高
双主模式实现
两个主机web服务同时开启,配置的VIP不同,让他们互为主从
修改keepalived.conf配置文件(只需修改配置文件末尾“vrrp_instance VI_2”中的内容)
vrrp_instance VI_2 {
interface eth0
state BACKUP # BACKUP for slave routers
priority 100 # 100 for BACKUP
virtual_router_id 52
garp_master_delay 1
authentication {
auth_type PASS
auth_pass password
}
track_interface {
eth0
}
virtual_ipaddress {
172.16.51.80/16 dev eth0 label eth0:1
}
track_script {
chk_httpd
chk_schedown
}
notify_master "/etc/keepalived/notify.sh master eth0:1"
notify_backup "/etc/keepalived/notify.sh backup eth0:1"
notify_fault "/etc/keepalived/notify.sh fault eth0:1"
}
在node2上启用“vrrp_instance VI_2”中的内容后,修改一下第二VIP地址与脚本名称(track_httpd, chk_schedown)
修改完成后,启动keepalived服务,查看node1与node2上的VIP地址配置
node1主机
node2主机
测试
模拟node1出现故障
# cd /etc/keepalived/
# touch down
查看node2上虚拟IP地址
此时,访问172.16..9.1与192.16.53都是由node2主机返回结果