使用Keepalived进行Memcached双机热备

本文介绍了如何使用Keepalived在两个节点上配置Memcached的双机热备,包括在节点A和B上的配置步骤,以及如何进行测试。测试过程中提到了使用wireshark抓包工具,并讨论了nopreempt选项的作用以及在虚拟机和物理机中进行故障模拟的注意事项。
摘要由CSDN通过智能技术生成
1.节点A
mkdir -p /etc/keepalived/
vi /etc/keepalived/keepalived.conf

global_defs
{
notification_email
{
admin@example.com
}
notification_email_from admin@ptp.cn
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id HA_1
}

vrrp_instance VMH1 {
state MASTER
interface eth0
virtual_router_id 100
priority 120
smtp_alert
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.73.203
}
}


2.节点B
mkdir -p /etc/keepalived/
vi /etc/keepalived/keepalived.conf

global_defs
{
notification_email
{
admin@example.com
}
notification_email_from admin@ptp.cn
smtp_server 127.0.0.1
stmp_connect_timeout 30
router_id HA_2
}

vrrp_instance VMH1 {
state BACKUP
interface eth0
virtual_router_id 100
priority 150
smtp_alert
nopreempt
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.73.203
}
}

3.测试
安装wireshark抓包工具。
#yum install wireshark。注意这样并无法使用wireshark命令和图形界面。但提供了抓包基本功能。
#yum install wireshark-gnome。这样就可以方便使用图形了。

service keepalived restart
查看日志
tail -f /var/log/messages

通过ip a可以看到VIP

在节点A中service keepalived stop后,可以在节点B的日志看到:

un 20 01:25:38 localhost Keepalived_vrrp[1728]: VRRP_Instance(VMH1) Transition to MASTER STATE
Jun 20 01:25:39 localhost Keepalived_vrrp[1728]: VRRP_Instance(VMH1) Entering MASTER STATE
Jun 20 01:25:39 localhost Keepalived_vrrp[1728]: VRRP_Instance(VMH1) setting protocol VIPs.
Jun 20 01:25:39 localhost avahi-daemon[1760]: Registering new address record for 192.168.73.203 on eth0.IPv4.
Jun 20 01:25:39 localhost Keepalived_healthcheckers[1727]: Netlink reflector reports IP 192.168.73.203 added
Jun 20 01:25:39 localhost Keepalived_vrrp[1728]: VRRP_Instance(VMH1) Sending gratuitous ARPs on eth0 for 192.168.73.203
Jun 20 01:25:44 localhost Keepalived_vrrp[1728]: VRRP_Instance(VMH1) Sending gratuitous ARPs on eth0 for 192.168.73.203


可以通过ping来测试是否成功切换。

[b]备注[/b]
1.关于nopreempt:
在实际生产环境中,当master故障停止以后,由backup接替工作,如果此时原先的master正常了,正常情况下,又会重新选举,来切换主控权,这是不能容忍的,所以有了这个选项。这个选项对应的是vrrp RFC文档中的preempt_mod,又来决定是否让高优先级的备份机来重新选举夺得低优先级的master的主控权。有两个值,一个是FALSE即不抢夺,一个是TRUE即抢夺,默认是TRUE,所以就有了 nopreempt。
nopreempt节点的初始状态必须是BACKUP,keepalived.conf中的man有说明
[quote]
# VRRP will normally preempt a lower priority
# machine when a higher priority machine comes
# online. "nopreempt" allows the lower priority
# machine to maintain the master role, even when
# a higher priority machine comes back online.
# NOTE: For this to work, the initial state of this
# entry must be BACKUP.
nopreempt
[/quote]
2.在虚拟机中的问题
在虚拟机中不能使用ifdown eth0这种方式来测试,因为我在测试的过程中遇到过ifdown之后,Backup中还是能收到Master的广播包。虚拟机中可以通过kill keepalived进程来测试。
[b]在物理机中也同时不能使用ifdown eth0这种方式来测试。[/b]

参考:
http://blog.sina.com.cn/s/blog_5f190fff0101e9ht.html
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值