Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统。心跳服务和集群通信是高可用集群的两个关键组件,在 Heartbeat 项目里,由 heartbeat 模块实现了这两个功能。
摘自 <https://baike.baidu.com/item/Heartbeat/16275>
tar包下载地址: http://linux-ha.org/wiki/Downloads
- Heartbeat 3.0.6: http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
- Cluster Glue 1.0.12: http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
- Resource Agents 3.9.6: https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz
os
rhel7.2
node01
eno16780032
192.168.1.151
心跳
ens224
10.1.1.1
node02
eno16780032
192.168.1.152
心跳
ens224
10.1.1.2
vip
192.168.1.161
# 以下 步骤均在 node01 & node02 操作
1、初始化系统
# vi /etc/selinux/config
SELINUX=disabled
# systemctl disable firewalld
# hostnamectl set-hostname xxx
# vi /etc/hosts
192.168.1.151 mysql-data01
192.168.1.152 mysql-data02
10.1.1.1 priv1
10.1.1.2 priv2
# reboot
2、Cluster Glue 1.0.12 安装
# yum -y install glib2-devel libtool-ltdl-devl net-snmp-devel bzip2-devel ncurses-devel openssl-devel libtool libxml2-devel gettext bison flex zlib-devel mailx which libxslt docbook-dtds docbook-style-xsl PyXML shadow-utils opensp autoconf automake bzip2
# yum install -y glib2-devel libxml2 libxml2-devel bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel make wget docbook-dtds docbook-style-xsl bzip2-devel asciidoc libuuid-devel
# groupadd haclient
# useradd -g haclient -M -s /sbin/nologin hacluster
# cd /usr/local/src/
# wget http://hg.linux-ha.org/glue/archive/0a7add1d9996.tar.bz2
# bunzip2 0a7add1d9996.tar.bz2
# tar -xf 0a7add1d9996.tar
# cd Reusable-Cluster-Components-glue--0a7add1d9996
# ./autogen.sh
autoconf: autoconf (GNU Autoconf) 2.69
automake: automake (GNU automake) 1.13.4
libtoolize --ltdl --force --copy
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `.'.
libtoolize: copying file `./ltmain.sh'
libtoolize: putting auxiliary files in `.'.
libtoolize: copying file `libltdl/config/compile'
libtoolize: copying file `libltdl/config/config.guess'
libtoolize: copying file `libltdl/config/config.sub'
libtoolize: copying file `libltdl/config/depcomp'
libtoolize: copying file `libltdl/config/install-sh'
libtoolize: copying file `libltdl/config/missing'
libtoolize: copying file `libltdl/config/ltmain.sh'
libtoolize: putting macros in `libltdl/m4'.
libtoolize: copying file `libltdl/m4/argz.m4'
libtoolize: copying file `libltdl/m4/libtool.m4'
libtoolize: copying file `libltdl/m4/ltdl.m4'
libtoolize: copying file `libltdl/m4/ltoptions.m4'
libtoolize: copying file `libltdl/m4/ltsugar.m4'
libtoolize: copying file `libltdl/m4/ltversion.m4'
libtoolize: copying file `libltdl/m4/lt~obsolete.m4'
libtoolize: putting libltdl files in `libltdl'.
libtoolize: `COPYING.LIB' not found in `/usr/share/libtool/libltdl'
aclocal
autoheader
automake --add-missing --include-deps --copy
configure.ac:71: warning: AM_INIT_AUTOMAKE: two- and three-arguments forms are deprecated. For more info, see:
configure.ac:71: http://www.gnu.org/software/automake/manual/automake.html#Modernize-AM_005fINIT_005fAUTOMAKE-invocation
configure.ac:84: installing './compile'
configure.ac:28: installing './config.guess'
configure.ac:28: installing './config.sub'
configure.ac:71: installing './install-sh'
configure.ac:71: installing './missing'
Makefile.am: installing './INSTALL'
lib/clplumbing/Makefile.am:25: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/clplumbing/Makefile.am: installing './depcomp'
lib/lrm/Makefile.am:21: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/pils/Makefile.am:22: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/plugins/InterfaceMgr/Makefile.am:22: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/plugins/compress/Makefile.am:32: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/plugins/lrm/Makefile.am:25: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/plugins/stonith/Makefile.am:33: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lib/stonith/Makefile.am:22: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
logd/Makefile.am:23: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lrm/admin/Makefile.am:36: warning: '%'-style pattern rules are a GNU make extension
lrm/admin/Makefile.am:21: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lrm/lrmd/Makefile.am:21: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
lrm/test/Makefile.am:23: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
replace/Makefile.am:20: warning: 'INCLUDES' is the old name for 'AM_CPPFLAGS' (or '*_CPPFLAGS')
autoconf
Now run ./configure
# ./configure --prefix=/usr/local/heartbeat && make && make install
3、Resource Agents 3.9.6 安装
# cd /usr/local/src
# wget https://github.com/ClusterLabs/resource-agents/archive/v3.9.6.tar.gz
# tar -zxf v3.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
# export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
# ./configure --prefix=/usr/local/heartbeat/
# ln -s /usr/local/heartbeat/lib/* /lib/
# ln -s /usr/local/heartbeat/lib/* /lib64/
# make && make install
注意:若遇到 metadata-IPv6addr.xml:1: parser error : Document is empty 报错,则重新解压等步骤
4、Heartbeat 3.0.6 安装
# cd /usr/local/src/
# wget http://hg.linux-ha.org/heartbeat-STABLE_3_0/archive/958e11be8686.tar.bz2
# bunzip2 958e11be8686.tar.bz2
# tar -xf 958e11be8686.tar
# cd Heartbeat-3-0-958e11be8686/
# ./bootstrap
…
autoconf
Now run ./configure.
# ./configure --prefix=/usr/local/heartbeat/
# make # 报错
In file included from ../include/lha_internal.h:41:0,
from strlcpy.c:1:
/usr/local/heartbeat/include/heartbeat/glue_config.h:105:0: error: "HA_HBCONF_DIR" redefined [-Werror]
#define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/"
^
In file included from ../include/lha_internal.h:38:0,
from strlcpy.c:1:
../include/config.h:390:0: note: this is the location of the previous definition
#define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d"
^
cc1: all warnings being treated as errors
gmake[1]: *** [strlcpy.lo] 错误 1
gmake[1]: 离开目录“/usr/local/src/Heartbeat-3-0-958e11be8686/replace”
make: *** [all-recursive] 错误 1
# vi /usr/local/heartbeat/include/heartbeat/glue_config.h
#define HA_HBCONF_DIR "/usr/local/heartbeat/etc/ha.d/" # 按下dd将这最后一行删除,保存退出
# make && make install
5、配置
# cd /usr/local/heartbeat/share/doc/heartbeat
# cp -a ha.cf authkeys haresources /usr/local/heartbeat/etc/ha.d/
# cd /usr/local/heartbeat/etc/ha.d
# chmod 600 etc/ha.d/authkeys
# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/* /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/
# ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/
# vi ha.cf
debugfile /var/log/ha-debug # 保存调试信息文件
logfile /var/log/ha-log # 日志文件
logfacility local0 # 表示使用系统日志
keepalive 2 # 心跳的时间间隔,单位s
deadtime 30 # 超出该时间间隔未收到对方节点的心跳,则判定对方死亡
warntime 10 # 超出该时间间隔未收到对方节点的心跳,则发出警告记录到日志中
initdead 120 # 在某系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔,取值至少为deadtime的2倍
udpport 694 # 设置广播通信使用的端口,694为默认使用的端口号
bcast ens224 # 传播心跳的广播播网卡信息
ucast ens224 10.1.1.2 # node02 配置 10.1.1.1 # 设置对方机器心跳检测的网卡和IP
auto_failback on # heartbeat的两台主机分别为主节点和从节点。主节点在正常情况下占用资源并运行所有的服务,遇到故障时把资源交给从节点由从节点运行服务。在该选项设为on的情况下,一旦主节点恢复运行,则 自动获取资源并取代从节点,否则不取代从节点
node mysql-data01 # 配置主从的节点信息
node mysql-data02
ping 192.168.1.1 # ping模式用于测试 如果ping不通 某个主机 就认为当前断网 需要转移vip
respawn hacluster /usr/local/heartbeat/libexec/heartbeat/ipfail # 指定与heartbeat一同启动和关闭的进程,该进程被自动监视,遇到故障则重新启动。最常用的进程是ipfail,该进程用于检测和处理网络故障,需要配合ping语句指定的ping node来检测网络连接。如果你的系统是64bit,请注意该文件的路径
apiauth ipfail gid=haclient uid=hacluster # 指定用户&组
# vi authkeys # 该文件表示发送心跳时 机器用于验证的key的hash算法 双方必须配置成一致的密码
auth 2
2 sha1 HI!
# vi haresources
mysql-data01 192.168.1.161/24/eno16780032 #说明:mysql-data01 为主节点hostname,192.168.1.161为vip,/24为掩码为24的网段,eno16780032为vip的设备名
6、启动
# chkconfig heartbeat on
# systemctl restart heartbeat
# ip a
# tailf /var/log/ha-log
7、测试
# 停心跳网卡,查看脑裂情况
# down 一个节点,查看 vip 漂移情况
8、进阶
[App] rhel7 下安装 Heartbeat 3.0.6
最新推荐文章于 2024-08-13 21:10:21 发布