搭建heartbeat高可用
1:准备阶段两台服务器一主一从
我这里采用了yum的方式进行安装,如想使用rpm安装,请自行下载rpm包
安装epel拓展源
国外的速度是在是太慢,我这里选择了阿里的拓展源,PS感谢马云。
# rm -rf /etc/yum.repos.d/*
# wget -P /etc/yum.repos.d/ http://mirrors.aliyun.com/repo/epel-6.repo 关闭防火墙
# iptables -F 2:安装heartbeat 以及依赖
# yum install -y heartbeat
# yum install -y libnet 3:拷贝样例文件并配置
heartbeat 给我们提供了一些样例配置,在/usr/share/doc/heartbeat
# cd /usr/share/doc/heartbeat-3.0.4/
# ls
apphbd.cfAUTHORS COPYING ha.cf README
authkeys ChangeLogCOPYING.LGPLharesources
# cp authkeys ha.cf haresources /etc/ha.d/ 编辑认证文件(authkeys)
auth 3
#1 crc
#2 sha1 HI!
3 md5 Hello! authkeys文件用于设定Heartbeat的认证方式,共有3种可用的认证方 式,即crc、md5和sha1。3种认证方式的安全性依次提高,但是占用的系统资源也依次增加。如果Heartbeat集群运行在安全的网络上,可以使 用crc方式;如果HA每个节点的硬件配置很高,建议使用sha1,这种认证方式安全级别最高;如果是处于网络安全和系统资源之间,可以使用md5认证方 式。这里我们使用md5认证方式,设置如下:
PS:确保该文件权限为600
-rw-------. 1 root root643 Aug7 14:10 authkeys
配置心跳的监控(haresources)
node1 192.168.1.122/24/eth0:0 nginx 指定 node1调用nginx服务,系统附加一个虚拟IP 192.168.1.122给eth0:0
这里如果node1宕机后,node2可以自动启动nginx服务,并新分配IP 192.168.1.122给node2的eth0:0
配置主配置文件(ha.conf)
logfile /var/log/ha_log/ha-log.log ## ha的日志文件记录位置。如没有该目录,则需
要手动添加
ucast eth0 192.168.1.107 ##探测对方ip
keepalive 2 ##设定心跳(监测)时间时间为2秒
warntime 10
deadtime 30
initdead 120
hopfudge 1
udpport 694 ##使用udp端口694 进行心跳监测
auto_failback on ##当主启动时备切换
node node1##节点
node node2##节点2
ping 192.168.1.1 ##通过ping 网关来监测心跳是否正常。
respawn hacluster /usr/lib64/heartbeat/ipfail ##自动拉起进程
apiauth ipfail gid=root uid=root
debugfile /Datas/logs/ha_log/ha-debug.log 拷贝配置文件到备机
# scp ha.cf haresources authkeys root@192.168.1.107:/etc/ha.d/
root@192.168.1.107's password:
ha.cf 100%682 0.7KB/s 00:00
haresources 100% 5888 5.8KB/s 00:00
authkeys 100%643 0.6KB/s 00:00
# 启动hearbeat /etc/init.d/heartbeat start
查看日志 tail -f /var/log/ha_log/ha-log.log
heartbeat 第一次启动非常慢,不要着急,耐心等耐,当vip启动完成,基本就没问题了
Aug 08 16:56:46 node1 heartbeat: : info: **************************
Aug 08 16:56:46 node1 heartbeat: : info: Configuration validated. Starting heartbeat 3.0.4
Aug 08 16:56:46 node1 heartbeat: : info: heartbeat: version 3.0.4
Aug 08 16:56:46 node1 heartbeat: : WARN: change_logfile_ownership: failed to chown dbgfile: No such file or directory
Aug 08 16:56:46 node1 heartbeat: : info: Heartbeat generation: 1470604473
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth0
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: bound send socket to device: eth0
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: set SO_REUSEPORT(w)
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: bound receive socket to device: eth0
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: set SO_REUSEPORT(w)
Aug 08 16:56:46 node1 heartbeat: : info: glib: ucast: started on port 694 interface eth0 to 192.168.1.107
Aug 08 16:56:46 node1 heartbeat: : info: glib: ping heartbeat started.
Aug 08 16:56:46 node1 heartbeat: : info: G_main_add_TriggerHandler: Added signal manual handler
Aug 08 16:56:46 node1 heartbeat: : info: G_main_add_TriggerHandler: Added signal manual handler
Aug 08 16:56:46 node1 heartbeat: : info: G_main_add_SignalHandler: Added signal handler for signal 17
Aug 08 16:56:46 node1 heartbeat: : info: Local status now set to: 'up'
Aug 08 16:56:47 node1 heartbeat: : info: Link 192.168.1.1:192.168.1.1 up.
Aug 08 16:56:47 node1 heartbeat: : info: Status update for node 192.168.1.1: status ping
Aug 08 16:58:46 node1 heartbeat: : WARN: node node2: is dead
Aug 08 16:58:46 node1 heartbeat: : info: Comm_now_up(): updating status to active
Aug 08 16:58:46 node1 heartbeat: : info: Local status now set to: 'active'
Aug 08 16:58:46 node1 heartbeat: : info: Starting child client "/usr/lib64/heartbeat/ipfail " (0,0)
Aug 08 16:58:46 node1 heartbeat: : WARN: No STONITH device configured.
Aug 08 16:58:46 node1 heartbeat: : WARN: Shared disks are not protected.
Aug 08 16:58:46 node1 heartbeat: : info: Resources being acquired from node2.
Aug 08 16:58:46 node1 heartbeat: : info: Starting "/usr/lib64/heartbeat/ipfail " as uid 0gid 0 (pid 1570)
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.1.122):2016/08/08_16:58:46 INFO:Resource is stopped
Aug 08 16:58:46 node1 heartbeat: : info: Local Resource acquisition completed.
Aug 08 16:58:57 node1 heartbeat: : info: Local Resource acquisition completed. (none)
Aug 08 16:58:57 node1 heartbeat: : info: local resource transition completed.
Aug 08 17:05:27 node1 heartbeat: : WARN: Shutdown delayed until current resource activity finishes.
Aug 08 17:11:19 HaMaster heartbeat: : info: Pacemaker support: false
Aug 08 17:11:19 HaMaster heartbeat: : ERROR: Current node not in configuration!
Aug 08 17:11:19 HaMaster heartbeat: : info: By default, cluster nodes are named by `uname -n` and must be declared with a 'node' directive in the ha.cf file.
Aug 08 17:11:19 HaMaster heartbeat: : info: See also: http://linux-ha.org/wiki/Ha.cf#node_directive
Aug 08 17:11:19 HaMaster heartbeat: : WARN: Logging daemon is disabled --enabling logging daemon is recommended
Aug 08 17:11:19 HaMaster heartbeat: : ERROR: Configuration error, heartbeat not started.
Aug 08 21:16:49 HaMaster heartbeat: : info: Pacemaker support: false
Aug 08 21:16:49 HaMaster heartbeat: : ERROR: Current node not in configuration!
Aug 08 21:16:49 HaMaster heartbeat: : info: By default, cluster nodes are named by `uname -n` and must be declared with a 'node' directive in the ha.cf file.
Aug 08 21:16:49 HaMaster heartbeat: : info: See also: http://linux-ha.org/wiki/Ha.cf#node_directive
Aug 08 21:16:49 HaMaster heartbeat: : WARN: Logging daemon is disabled --enabling logging daemon is recommended
Aug 08 21:16:49 HaMaster heartbeat: : ERROR: Configuration error, heartbeat not started.
Aug 08 21:18:34 node1 heartbeat: : info: Pacemaker support: false
Aug 08 21:18:34 node1 heartbeat: : WARN: Logging daemon is disabled --enabling logging daemon is recommended
Aug 08 21:18:34 node1 heartbeat: : info: **************************
Aug 08 21:18:34 node1 heartbeat: : info: Configuration validated. Starting heartbeat 3.0.4
Aug 08 21:18:34 node1 heartbeat: : info: heartbeat: version 3.0.4
Aug 08 21:18:34 node1 heartbeat: : info: Heartbeat generation: 1470604474
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth0
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: bound send socket to device: eth0
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: set SO_REUSEPORT(w)
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: bound receive socket to device: eth0
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: set SO_REUSEPORT(w)
Aug 08 21:18:34 node1 heartbeat: : info: glib: ucast: started on port 694 interface eth0 to 192.168.1.110
Aug 08 21:18:34 node1 heartbeat: : info: glib: ping heartbeat started.
Aug 08 21:18:34 node1 heartbeat: : info: G_main_add_TriggerHandler: Added signal manual handler
Aug 08 21:18:34 node1 heartbeat: : info: G_main_add_TriggerHandler: Added signal manual handler
Aug 08 21:18:34 node1 heartbeat: : info: G_main_add_SignalHandler: Added signal handler for signal 17
Aug 08 21:18:34 node1 heartbeat: : info: Local status now set to: 'up'
Aug 08 21:18:35 node1 heartbeat: : info: Link 192.168.1.1:192.168.1.1 up.
Aug 08 21:18:35 node1 heartbeat: : info: Status update for node 192.168.1.1: status ping
Aug 08 21:20:35 node1 heartbeat: : WARN: node node2: is dead
Aug 08 21:20:35 node1 heartbeat: : info: Comm_now_up(): updating status to active
Aug 08 21:20:35 node1 heartbeat: : info: Local status now set to: 'active'
Aug 08 21:20:35 node1 heartbeat: : info: Starting child client "/usr/lib64/heartbeat/ipfail " (0,0)
Aug 08 21:20:35 node1 heartbeat: : WARN: No STONITH device configured.
Aug 08 21:20:35 node1 heartbeat: : WARN: Shared disks are not protected.
Aug 08 21:20:35 node1 heartbeat: : info: Resources being acquired from node2.
Aug 08 21:20:35 node1 heartbeat: : info: Starting "/usr/lib64/heartbeat/ipfail " as uid 0gid 0 (pid 1521)
harc(default): 2016/08/08_21:20:35 info: Running /etc/ha.d//rc.d/status status
mach_down(default): 2016/08/08_21:20:35 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down(default): 2016/08/08_21:20:35 info: mach_down takeover complete for node node2.
Aug 08 21:20:35 node1 heartbeat: : info: mach_down takeover complete.
Aug 08 21:20:35 node1 heartbeat: : info: Initial resource acquisition complete (mach_down)
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.1.122):2016/08/08_21:20:35 INFO:Resource is stopped
Aug 08 21:20:35 node1 heartbeat: : info: Local Resource acquisition completed.
harc(default): 2016/08/08_21:20:35 info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp
ip-request-resp(default): 2016/08/08_21:20:35 received ip-request-resp 192.168.1.122/24/eth0:0 OK yes
ResourceManager(default): 2016/08/08_21:20:35 info: Acquiring resource group: node1 192.168.1.122/24/eth0:0 nginx
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.1.122):2016/08/08_21:20:35 INFO:Resource is stopped
ResourceManager(default): 2016/08/08_21:20:35 info: Running /etc/ha.d/resource.d/IPaddr 192.168.1.122/24/eth0:0 start
IPaddr(IPaddr_192.168.1.122): 2016/08/08_21:20:35 INFO: Adding inet address 192.168.1.122/24 with broadcast address 192.168.1.255 to device eth0 (with label eth0:0)
IPaddr(IPaddr_192.168.1.122): 2016/08/08_21:20:35 INFO: Bringing device eth0 up
IPaddr(IPaddr_192.168.1.122): 2016/08/08_21:20:35 INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.1.122 eth0 192.168.1.122 auto not_used not_used
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.1.122):2016/08/08_21:20:35 INFO:Success
ResourceManager(default): 2016/08/08_21:20:36 info: Running /etc/init.d/nginxstart
Aug 08 21:20:45 node1 heartbeat: : info: Local Resource acquisition completed. (none)
Aug 08 21:20:45 node1 heartbeat: : info: local resource transition completed.
页:
[1]