`
yangzb
  • 浏览: 3471323 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

配置Heartbeat

阅读更多

Heartbeat是linux的HA插件,它可以通过主备的互相检测来到达主服务器倒了,自动切换备服务器。不仅可以用于lvs,其他服务也可以使用。
Ldirectord是lvs的启动工具,可以根据配置来启动对应LVS的服务。

由于资源的问题只在2台服务器上配置Heartbeat可以自动切换,没有测试Ldirectord。这部分介绍网上有很多。实际就是在两个配置了一样的LVS Director机器上实现主备的自动切换。

主 eth0:202.106.184.251外网IP,eth1:10.55.37.220内网IP
备 eth0:202.106.184.145外网IP,eth1:10.55.37.145内网IP。
2台服务器都要安装Heartbeat,并配置节点,Heartbeat可以通过串口或网络来检查主节点服务器是否存在,因此2个机器内网IP提供给Heartbeat使用。
在主备两个机器上都要在配置一个VIP,VIP提供用户访问。
VIP:202.106.184.132

Heartbeat的配置
在两个主备D机器上:
安装
yum install heartbeat-ldirectord.i386

yum install heartbeat.i386

配置VIP
vi /etc/sysconfig/network-scripts/ifcfg-eth0:0
DEVICE=eth0:0
IPADDR=202.106.184.132
broadcast=202.106.184.255
NETMASK=255.255.255.255
ONBOOT=yes#开机就启动

/etc/rc.d/init.d/network restart #重启网卡

route add -host 202.106.184.132 dev eth0:0

在两台机器的hosts上把两个主机名 对应的IP地址增加上。
XD_Blog_Web_184_251 202.106.184.251
XD_Blog_Web_184_145 202.106.184.145

配置Heartbeat:

在/usr/share/doc/heartbeat-2.1.3下有配置文件的模板
authkeys 是主备服务器验证配置文件,需要上传到/etc/ha.d/ 权限600
格式
auth 2 #选择哪种认证
#1 crc #crc方式
2 sha1 HI! #sha1加密 后面的”HI!”是密码
#3 md5 Hello! #md5方式

haresources 是Heartbeat主节点和监控服务的配置文件
格式:
XD_Blog_Web_184_251 IPaddr::202.106.184.251/24/202.106.184.255 ipvsadm ldirectord::www
#XD_Blog_Web_184_251主节点的主机名,需要在/etc/hosts下增加主机名 对应的ip地址;
#IPaddr::vip/24/网关;
#ipvsadm ldirectord::www 要切换的服务 及ldirectord读取www这个配置文件

我测试的是httpd服务
XD_Blog_Web_184_251 IPaddr::202.106.184.132/24/202.106.184.255 httpd

ha.cf是Heartbeat的配置文件,主要是在主机down的时候备机如何处理。
bcast    eth1 # 其他参数基本用默认的,这个参数是两台服务器的Heartbeat用什么形式连接,用内网端口eth1连接

node    XD_Blog_Web_184_251#一共有多少个节点就写多少个
node    XD_Blog_Web_184_145
其他参数解释:
serial /dev/ttyS0

使用串口heartbeat - 如果你不使用串口heartbeat, 你必须选择其它的介质,比如以太网bcast (ethernet) heartbeat。如果你使用其它串口heartbeat,修改/dev/ttyS0 为其它的串口设备。

watchdog /dev/watchdog

可选项:watchdog功能提供了一种方法能让系统在出现故障无法提供”heartbeat”时, 仍然具有最小的功能,能在出现故障1分钟后重启该机 器。这个功能可以帮助服务器在确实停止心跳后能够重新恢复心跳。如果你想使用该特性,你必须在内核中装入”softdog” 内核模块用来生成实际的设备文件。想要达到这个目的, 首先输入 “insmod softdog” 加载模块。然后,输入”grep misc /proc/devices” 注意显示的数字 (should be 10).然后, 输入”cat /proc/misc | grep watchdog” 注意输出显示出的数字(should be 130)。现在你可以生成设备文件使用如下命令:”mknod /dev/watchdog c 10 130″ 。

bcast eth1

指定使用的广播heartbeat 的网络接口eth1(修改为eth0, eth2, 或你所使用的接口)

keepalive 2

设置心跳间隔时间为2两秒。

warntime 10

在日志中发出最后心跳”late heartbeat” 前的警告时间设定。

deadtime 30

在30秒后明确该节点的死亡。

initdead 120

在一些配置中,节点重启后需要花一些时间启动网络。这个时间与”deadtime”不同,要单独对待。 至少是标准死亡时间的两倍。

hopfudge 1

可选项: 用于环状拓扑结构,在集群中总共跳跃节点的数量。

baud 19200

串口波特率的设定(bps).

udpport 694

bcast和ucast通讯使用的端口号694 。这是缺省值,官方IANA 使用标准端口号。

nice_failback on

可选项:对那些熟悉Tru64 Unix, 心跳活动就像是”favored member”模式。主节点获取所有资源直到它宕机,同时备份节点启用。一旦主节点重新开始工作, 它将从备份节点重新获取所有资源。这个选项用来防止主节点失效后重新又获得集群资源。

node linuxha1.linux-ha.org

强制选项:通过`uname -n`命令显示出的集群中的机器名。

node linuxha2.linux-ha.org

强制选项:通过`uname -n`命令显示出的集群中的机器名。

respawnuseridcmd

可选项:列出可以被spawned 和监控的命令。例如:To spawn ccm 后台进程,可以增加如下内容:
respawn hacluster /usr/lib/heartbeat/ccm
通知heartbeat 重新以可信任userid身份运行(在我们的例子中是hacluster) 同时监视该进程的”健康”状况,如果进程死掉,重启它。例如ipfail, 内容如下:
respawn hacluster /usr/lib/heartbeat/ipfail
NOTE: 如果进程以退出代码100死掉, 这个进程将不会respawned。

pingping1.linux-ha.orgping2.linux-ha.org ….

可选项:指定ping 的节点。 这些节点不是集群中的节点。它们用来检测网络的连接性,以便运行一些像ipfail的模块。

两个服务器启动Heartbeat
/etc/init.d/heartbeat start

当主服务器关闭时,服务会自动切换到备服务器。
备服务器检查到主服务器没有相应的Log:
heartbeat[9836]: 2008/05/30_15:07:47 WARN: node xd_blog_web_184_251: is dead
heartbeat[9836]: 2008/05/30_15:07:47 WARN: No STONITH device configured.
heartbeat[9836]: 2008/05/30_15:07:47 WARN: Shared disks are not protected.
heartbeat[9836]: 2008/05/30_15:07:47 info: Resources being acquired from xd_blog_web_184_251.
heartbeat[9836]: 2008/05/30_15:07:47 info: Link xd_blog_web_184_251:eth1 dead.
harc[10882]:    2008/05/30_15:07:47 info: Running /etc/ha.d/rc.d/status status
heartbeat[10883]: 2008/05/30_15:07:47 info: No local resources [/usr/share/heartbeat/ResourceManager listkeys xd_blog_web_184_145] to acquire.
mach_down[10911]:       2008/05/30_15:07:47 info: Taking over resource group IPaddr::202.106.184.132/24/202.106.184.255
ResourceManager[10937]: 2008/05/30_15:07:47 info: Acquiring resource group: xd_blog_web_184_251 IPaddr::202.106.184.132/24/202.106.184.255 httpd
IPaddr[10964]: 2008/05/30_15:07:47 INFO: Running OK
mach_down[10911]:       2008/05/30_15:07:47 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down[10911]:       2008/05/30_15:07:47 info: mach_down takeover complete for node xd_blog_web_184_251.
heartbeat[9836]: 2008/05/30_15:07:47 info: mach_down takeover complete.

主服务器恢复,备服务器停止服务器的Log
heartbeat[9836]: 2008/05/30_15:17:48 info: Heartbeat restart on node xd_blog_web_184_251
heartbeat[9836]: 2008/05/30_15:17:48 info: Link xd_blog_web_184_251:eth1 up.
heartbeat[9836]: 2008/05/30_15:17:48 info: Status update for node xd_blog_web_184_251: status init
heartbeat[9836]: 2008/05/30_15:17:48 info: Status update for node xd_blog_web_184_251: status up
harc[11426]:    2008/05/30_15:17:48 info: Running /etc/ha.d/rc.d/status status
heartbeat[9836]: 2008/05/30_15:17:48 info: Status update for node xd_blog_web_184_251: status active
heartbeat[9836]: 2008/05/30_15:17:48 info: all clients are now paused
harc[11442]:    2008/05/30_15:17:48 info: Running /etc/ha.d/rc.d/status status
heartbeat[9836]: 2008/05/30_15:17:48 info: remote resource transition completed.
heartbeat[9836]: 2008/05/30_15:17:48 info: xd_blog_web_184_145 wants to go standby [foreign]
harc[11458]:    2008/05/30_15:17:48 info: Running /etc/ha.d/rc.d/status status
heartbeat[9836]: 2008/05/30_15:17:49 info: standby: xd_blog_web_184_251 can take our foreign resources
heartbeat[11474]: 2008/05/30_15:17:49 info: give up foreign HA resources (standby).
ResourceManager[11487]: 2008/05/30_15:17:49 info: Releasing resource group: xd_blog_web_184_251 IPaddr::202.106.184.132/24/202.106.184.255 httpd
ResourceManager[11487]: 2008/05/30_15:17:49 info: Running /etc/init.d/httpd stop
ResourceManager[11487]: 2008/05/30_15:17:49 info: Running /etc/ha.d/resource.d/IPaddr 202.106.184.132/24/202.106.184.255 stop
IPaddr[11577]: 2008/05/30_15:17:49 INFO: ifconfig eth0:0 down
IPaddr[11551]: 2008/05/30_15:17:49 INFO: Success
heartbeat[11474]: 2008/05/30_15:17:49 info: foreign HA resource release completed (standby).
heartbeat[9836]: 2008/05/30_15:17:49 info: Local standby process completed [foreign].
heartbeat[9836]: 2008/05/30_15:17:51 info: all clients are now resumed
Ldirectord的配置,没有经过测试,将Ldirectord.cf存为www.cf,内容如下:

virtual=202.106.184.132:80 #vip
real=202.106.184.250:80 gate #R机
fallback=127.0.0.1:80 gate
service=http
request=”index.php”
receive=”Test Page”
#virtualhost=some.domain.com.au
scheduler=rr
#persistent=600
#netmask=255.255.255.255
protocol=tcp
checktype=negotiate
checkport=80
#request=”index.php”
#receive=”Test Page”
#virtualhost=www.x.y.z

<!---->

相关日志

由于垃圾评论过多,本站评论只有经过审核才可放出,请大家见谅!

2 Responses to “ 配置Heartbeat ”

  1. 如果把HA01 reboot了呢?
    我这里试着结果HA01重启时HA02接管了,但重启完成后两边都开http了。
    不知道是怎么回事,是HEARTBEAT本来就这样吗?

  2. 你可以把HA01的HTTP关掉,这是访问就会是HA02的了

分享到:
评论
1 楼 Ray_Mysterio 2013-05-04  
我在两台虚拟机上进行配置,只有一个网卡可以么?我现在配置完成以后,只能在本机访问虚拟ip,第三台机器通过浏览器访问不到,找不到虚拟ip.请问原因是什么呢?

相关推荐

Global site tag (gtag.js) - Google Analytics