Heartbeat:
HA即(high available)高可用,又被叫做双机热备,用于关键性业务。简单理解就是,有2台机器 A 和 B,正常是 A 提供服务,B 待命闲置,当 A 宕机或服务宕掉,会切换至B机器继续提供服务。常见的实现高可用的开源软件有 heartbeat 和 keepalived。
准备:
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
环境:
Vm4—->server4 172.25.30.4
Vm4—->server5 172.25.30.5
Heartbeat 3.0.4
Httpd
1.安装
yum install -y /rhel6/heartbeat-*
scp * server5:
cd /etc/ha.d/
ls
harc rc.d README.config resource.d shellfuncs
rpm -q heartbeat -d
/usr/share/doc/heartbeat-3.0.4/AUTHORS
/usr/share/doc/heartbeat-3.0.4/COPYING
/usr/share/doc/heartbeat-3.0.4/COPYING.LGPL
/usr/share/doc/heartbeat-3.0.4/ChangeLog
/usr/share/doc/heartbeat-3.0.4/README
/usr/share/doc/heartbeat-3.0.4/apphbd.cf
/usr/share/doc/heartbeat-3.0.4/authkeys
/usr/share/doc/heartbeat-3.0.4/ha.cf
/usr/share/doc/heartbeat-3.0.4/haresources
/usr/share/man/man1/cl_status.1.gz
/usr/share/man/man1/hb_addnode.1.gz
/usr/share/man/man1/hb_delnode.1.gz
/usr/share/man/man1/hb_standby.1.gz
/usr/share/man/man1/hb_takeover.1.gz
/usr/share/man/man5/authkeys.5.gz
/usr/share/man/man5/ha.cf.5.gz
/usr/share/man/man8/apphbd.8.gz
/usr/share/man/man8/heartbeat.8.gz
yum install httpd
2.更改配置
cd /usr/share/doc/heartbeat-3.0.4/
ls
apphbd.cf AUTHORS COPYING ha.cf README
authkeys ChangeLog COPYING.LGPL haresources
cp ha.cf authkeys haresources /etc/ha.d/ ##拷贝文件
cd /etc/ha.d
ls
authkeys ha.cf harc haresources rc.d README.config resource.d shellfuncs
[root@server4 ha.d]# vim ha.cf
34 logfacility local0 日志文件
48 keepalive 2 心跳的时间间隔,默认单位时间秒
56 deadtime 30 超出该时间间隔未收到对方节点的心跳,则认为对方死亡
61 warntime 10 发出警告并记录在日志中
71 initdead 60 系统重启之后需要多长时间正常工作
76 udpport 724 广播通信使用的端口
91 bcast eth0 # Linux
157 auto_failback on 主节点和从节点,遇到故障时主节点把资源交给从节点
211 node server4 节点主机名
212 node server5
220 ping 172.25.30.250
253 respawn hacluster /usr/lib64/heartbeat/ipfail
该进程用于检测和处理网络故障,需要配合ping语句指定的ping node来检测 网络连接
259 apiauth ipfail gid=haclient uid=hacluster
[root@server4 ha.d]# vim authkeys
auth 1
1 crc
[root@server4 ha.d]# chmod 600 authkeys
[root@server4 ha.d]# vim haresources
server4 IPaddr::172.25.30.100/24/eth0 httpd ##节点的主机名 vip 执行脚本
[root@server4 ha.d]# ll /etc/init.d/ -d
drwxr-xr-x. 2 root root 4096 Jul 25 09:41 /etc/init.d/
[root@server4 ha.d]# scp ha.cf authkeys haresources server5:/etc/ha.d/
3.启动服务(server4、server5的httpd关闭)
[root@server4 ha.d]# /etc/init.d/heartbeat start
Starting High-Availability services: INFO: Resource is stopped
Done.
[root@server4 ha.d]# tail -f /var/log/messages
Jul 25 10:20:04 server4 heartbeat: [2067]: info: glib: UDP Broadcast heartbeat started on port 724 (724) interface eth0
Jul 25 10:20:04 server4 heartbeat: [2067]: info: glib: UDP Broadcast heartbeat closed on port 724 interface eth0 - Status: 1
Jul 25 10:20:04 server4 heartbeat: [2067]: info: glib: ping heartbeat started.
Jul 25 10:20:04 server4 heartbeat: [2067]: info: G_main_add_TriggerHandler: Added signal manual handler
Jul 25 10:20:04 server4 heartbeat: [2067]: info: G_main_add_TriggerHandler: Added signal manual handler
Jul 25 10:20:04 server4 heartbeat: [2067]: info: G_main_add_SignalHandler: Added signal handler for signal 17
Jul 25 10:20:04 server4 heartbeat: [2067]: info: Local status now set to:
[root@server4 ha.d]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 52:54:00:dd:bc:0e brd ff:ff:ff:ff:ff:ff
inet 172.25.30.4/24 brd 172.25.30.255 scope global eth0
inet 172.25.30.100/24 brd 172.25.30.255 scope global secondary eth0
inet6 fe80::5054:ff:fedd:bc0e/64 scope link
valid_lft forever preferred_lft forever
5.server5配置
[root@server5 ha.d]# ls
authkeys ha.cf haresources
[root@server5 ha.d]# cd ~
[root@server5 ~]# ls
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
[root@server5 ~]# yum install -y heartbeat-*
[root@server5 ha.d]# /etc/init.d/heartbeat start ###启动(server4 先启动正常)
Starting High-Availability services: INFO: Resource is stopped
Done.
6.测试:
当server4的hearbeat服务停止,仍可以继续访问server5;server4恢复,master为server4