HeartBeat

601次阅读

共计 1626 个字符,预计需要花费 5 分钟才能阅读完成。

一,原理介绍

(Linux-HA)的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未收到对方发送的报文,那么就认为对方失效,这时需启动资源接管模块来接管运 行在对方主机上的资源或者服务。

二,环境

Server1.example.com

Server2.example.com

三,安装软件

从49下载以下文件:

heartbeat-3.0.4-2.el6.x86_64.rpm        heartbeat-libs-3.0.4-2.el6.x86_64.rpm

heartbeat-devel-3.0.4-2.el6.x86_64.rpm  ldirectord-3.9.5-3.1.x86_64.rpm

#Yum install * -y

 

四,配置

4.1 复制模板文件

#Cp /usr/share/doc/heartbeat-3.0.4/ha.cf haresources authkeys /etc/ha.d/

#Cd /etc/ha.d

4.2 配置文件

vim ha.cf

24 debugfile /var/log/ha-debug                                 ###调试文件目录

29 logfile /var/log/ha-log                                           ###日志文档

48 keepalive 2                                                                 ###检测频率

56 deadtime 30                                              ###30s无心跳,则认为宕机

61 warntime 10                                             ###10s无心跳,则警告

76 udpport 743                                           #服务端口。默认694,做实验避免冲突

91 bcast   eth0                                             ###采用广播

211 node    server1.example.com             ###节点,谁在上面谁为主,必须是hostname

212 node    server2.example.com

220 ping 172.25.49.250                               ###网络测试

253 respawn hacluster /usr/lib64/heartbeat/ipfail

259 apiauth ipfail gid=haclient uid=hacluster

#Vim haresources

server1.example.com   IPaddr::172.25.49.100/24/eth0 httpd  添加vip地址和节点服务

#Vim authkeys

auth 1                               ###采用crc,铭文方式,最不可靠,但简单

1 crc

4.3 启动服务

#/etc/init.d/heartbeat start

4.4 查看日志

#tail -f /var/log/ha-log

 

将配置文件发送到另外一个节点server2:

#Scp ha.cf authkeys haresources 172.25.49.2:/etc/ha.d/

在server2.example.com上启动服务:

#/etc/init.d/heartbeat start

五,测试

访问vip:172.25.49.100,显示:

Server1.example.com

停止server1上面的heartbeat服务,server2检测不到,自动接管,则显示server2.example.com

正文完
 
mervinwang
版权声明:本站原创文章,由 mervinwang 2016-03-03发表,共计1626字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
文章搜索