keepalived实现双主模式
以下称test节点:CentOS release6.3 (Final) 192.168.88.130 test.field.com
以下称www节点:CentOS release6.3 (Final) 192.168.88.131 www.field.com
配置实例:
1、test节点配置:
VI_1:作为主节点
VI_2:作为从节点
[root@testkeepalived]# vi keepalived.conf
! ConfigurationFile for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from kaadimin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test.field.com
vrrp_mcast_group4 224.18.0.200
}
vrrp_scriptchk_maintanance {
script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0"
interval 1
#interval多长时间检查一次
#如果失败返回1权重-2
weight -2
}
vrrp_instanceVI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 4e78bb3a
}
virtual_ipaddress {
192.168.88.80/16 dev eth0 label eth0:0
}
track_script {
#track_script 调用脚本
chk_maintanance
}
}
vrrp_instanceVI_2 {
state BACKUP
interface eth0
virtual_router_id 61
"keepalived.conf"185L, 4211C written
[root@testkeepalived]#
[root@testkeepalived]#
[root@testkeepalived]# vi keepalived.conf
! ConfigurationFile for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from kaadimin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id test.field.com
vrrp_mcast_group4 224.18.0.200
}
vrrp_scriptchk_maintanance {
script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0"
interval 1
#interval多长时间检查一次
#如果失败返回1权重-2
weight -2
}
vrrp_instanceVI_1 {
state MASTER
interface eth0
virtual_router_id 51
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 4e78bb3a
}
virtual_ipaddress {
192.168.88.80/16 dev eth0 label eth0:0
}
track_script {
#track_script 调用脚本
chk_maintanance
}
}
vrrp_instanceVI_2 {
state BACKUP
interface eth0
virtual_router_id 61
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 8eR8bb5L
}
virtual_ipaddress {
192.168.88.90/16 dev eth0 label eth0:1
}
track_script {
#track_script 调用脚本
chk_maintanance
}
}
2、www节点配置:
VI_2:作为主节点
VI_1:作为从节点
[root@wwwkeepalived]# vi keepalived.conf
! ConfigurationFile for keepalived
global_defs {
notification_email {
root@localhost
}
notification_email_from kaadimin@localhost
smtp_server 127.0.0.1
smtp_connect_timeout 30
router_id www.field.com
vrrp_mcast_group4 224.18.0.200
}
vrrp_scriptchk_maintanance {
script "[[ -f /etc/keepalived/down]] && exit 1 || exit 0 "
interval 1
#interval多长时间检查一次
#如果失败返回1权重-20
weight -2
}
vrrp_instanceVI_1 {
state BACKUP
interface eth1
virtual_router_id 51
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 4e78bb3a
}
virtual_ipaddress {
192.168.88.80/16 dev eth1 label eth1:0
}
track_script {
#track_script 调用脚本
chk_maintanance
}
}
vrrp_instanceVI_2 {
state MASTER
interface eth1
virtual_router_id 61
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 8eR8bb5L
}
virtual_ipaddress {
192.168.88.90/16 dev eth1 label eth1:1
}
track_script {
#track_script 调用脚本
chk_maintanance
}
}
keepalived双主模式实现
案例1、keepalived配置单个vip实例
注释VIP实例VI_1,启用VIP实例VI_2
[root@wwwkeepalived]# vi keepalived.conf
使用以下命令注释VI_1
:.,33s/^/#/g
#vrrp_instanceVI_1 {
# state BACKUP
# interface eth1
# virtual_router_id 51
# priority 99
# advert_int 1
# authentication {
# auth_type PASS
# auth_pass 4e78bb3a
# }
# virtual_ipaddress {
# 192.168.88.80/16 dev eth1 label eth1:0
# }
[root@test keepalived]#!1057
servicekeepalived restart;ssh www 'service keepalived restart'
停止 keepalived:[确定]
正在启动 keepalived:[确定]
停止 keepalived:[确定]
正在启动 keepalived:[确定]
[root@testkeepalived]# ip addr list
1: lo:<LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd00:00:00:00:00:00
&n

本文详细介绍了如何使用keepalived实现双主模式的双机热备。通过配置两个节点,每个节点分别作为另一个节点的主和备,利用VRRP_script来监测节点状态,并通过VIP流转确保高可用性。在测试中,创建和删除down文件可以观察VIP在两台机器间的切换,验证了配置的有效性。
最低0.47元/天 解锁文章
2226

被折叠的 条评论
为什么被折叠?



