标签:5.0 生效 发送 对比 角色 interface install server ipa
1、Keepalived高可用的工作原理工作原理:在Keepalived服务正常工作时,主Master节点会不断地向备节点发送(多播的方式)心跳消息,用以告诉备Backup节点自己还活着,当主Master节点发生故障时,就无法发送心跳消息,备节点也就因此无法继续检查到来自主Master节点的心跳了,于是调用自身的接管程序,接管主Master节点的IP资源及服务。而当主Master节点恢复时,备Backup节点又会释放主节点故障时自身接管的IP资源及服务,恢复到原来的备用角色。
yum -y install keepalived
配置文件:/etc/keepalived/keepalived.conf
lb01:10.3.151.183(主配置)
lb02:10.3.151.184(备配置)
VIP: 10.3.151.228 (虚拟IP)
! Configuration File for keepalived
global_defs {
notification_email {
345619885@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id lb01 #id为lb01,不同的keepalived.conf此ID要唯一
}
vrrp_instance VI_1 { #实例名字为VI_1,相同实例的备节点名字要和这个相同
state MASTER #主状态为MASTER(必须大写),备节点为BACKUP
interface eth2 #通信接口网卡
virtual_router_id 51 #实例ID为51,keepalived.conf里唯一
priority 150 #优先级为150,数值越大,优先级越高,与BACKUP对比
advert_int 1 #通信检查间隔为1秒
authentication {
auth_type PASS #PASS认证类型
auth_pass 2222 #密码为2222
}
virtual_ipaddress {
10.3.151.228/24 dev eth2 label eth2:1 #虚拟IP地址
}
}
! Configuration File for keepalived
global_defs {
notification_email {
345619885@qq.com
}
notification_email_from Alexandre.Cassen@firewall.loc
smtp_server 192.168.200.1
smtp_connect_timeout 30
router_id lb02
}
vrrp_instance VI_1 {
state BACKUP
interface eth2
virtual_router_id 51
priority 140
advert_int 1
authentication {
auth_type PASS
auth_pass 2222
}
virtual_ipaddress {
10.3.151.228/24 dev eth2 label eth2:1
}
}
[root@yewu-app1 nginx]# ifconfig | grep "inet addr"
inet addr:10.3.151.183 Bcast:10.3.151.255 Mask:255.255.255.0
inet addr:10.3.151.228 Bcast:0.0.0.0 Mask:255.255.255.0
#在主节点,检查VIP是否生效
inet addr:127.0.0.1 Mask:255.0.0.0
[root@yewu-app1 nginx]# /etc/init.d/keepalived stop #停止主节点的keepalived
Stopping keepalived: [ OK ]
[root@yewu-app1 nginx]# ifconfig | grep "inet addr" #VIP已飘走
inet addr:10.3.151.183 Bcast:10.3.151.255 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0
[root@yewu-app2 nginx]# ifconfig | grep "inet addr" #在备节点上查看VIP是否存在
inet addr:10.3.151.184 Bcast:10.3.151.255 Mask:255.255.255.0
inet addr:10.3.151.228 Bcast:0.0.0.0 Mask:255.255.255.0
inet addr:127.0.0.1 Mask:255.0.0.0
标签:5.0 生效 发送 对比 角色 interface install server ipa
原文地址:http://blog.51cto.com/12965094/2146956