共计 28746 个字符,预计需要花费 72 分钟才能阅读完成。
系统:CentOS 6.6 x86_64(两台虚拟机)
安全:SElinux disabled
网络:业务网络 + 心跳网络
Heartbeat 版本:v3.0.6
Cluster Gule 版本:v1.0.12
Resource Agents 版本:v3.9.6
软件包安装方式:源码安装
Heartbeat 3.0 以后是由 gule、heartbeat、agents 三部分组成。因此,我们需要分别安装。
事先必须安装好必要的基础工具及编译工具:
gcc 系列
flex 和 bison 编译解析
net-snmp 开发头文件
OpenIPMI 开发头
Python 解释器
添加运行 heartbeat 的用户和组(在主备服务器上都需要有该操作)
#groupadd -r haclient
#useradd -r -g haclient -M -s /sbin/nologin hacluster
下载安装 Cluster Gule
#wget -O Glue_1.0.12.tar.bz2 http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
#tar xf Glue_1.0.12.tar.bz2
#cd Reusable-Cluster-Components-glue–0a7add1d9996/
#bash autogen.sh
#./configure LIBS=’/lib64/libuuid.so.1′
…………………..
cluster-glue configuration:
Version = 1.0.12 (Build: 0a7add1d9996b6d869d441da6c82fb7b8abcef4f)
Features =
Prefix = /usr
Executables = /usr/sbin
Man pages = /usr/share/man
Libraries = /usr/lib64
Header files = /usr/include
Arch-independent files = /usr/share
Documentation = /usr/share/doc/cluster-glue
State information = /usr/var
System configuration = /usr/etc
Use system LTDL = yes
HA group name = haclient
HA user name = hacluster
CFLAGS = -g -O2 -ggdb -fgnu89-inline -fstack-protector-all -Wall -Waggregate-return -Wbad-function-cast -Wcast-qual -Wcast-align -Wdeclaration-after-statement -Wendif-labels -Wfloat-equal -Wformat=2 -Wformat-security -Wformat-nonliteral -Winline -Wmissing-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wnested-externs -Wno-long-long -Wno-strict-aliasing -Wpointer-arith -Wstrict-prototypes -Wwrite-strings -ansi -D_GNU_SOURCE -DANSI_ONLY -Werror
Libraries = -lbz2 -lz -lxml2 -lc -lrt -ldl /lib64/libuuid.so.1 -lglib-2.0 -lltdl
Stack Libraries =
#make -j 2 && make install
下载安装 Heartbeat
#wget -O Heartbeat_3.0.6.tar.bz2 http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
#tar xf Heartbeat_3.0.6.tar.bz2
#cd Heartbeat-3-0-958e11be8686/
#./bootstrap
#./configure
…….
configure: WARNING: stdocdir directory () does not exist!
configure: WARNING: value/default “–localstatedir=/usr/local/var” is poor.
configure: WARNING: “/var/something” is strongly recommended.
configure: WARNING: We also recommend using “ConfigureMe”. // 使用 configureMe
configure: WARNING: Sleeping for 10 seconds.
……
#./ConfigureMe configure LIBS=/lib64/libuuid.so.1
………..
heartbeat configuration:
Version = “3.0.6”
Executables = “/usr/sbin”
Man pages = “/usr/share/man”
Libraries = “/usr/lib64”
Header files = “/usr/include”
Arch-independent files = “/usr/share”
Documentation files = “/usr/share/doc/heartbeat”
State information = “/var”
System configuration = “/etc”
Init (rc) scripts = “/etc/rc.d/init.d”
Init (rc) defaults = “/etc/sysconfig”
Use system LTDL = “yes”
HA group name = “haclient”
HA group id = “499”
HA user name = “hacluster”
HA user user id = “498”
Build dopd plugin = “yes”
Enable times kludge = “yes”
CC_WARNINGS = ” -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror “
Mangled CFLAGS = “-g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror -ggdb3 -funsigned-char”
Libraries = “-lbz2 -lz -lc -lrt -ldl -lltdl”
RPATH enabled = “no”
Distro-style RPMs = “no”
Note: If you use the ‘make install’ method for installation you
also need to adjust ‘/etc/passwd’ and ‘/etc/group’ manually.
#make -j 2 && make install
////////////make 的时候报错
/usr/bin/xsltproc \
–xinclude \
http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl hb_report.xml
error : Operation in progress
warning: failed to load external entity “http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl”
cannot parse http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
gmake[2]: *** [hb_report.8] Error 4
gmake[2]: Leaving directory `/heartbeat/Reusable-Cluster-Components-glue–5e06b2ddd24b/doc’
yum install docbook-style-xsl -y
#make -j 2 && make install
下载安装 Agents
#wget -O Resource_Agents_3.9.6.tar.gz
#tar xf Resource_Agents_3.9.6.tar.gz
#cd resource-agents-3.9.6/
#./autogen.sh
autoreconf: Entering directory `.’
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf
autoreconf: running: /usr/bin/autoheader
autoreconf: running: automake –add-missing –copy –no-force
configure.ac:102: installing `./compile’
configure.ac:33: installing `./config.guess’
configure.ac:33: installing `./config.sub’
configure.ac:83: installing `./install-sh’
configure.ac:83: installing `./missing’
heartbeat/Makefile.am: installing `./depcomp’
autoreconf: Leaving directory `.’
Now run ./configure and make
#./configure LIBS=’/lib64/libuuid.so.1′
#make -j 2 && make install
至此,安装完毕
——————————————————————————–
配置 Heartbeat
#tree /etc/ha.d/
/etc/ha.d/
├── harc
├── rc.d
│ ├── ask_resources
│ ├── hb_takeover
│ ├── ip-request
│ ├── ip-request-resp
│ └── status
├── README.config
├── resource.d
│ ├── apache
│ ├── AudibleAlarm
│ ├── db2
│ ├── Delay
│ ├── Filesystem
│ ├── hto-mapfuncs
│ ├── ICP
│ ├── ids
│ ├── IPaddr
│ ├── IPaddr2
│ ├── IPsrcaddr
│ ├── IPv6addr
│ ├── ldirectord -> /usr/sbin/ldirectord
│ ├── LinuxSCSI
│ ├── LVM
│ ├── MailTo
│ ├── OCF
│ ├── portblock
│ ├── Raid1
│ ├── SendArp
│ ├── ServeRAID
│ ├── WAS
│ ├── WinPopup
│ └── Xinetd
└── shellfuncs
2 directories, 32 files
README.config 文档介绍说明 最主要的三个文件 ha.cf、haresources、authkeys。
注意:authkeys 的权限为 600
#cd /usr/share/doc/heartbeat/
#cp ha.cf haresources authkeys /etc/ha.d/
ha.cf 主配置文件
logfile /var/log/ha-log
logfacility local0 #日志等级
keepalive 5 #心跳频率,默认为 2 秒
deadtime 30 #死亡超时时间 默认 30 秒
warntime 10 #告警时间
initdead 150 #网络初始化最长时间,默认 120 秒
udpport 694 #心跳检测 udp 端口
ucast eth1 10.1.1.1 #我这里选择单播,检测网卡 eth1 ip 地址为对端心跳端口的 IP
auto_failback on #如果主节点重新恢复,主节点将抢占资源恢复服务,如果为 off,则只当备用节点当掉后,主节点恢复
watchdog /dev/watchdog #监控设备
node heartbeat_73 ### 节点和主机名(节点主机名必须和 uname - n 的结果一样)
node heartbeat_72 ### 节点和主机名(节点主机名必须和 uname - n 的结果一样)
haresources 主备节点配置文件
[root@heartbeat_73 /etc/ha.d]#grep -v “^#” haresources
master IPaddr::211.162.174.74/24/eth0:1/ nginx #后端要跟服务名
haresources 文件的用法:
资源文件(/etc/ha.d/haresources)
Haresources 文件用于指定双机系统的主节点、集群 IP、子网掩码、广播地址以及启动的服务等集群资源,文件每一行可以包含一个或多个资源脚本名,资源之间使用空格隔开,参数之间使用两个冒号隔开,在两个 HA 节点上该文件必须完全一致,此文件的一般格式为:
node-name network <resource-group>
node-name 表示主节点的主机名,必须和 ha.cf 文件中指定的节点名一致。network 用于设定集群的 IP 地址、子网掩码和网络设备标识 等。需要注意的是,这里指定的 IP 地址就是集群对外服务的 IP 地址,resource-group 用来指定需要 Heartbeat 托管的服务,也就是这些 服务可以由 Heartbeat 来启动和关闭。如果要托管这些服务,就必须将服务写成可以通过 start/stop 来启动和关闭的脚步,然后放到 /etc /init.d/ 或者 /etc/ha.d/resource.d/ 目录下,Heartbeat 会根据脚本的名称自动去 /etc/init.d 或者 /etc /ha.d/resource.d/ 目录下找到相应脚步进行启动或关闭操作。
下面对配置方法进行具体说明:
node1 IPaddr::192.168.60.200/24/eth0/ Filesystem:: /dev/sdb5::/webdata::ext3 httpd tomcat
其中,node1 是 HA 集群的主节点,IPaddr 为 heartbeat 自带的一个执行脚 步,Heartbeat 首先将执行 /etc/ha.d/resource.d/IPaddr 192.168.60.200/24 start 的操作,也就是虚拟出一个子网掩码为 255.255.255.0,IP 为 192.168.60.200 的地址。此 IP 为 Heartbeat 对外 提供服务的网络地址,同时指定此 IP 使用的网络接口为 eth0。接着,Heartbeat 将执行共享磁盘分区的挂载操 作,”Filesystem::/dev/sdb5::/webdata::ext3″ 相当于在命令行下执行 mount 操作,即 ”mount -t ext3 /dev/sdb5 /webdata”,最后依次启动 httpd 和 Tomcat 服务。
注意:主节点和备份节点中资源文件 haresources 要完全一样。
authkeys 心跳密钥验证文件
[root@heartbeat_73 /etc/ha.d]#grep -v “^#” authkeys
auth 1
1 sha1 HI!
注意:确保 authkeys 文件的权限为 600
好了,配置文件到现在基本配置完毕。
(以上配置在主 备服务器上都需要配置)
——————————————————————————–
启动 heartbeat
在这之前有四个需要设置的地方:
1,服务器的 IP 需要配置,业务网卡 和 心跳网卡。并规划好 VIP 地址。
2,修改主备节点的 hosts 文件的名字解析(并检测网络是否可以通)
3,由于我们在安装 heartbeat 的时候没有使用 –prefix 选项指定安装目录,所以需要执行以下操作
#cd /etc/ha.d/
#mkdir /usr/etc/ha.d/
#cp -R ./* /usr/etc/ha.d/
(主备服务器上都需要操作)
4,如果心跳网络是专用网卡,那么请在 iptables 中放开限制。
————————————– 分割线 ————————————–
基于 Heartbeat V1 实现 Web 服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm
Heartbeat 实现 Web 服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm
Heartbeat+LVS+Ldirectord 高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm
DRBD+Heartbeat+NFS 高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm
Heartbeat 基于 CRM 使用 NFS 对 MySQL 高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm
Heartbeat 高可用 httpd 基于 Resources 简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm
————————————– 分割线 ————————————–
为了测试 heartbeat,我们现在在主备服务器上分别安装 nginx(或者 httpd),并吧默认的 index.html 做个小小的改动
这是备用服务器上的 主页面。
这是主服务器上的 主页面。
做好上述操作后,接下来捣鼓 heartbeat 启动脚本,默认按上述方法安装好后,会在 /etc/init.d/ 目录下创建 heartbeat 启动脚本,但是并没在 chkconfig 启动列表中出现。
chkconfig –add heartbeat
chkconfig –list // 查看是否已经设置为开机启动。
service heartbeat stop // 确保未启动状态
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2015-04/116153p2.htm
备服务器:
#service heartbeat stop
Stopping High-Availability services: [OK]
ifconfig 查看网络连接信息
主服务器:
ifconfig // 确认网络连接信息
#service heartbeat start
Starting High-Availability services: INFO: Resource is stopped
[OK]
ifconfig 查看网络连接信息
查看 /var/log/ha-log 日志信息
Apr 09 13:22:02 heartbeat_72 heartbeat: [6811]: WARN: Logging daemon is disabled –enabling logging daemon is recommended
Apr 09 13:22:02 heartbeat_72 heartbeat: [6811]: info: **************************
Apr 09 13:22:02 heartbeat_72 heartbeat: [6811]: info: Configuration validated. Starting heartbeat 3.0.6
Apr 09 13:22:02 heartbeat_72 heartbeat: [6812]: info: heartbeat: version 3.0.6
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: Heartbeat generation: 1428508344
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: write socket priority set to IPTOS_LOWDELAY on eth1
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: bound send socket to device: eth1
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: set SO_REUSEPORT(w)
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: set SO_REUSEADDR
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: bound receive socket to device: eth1
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: set SO_REUSEPORT
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: glib: ucast: started on port 694 interface eth1 to 10.1.1.2
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: notice: Using watchdog device: /dev/watchdog
Apr 09 13:22:03 heartbeat_72 heartbeat: [6812]: info: Local status now set to: ‘up’
当前备用服务器并没有启动 heartbeat 服务。
ifconfig 查看主服务器 并未配置 VIP
主节点 heartbeat 启动一段时间后,日志限制 备服务器已经被认为死亡。
Apr 09 13:46:48 heartbeat_72 heartbeat: [8379]: WARN: node heartbeat_73: is dead
Apr 09 13:46:48 heartbeat_72 heartbeat: [8379]: info: Dead node heartbeat_73 gave up resources.
Apr 09 13:46:48 heartbeat_72 heartbeat: [8379]: info: Link heartbeat_73:eth1 dead.
现在查看 ifocnfig 已经配置了 VIP
网页截图:
备用节点:
接上网线,开启 heartbeat 服务。
查看日志:
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: info: Heartbeat generation: 1428508003
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 – Status: 1
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: notice: Using watchdog device: /dev/watchdog
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: info: Local status now set to: ‘up’
Apr 09 13:49:03 heartbeat_73 heartbeat: [2089]: info: Link heartbeat_73:eth1 up.
Apr 09 13:49:05 heartbeat_73 heartbeat: [2089]: info: Link heartbeat_72:eth1 up.
Apr 09 13:49:05 heartbeat_73 heartbeat: [2089]: info: Status update for node heartbeat_72: status active
harc(default)[2096]: 2015/04/09_13:49:05 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 13:49:05 heartbeat_73 heartbeat: [2089]: info: Comm_now_up(): updating status to active
Apr 09 13:49:05 heartbeat_73 heartbeat: [2089]: info: Local status now set to: ‘active’
Apr 09 13:49:06 heartbeat_73 heartbeat: [2089]: info: remote resource transition completed.
Apr 09 13:49:06 heartbeat_73 heartbeat: [2089]: info: remote resource transition completed.
Apr 09 13:49:06 heartbeat_73 heartbeat: [2089]: info: Local Resource acquisition completed. (none)
Apr 09 13:49:06 heartbeat_73 heartbeat: [2089]: info: heartbeat_72 wants to go standby [foreign]
Apr 09 13:49:07 heartbeat_73 heartbeat: [2089]: info: standby: acquire [foreign] resources from heartbeat_72
Apr 09 13:49:07 heartbeat_73 heartbeat: [2116]: info: acquire local HA resources (standby).
Apr 09 13:49:07 heartbeat_73 heartbeat: [2116]: info: local HA resource acquisition completed (standby).
Apr 09 13:49:07 heartbeat_73 heartbeat: [2089]: info: Standby resource acquisition done [foreign].
Apr 09 13:49:07 heartbeat_73 heartbeat: [2089]: info: Initial resource acquisition complete (auto_failback)
Apr 09 13:49:07 heartbeat_73 heartbeat: [2089]: info: remote resource transition completed.
#ifconfig 查看网络信息,并未配置 VIP
主节点的日志:
Apr 09 13:49:04 heartbeat_72 heartbeat: [8379]: info: Heartbeat restart on node heartbeat_73
Apr 09 13:49:04 heartbeat_72 heartbeat: [8379]: info: Link heartbeat_73:eth1 up.
Apr 09 13:49:04 heartbeat_72 heartbeat: [8379]: info: Status update for node heartbeat_73: status init
Apr 09 13:49:04 heartbeat_72 heartbeat: [8379]: info: Status update for node heartbeat_73: status up
harc(default)[8998]: 2015/04/09_13:49:04 info: Running /usr/etc/ha.d//rc.d/status status
harc(default)[9015]: 2015/04/09_13:49:04 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 13:49:06 heartbeat_72 heartbeat: [8379]: info: Status update for node heartbeat_73: status active
Apr 09 13:49:06 heartbeat_72 heartbeat: [8379]: WARN: T_STARTING received during takeover.
harc(default)[9032]: 2015/04/09_13:49:06 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 13:49:06 heartbeat_72 heartbeat: [8379]: info: remote resource transition completed.
Apr 09 13:49:06 heartbeat_72 heartbeat: [8379]: info: heartbeat_72 wants to go standby [foreign]
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: info: standby: heartbeat_73 can take our foreign resources
Apr 09 13:49:07 heartbeat_72 heartbeat: [9049]: info: give up foreign HA resources (standby).
Apr 09 13:49:07 heartbeat_72 heartbeat: [9049]: info: foreign HA resource release completed (standby).
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: info: Local standby process completed [foreign].
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: WARN: 1 lost packet(s) for [heartbeat_73] [9:11]
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: info: remote resource transition completed.
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: info: No pkts missing from heartbeat_73!
Apr 09 13:49:07 heartbeat_72 heartbeat: [8379]: info: Other node completed standby takeover of foreign resources.
主节点:
#service heartbeat stop
查看日志:
Apr 09 14:41:06 heartbeat_72 heartbeat: [9495]: info: Heartbeat shutdown in progress. (9495)
Apr 09 14:41:06 heartbeat_72 heartbeat: [9631]: info: Giving up all HA resources.
ResourceManager(default)[9644]: 2015/04/09_14:41:06 info: Releasing resource group: heartbeat_72 IPaddr::211.162.174.74/24/eth0:1/ nginx
ResourceManager(default)[9644]: 2015/04/09_14:41:06 info: Running /etc/rc.d/init.d/nginx stop
ResourceManager(default)[9644]: 2015/04/09_14:41:06 info: Running /etc/ha.d/resource.d/IPaddr 211.162.174.74/24/eth0:1/ stop
IPaddr(IPaddr_211.162.174.74)[9732]: 2015/04/09_14:41:06 INFO: ifconfig eth0:1 down
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_211.162.174.74)[9706]: 2015/04/09_14:41:06 INFO: Success
Apr 09 14:41:06 heartbeat_72 heartbeat: [9631]: info: All HA resources relinquished.
Apr 09 14:41:06 heartbeat_72 heartbeat: [9495]: WARN: 1 lost packet(s) for [heartbeat_73] [51:53]
Apr 09 14:41:06 heartbeat_72 heartbeat: [9495]: info: No pkts missing from heartbeat_73!
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: killing HBFIFO process 9498 with signal 15
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: killing HBWRITE process 9499 with signal 15
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: killing HBREAD process 9500 with signal 15
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: Core process 9498 exited. 3 remaining
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: Core process 9499 exited. 2 remaining
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: Core process 9500 exited. 1 remaining
Apr 09 14:41:08 heartbeat_72 heartbeat: [9495]: info: heartbeat_72 Heartbeat shutdown complete.
备节点:
Apr 09 14:41:38 heartbeat_73 heartbeat: [2828]: WARN: node heartbeat_72: is dead
Apr 09 14:41:38 heartbeat_73 heartbeat: [2828]: info: Dead node heartbeat_72 gave up resources.
Apr 09 14:41:38 heartbeat_73 heartbeat: [2828]: info: Link heartbeat_72:eth1 dead.
已经正确记录主节点宕机,并且 VIP 已经漂移到备用节点。
网页截图:
主节点开启服务:
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Heartbeat restart on node heartbeat_72
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Link heartbeat_72:eth1 up.
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status init
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status up
harc(default)[3353]: 2015/04/09_14:43:48 info: Running /usr/etc/ha.d//rc.d/status status
harc(default)[3370]: 2015/04/09_14:43:48 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status active
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: WARN: T_STARTING received during takeover.
harc(default)[3387]: 2015/04/09_14:43:52 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: remote resource transition completed.
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: heartbeat_73 wants to go standby [foreign]
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: standby: heartbeat_72 can take our foreign resources
Apr 09 14:43:52 heartbeat_73 heartbeat: [3404]: info: give up foreign HA resources (standby).
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Releasing resource group: heartbeat_72 IPaddr::211.162.174.74/24/eth0:1/ nginx
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Running /etc/rc.d/init.d/nginx stop
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Running /etc/ha.d/resource.d/IPaddr 211.162.174.74/24/eth0:1/ stop
IPaddr(IPaddr_211.162.174.74)[3505]: 2015/04/09_14:43:52 INFO: ifconfig eth0:0 down
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_211.162.174.74)[3479]: 2015/04/09_14:43:52 INFO: Success
Apr 09 14:43:52 heartbeat_73 heartbeat: [3404]: info: foreign HA resource release completed (standby).
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: Local standby process completed [foreign].
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: WARN: 1 lost packet(s) for [heartbeat_72] [11:13]
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: remote resource transition completed.
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: No pkts missing from heartbeat_72!
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: Other node completed standby takeover of foreign resources.
备用节点日志:
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Heartbeat restart on node heartbeat_72
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Link heartbeat_72:eth1 up.
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status init
Apr 09 14:43:48 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status up
harc(default)[3353]: 2015/04/09_14:43:48 info: Running /usr/etc/ha.d//rc.d/status status
harc(default)[3370]: 2015/04/09_14:43:48 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: Status update for node heartbeat_72: status active
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: WARN: T_STARTING received during takeover.
harc(default)[3387]: 2015/04/09_14:43:52 info: Running /usr/etc/ha.d//rc.d/status status
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: remote resource transition completed.
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: heartbeat_73 wants to go standby [foreign]
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: standby: heartbeat_72 can take our foreign resources
Apr 09 14:43:52 heartbeat_73 heartbeat: [3404]: info: give up foreign HA resources (standby).
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Releasing resource group: heartbeat_72 IPaddr::211.162.174.74/24/eth0:1/ nginx
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Running /etc/rc.d/init.d/nginx stop
ResourceManager(default)[3417]: 2015/04/09_14:43:52 info: Running /etc/ha.d/resource.d/IPaddr 211.162.174.74/24/eth0:1/ stop
IPaddr(IPaddr_211.162.174.74)[3505]: 2015/04/09_14:43:52 INFO: ifconfig eth0:0 down
/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_211.162.174.74)[3479]: 2015/04/09_14:43:52 INFO: Success
Apr 09 14:43:52 heartbeat_73 heartbeat: [3404]: info: foreign HA resource release completed (standby).
Apr 09 14:43:52 heartbeat_73 heartbeat: [2828]: info: Local standby process completed [foreign].
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: WARN: 1 lost packet(s) for [heartbeat_72] [11:13]
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: remote resource transition completed.
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: No pkts missing from heartbeat_72!
Apr 09 14:43:53 heartbeat_73 heartbeat: [2828]: info: Other node completed standby takeover of foreign resources.
好了,主节点恢复后,VIP 已经默认转移到主节点上了。
OK 实验完成。
更多 CentOS 相关信息见 CentOS 专题页面 http://www.linuxidc.com/topicnews.aspx?tid=14
本文永久更新链接地址 :http://www.linuxidc.com/Linux/2015-04/116153.htm
系统:CentOS 6.6 x86_64(两台虚拟机)
安全:SElinux disabled
网络:业务网络 + 心跳网络
Heartbeat 版本:v3.0.6
Cluster Gule 版本:v1.0.12
Resource Agents 版本:v3.9.6
软件包安装方式:源码安装
Heartbeat 3.0 以后是由 gule、heartbeat、agents 三部分组成。因此,我们需要分别安装。
事先必须安装好必要的基础工具及编译工具:
gcc 系列
flex 和 bison 编译解析
net-snmp 开发头文件
OpenIPMI 开发头
Python 解释器
添加运行 heartbeat 的用户和组(在主备服务器上都需要有该操作)
#groupadd -r haclient
#useradd -r -g haclient -M -s /sbin/nologin hacluster
下载安装 Cluster Gule
#wget -O Glue_1.0.12.tar.bz2 http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
#tar xf Glue_1.0.12.tar.bz2
#cd Reusable-Cluster-Components-glue–0a7add1d9996/
#bash autogen.sh
#./configure LIBS=’/lib64/libuuid.so.1′
…………………..
cluster-glue configuration:
Version = 1.0.12 (Build: 0a7add1d9996b6d869d441da6c82fb7b8abcef4f)
Features =
Prefix = /usr
Executables = /usr/sbin
Man pages = /usr/share/man
Libraries = /usr/lib64
Header files = /usr/include
Arch-independent files = /usr/share
Documentation = /usr/share/doc/cluster-glue
State information = /usr/var
System configuration = /usr/etc
Use system LTDL = yes
HA group name = haclient
HA user name = hacluster
CFLAGS = -g -O2 -ggdb -fgnu89-inline -fstack-protector-all -Wall -Waggregate-return -Wbad-function-cast -Wcast-qual -Wcast-align -Wdeclaration-after-statement -Wendif-labels -Wfloat-equal -Wformat=2 -Wformat-security -Wformat-nonliteral -Winline -Wmissing-prototypes -Wmissing-declarations -Wmissing-format-attribute -Wnested-externs -Wno-long-long -Wno-strict-aliasing -Wpointer-arith -Wstrict-prototypes -Wwrite-strings -ansi -D_GNU_SOURCE -DANSI_ONLY -Werror
Libraries = -lbz2 -lz -lxml2 -lc -lrt -ldl /lib64/libuuid.so.1 -lglib-2.0 -lltdl
Stack Libraries =
#make -j 2 && make install
下载安装 Heartbeat
#wget -O Heartbeat_3.0.6.tar.bz2 http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
#tar xf Heartbeat_3.0.6.tar.bz2
#cd Heartbeat-3-0-958e11be8686/
#./bootstrap
#./configure
…….
configure: WARNING: stdocdir directory () does not exist!
configure: WARNING: value/default “–localstatedir=/usr/local/var” is poor.
configure: WARNING: “/var/something” is strongly recommended.
configure: WARNING: We also recommend using “ConfigureMe”. // 使用 configureMe
configure: WARNING: Sleeping for 10 seconds.
……
#./ConfigureMe configure LIBS=/lib64/libuuid.so.1
………..
heartbeat configuration:
Version = “3.0.6”
Executables = “/usr/sbin”
Man pages = “/usr/share/man”
Libraries = “/usr/lib64”
Header files = “/usr/include”
Arch-independent files = “/usr/share”
Documentation files = “/usr/share/doc/heartbeat”
State information = “/var”
System configuration = “/etc”
Init (rc) scripts = “/etc/rc.d/init.d”
Init (rc) defaults = “/etc/sysconfig”
Use system LTDL = “yes”
HA group name = “haclient”
HA group id = “499”
HA user name = “hacluster”
HA user user id = “498”
Build dopd plugin = “yes”
Enable times kludge = “yes”
CC_WARNINGS = ” -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror “
Mangled CFLAGS = “-g -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -Wstrict-prototypes -Wdeclaration-after-statement -Wpointer-arith -Wwrite-strings -Wcast-qual -Wcast-align -Wbad-function-cast -Winline -Wmissing-format-attribute -Wformat=2 -Wformat-security -Wformat-nonliteral -Wno-long-long -Wno-strict-aliasing -Werror -ggdb3 -funsigned-char”
Libraries = “-lbz2 -lz -lc -lrt -ldl -lltdl”
RPATH enabled = “no”
Distro-style RPMs = “no”
Note: If you use the ‘make install’ method for installation you
also need to adjust ‘/etc/passwd’ and ‘/etc/group’ manually.
#make -j 2 && make install
////////////make 的时候报错
/usr/bin/xsltproc \
–xinclude \
http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl hb_report.xml
error : Operation in progress
warning: failed to load external entity “http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl”
cannot parse http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl
gmake[2]: *** [hb_report.8] Error 4
gmake[2]: Leaving directory `/heartbeat/Reusable-Cluster-Components-glue–5e06b2ddd24b/doc’
yum install docbook-style-xsl -y
#make -j 2 && make install
下载安装 Agents
#wget -O Resource_Agents_3.9.6.tar.gz
#tar xf Resource_Agents_3.9.6.tar.gz
#cd resource-agents-3.9.6/
#./autogen.sh
autoreconf: Entering directory `.’
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /usr/bin/autoconf
autoreconf: running: /usr/bin/autoheader
autoreconf: running: automake –add-missing –copy –no-force
configure.ac:102: installing `./compile’
configure.ac:33: installing `./config.guess’
configure.ac:33: installing `./config.sub’
configure.ac:83: installing `./install-sh’
configure.ac:83: installing `./missing’
heartbeat/Makefile.am: installing `./depcomp’
autoreconf: Leaving directory `.’
Now run ./configure and make
#./configure LIBS=’/lib64/libuuid.so.1′
#make -j 2 && make install
至此,安装完毕
——————————————————————————–
配置 Heartbeat
#tree /etc/ha.d/
/etc/ha.d/
├── harc
├── rc.d
│ ├── ask_resources
│ ├── hb_takeover
│ ├── ip-request
│ ├── ip-request-resp
│ └── status
├── README.config
├── resource.d
│ ├── apache
│ ├── AudibleAlarm
│ ├── db2
│ ├── Delay
│ ├── Filesystem
│ ├── hto-mapfuncs
│ ├── ICP
│ ├── ids
│ ├── IPaddr
│ ├── IPaddr2
│ ├── IPsrcaddr
│ ├── IPv6addr
│ ├── ldirectord -> /usr/sbin/ldirectord
│ ├── LinuxSCSI
│ ├── LVM
│ ├── MailTo
│ ├── OCF
│ ├── portblock
│ ├── Raid1
│ ├── SendArp
│ ├── ServeRAID
│ ├── WAS
│ ├── WinPopup
│ └── Xinetd
└── shellfuncs
2 directories, 32 files
README.config 文档介绍说明 最主要的三个文件 ha.cf、haresources、authkeys。
注意:authkeys 的权限为 600
#cd /usr/share/doc/heartbeat/
#cp ha.cf haresources authkeys /etc/ha.d/
ha.cf 主配置文件
logfile /var/log/ha-log
logfacility local0 #日志等级
keepalive 5 #心跳频率,默认为 2 秒
deadtime 30 #死亡超时时间 默认 30 秒
warntime 10 #告警时间
initdead 150 #网络初始化最长时间,默认 120 秒
udpport 694 #心跳检测 udp 端口
ucast eth1 10.1.1.1 #我这里选择单播,检测网卡 eth1 ip 地址为对端心跳端口的 IP
auto_failback on #如果主节点重新恢复,主节点将抢占资源恢复服务,如果为 off,则只当备用节点当掉后,主节点恢复
watchdog /dev/watchdog #监控设备
node heartbeat_73 ### 节点和主机名(节点主机名必须和 uname - n 的结果一样)
node heartbeat_72 ### 节点和主机名(节点主机名必须和 uname - n 的结果一样)
haresources 主备节点配置文件
[root@heartbeat_73 /etc/ha.d]#grep -v “^#” haresources
master IPaddr::211.162.174.74/24/eth0:1/ nginx #后端要跟服务名
haresources 文件的用法:
资源文件(/etc/ha.d/haresources)
Haresources 文件用于指定双机系统的主节点、集群 IP、子网掩码、广播地址以及启动的服务等集群资源,文件每一行可以包含一个或多个资源脚本名,资源之间使用空格隔开,参数之间使用两个冒号隔开,在两个 HA 节点上该文件必须完全一致,此文件的一般格式为:
node-name network <resource-group>
node-name 表示主节点的主机名,必须和 ha.cf 文件中指定的节点名一致。network 用于设定集群的 IP 地址、子网掩码和网络设备标识 等。需要注意的是,这里指定的 IP 地址就是集群对外服务的 IP 地址,resource-group 用来指定需要 Heartbeat 托管的服务,也就是这些 服务可以由 Heartbeat 来启动和关闭。如果要托管这些服务,就必须将服务写成可以通过 start/stop 来启动和关闭的脚步,然后放到 /etc /init.d/ 或者 /etc/ha.d/resource.d/ 目录下,Heartbeat 会根据脚本的名称自动去 /etc/init.d 或者 /etc /ha.d/resource.d/ 目录下找到相应脚步进行启动或关闭操作。
下面对配置方法进行具体说明:
node1 IPaddr::192.168.60.200/24/eth0/ Filesystem:: /dev/sdb5::/webdata::ext3 httpd tomcat
其中,node1 是 HA 集群的主节点,IPaddr 为 heartbeat 自带的一个执行脚 步,Heartbeat 首先将执行 /etc/ha.d/resource.d/IPaddr 192.168.60.200/24 start 的操作,也就是虚拟出一个子网掩码为 255.255.255.0,IP 为 192.168.60.200 的地址。此 IP 为 Heartbeat 对外 提供服务的网络地址,同时指定此 IP 使用的网络接口为 eth0。接着,Heartbeat 将执行共享磁盘分区的挂载操 作,”Filesystem::/dev/sdb5::/webdata::ext3″ 相当于在命令行下执行 mount 操作,即 ”mount -t ext3 /dev/sdb5 /webdata”,最后依次启动 httpd 和 Tomcat 服务。
注意:主节点和备份节点中资源文件 haresources 要完全一样。
authkeys 心跳密钥验证文件
[root@heartbeat_73 /etc/ha.d]#grep -v “^#” authkeys
auth 1
1 sha1 HI!
注意:确保 authkeys 文件的权限为 600
好了,配置文件到现在基本配置完毕。
(以上配置在主 备服务器上都需要配置)
——————————————————————————–
启动 heartbeat
在这之前有四个需要设置的地方:
1,服务器的 IP 需要配置,业务网卡 和 心跳网卡。并规划好 VIP 地址。
2,修改主备节点的 hosts 文件的名字解析(并检测网络是否可以通)
3,由于我们在安装 heartbeat 的时候没有使用 –prefix 选项指定安装目录,所以需要执行以下操作
#cd /etc/ha.d/
#mkdir /usr/etc/ha.d/
#cp -R ./* /usr/etc/ha.d/
(主备服务器上都需要操作)
4,如果心跳网络是专用网卡,那么请在 iptables 中放开限制。
————————————– 分割线 ————————————–
基于 Heartbeat V1 实现 Web 服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm
Heartbeat 实现 Web 服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm
Heartbeat+LVS+Ldirectord 高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm
DRBD+Heartbeat+NFS 高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm
Heartbeat 基于 CRM 使用 NFS 对 MySQL 高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm
Heartbeat 高可用 httpd 基于 Resources 简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm
————————————– 分割线 ————————————–
为了测试 heartbeat,我们现在在主备服务器上分别安装 nginx(或者 httpd),并吧默认的 index.html 做个小小的改动
这是备用服务器上的 主页面。
这是主服务器上的 主页面。
做好上述操作后,接下来捣鼓 heartbeat 启动脚本,默认按上述方法安装好后,会在 /etc/init.d/ 目录下创建 heartbeat 启动脚本,但是并没在 chkconfig 启动列表中出现。
chkconfig –add heartbeat
chkconfig –list // 查看是否已经设置为开机启动。
service heartbeat stop // 确保未启动状态
更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2015-04/116153p2.htm