Compile and install Heartbeat from source code on centos7

  Recently, I encountered the modification of a third-party software installation package, and unified the installation path to the /opt/ path. Originally it was installed directly using yum. This article introduces how to install Heartbeat on centos7 using source code compilation.

1. Understand what Heartbeat is

  The Heartbeat project is an integral part of the Linux-HA project, which implements a high-availability cluster system. Heartbeat service and cluster communication are two key components of a high-availability cluster. In the Heartbeat project, these two functions are implemented by the heartbeat module.

Principle: The core of heartbeat includes two parts, the heartbeat monitoring part and the resource takeover part. Heartbeat monitoring can be performed through network links and serial ports, and it supports redundant links. They send messages to each other to tell each other their current status. status, if no message sent by the other party is received within the specified time, the other party is considered invalid. At this time, the resource takeover module needs to be started to take over the resources or services running on the other party's host.

Heartbeat’s official address: http://www.linux-ha.org/wiki/Download

2. Compile and install Heartbeat

1. Prepare the compilation environment

服务器:centos7

安装依赖包:yum install -y gcc gcc-c++ autoconf automake libnet  libtool glib2-devel libxml2-devel bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel docbook-dtds docboot-style-xsl asciidoc

创建用户和用户组:
groupadd haclient #创建组haclient
useradd -g haclient hacluster -M -s /sbin/nologin  #创建用户hacluster

2. Download the relevant installation package

  The installation package files that need to be downloaded to compile and install Heartbeat from source code include (note that you need to install them in order):

3. Compile cluster-glue

#解压安装包
tar -xf 0a7add1d9996.tar.bz2
#进入解压后的目录
cd Reusable-Cluster-Components-glue--0a7add1d9996/
#执行脚本
./autogen.sh
#执行configure
./configure --prefix=/opt/heartbeat/ --sysconfdir=/opt/heartbeat/etc libdir=/opt/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
#编译并安装
make && make install

4. Compile resource agents

Resource agents are ocf scripts for various resources. These scripts are called by LRM to start, stop, monitor, etc. various resources.

#解压安装包
tar xf resource-agents-3.9.6.tar.gz
#进入解压后的目录
cd resource-agents-3.9.6/
#执行脚本
./autogen.sh
#执行configure
./configure --prefix=/opt/heartbeat/ --sysconfdir=/opt/heartbeat/etc libdir=/opt/heartbeat/lib64 CFLAGS=-I/opt/heartbeat/include LDFLAGS=-I/opt/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
#编译并安装
make && make install

5. Compile and install heartbeat

#解压安装包
tar -jxvf 958e11be8686.tar.bz2
#进入解压目录
cd Heartbeat-3-0-958e11be8686
#执行脚本
./bootstrap
#执行configure
./configure --prefix=/opt/heartbeat --sysconfdir=/opt/heartbeat/etc CFLAGS=-I/opt/heartbeat/include LDFLAGS=-L/opt/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
#创建库文件链接
ln -s /opt/heartbeat/lib64/\*    /lib64
#修改源码文件,否则会make报错
vim /opt/heartbeat/include/heartbeat/glue_config.h
  /*define HA_HBCONF_DIR “/usr/local/heartbeat/etc/ha.d/”*/ #把这一行用/**/注释掉或者删除掉
#编译并安装
make && make install

6. Copy relevant files

#复制配置源码中的配置文件到配置目录
cp -rf doc/{ha.cf,haresources,authkeys} /opt/heartbeat/etc/ha.d/
mkdir -p /opt/heartbeat/usr/lib
cp -rf /usr/lib/ocf /opt/heartbeat/usr/lib/
#修改认证文件及属性
chmod 600 authkeys
#修改配置文件中软件启动路径
sed -i 's#/usr/lib/ocf#/opt/heartbeat/usr/lib/ocf#g' /opt/heartbeat/etc/ha.d/shellfuncs
sed -i 's#/usr/lib/ocf#/opt/heartbeat/usr/lib/ocf#g' /opt/heartbeat/etc/ha.d/resource.d/hto-mapfuncs
sed -i 's#/usr/lib/ocf#/opt/heartbeat/usr/lib/ocf#g' /opt/heartbeat/usr/lib/ocf/lib/heartbeat/ocf-shellfuncs

7. Modify the configuration file and enable the Heartbeat service.

Edit the configuration file ha.cf (/opt/heartbeat/etc/ha.d/ha.cf)

#调试日志
debugfile /var/log/ha-debug         
#日志文件
logfile /var/log/ha-log
#表示使用系统日志            
logfacility local0  
#心跳的时间间隔,默认单位为秒                 
keepalive 1                         
#超出该时间间隔未收到对方节点的心跳,则判定对方死亡
deadtime 30  
#超出该时间间隔未收到对方节点的心跳,则发出警告记录到日志中                       
warntime 10 
#在某系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,该选项用于解决这种情况产生的时间间隔,取值至少为deadtime的2倍                         
initdead 120  
#设置广播通信使用的端口,694为默认使用的端口号                           
udpport 694                         
#传播心跳的广播网卡信息
bcast eth0      
#设置对方机器心跳检测的IP                   
ucast eth0 192.168.17.10   
#在该选项设为on的情况下,一旦主节点恢复运行,则自动获取资源并取代从节点         
auto_failback off              
#配置主从的节点信息(主机名)
node localhost
#如果ping不通该地址,就认为当前断网,需要转移vip
ping 127.0.0.1                  
#指定与heartbeat一同启动和关闭的进程,该进程被自动监视,遇到故障则重新启动。最常用的进程是ipfail,该进程用于检测和处理网络故障,需要配合ping语句指定的ping、node来检测网络连接。如果你的系统是64bit,请注意该文件的路径
respawn hacluster /opt/heartbeat/libexec/heartbeat/ipfail  
#指定用户和组
apiauth ipfail gid=haclient uid=hacluster

Edit authentication keys authkeys (/opt/heartbeat/etc/ha.d/authkeys)

#
#       Authentication file.  Must be mode 600
#
#
#       Must have exactly one auth directive at the front.
#       auth    send authentication using this method-id
#
#       Then, list the method and key that go with that method-id
#
#       Available methods: crc sha1, md5.  Crc doesn't need/want a  key.
#
#       You normally only have one authentication method-id listed in this file
#
#       Put more than one to make a smooth transition when changing auth
#       methods and/or keys.
#
#
#       sha1 is believed to be the "best", md5 next best.   --->sha1是被认为是最好的  咱们用这个就是最好
#
#       crc adds no security, except from packet corruption.
#               Use only on physically secure networks.
#
auth 1
1 crc
2 sha1 HI!
3 md5 Hello!

Edit the resource file haresources (/opt/heartbeat/etc/ha.d/haresources)

  This file represents the management of resources. If it is a host, all startup resources configured in this file will be automatically loaded after the host is started. The resource script is by default in the resource.d directory under the same level directory as haresources.

#机器名 虚拟服务器IP 系统服务
localhost 192.168.17.10 mysqld

8. Close the firewall and start the heartbeat service

Find the executable file heartbeat and enter: heartbeat start

3. Common problems and solutions

1、/usr/bin/ld: cannot find -lplumb

Solution: find / -name libplumb*, find the corresponding dependent library file, and copy it to /usr/lib64.

2. gmake[2]: a2x: command not found

Solution: yum install asciidoc

3. Installing resource-agents-3.9.6, error ln: Unable to create symbolic link "/usr/lib/ocf/resource.d/heartbeat/.ocf-binaries": file already exists

Solution: make uninstall and then reinstall.

4、ERROR: Illegal directive [xxx] in /opt/heartbeat/etc/ha.d//ha.cf

Solution: This situation is usually caused by incorrect configuration in the configuration file ha.cf. Check the configuration file.

Guess you like

Origin blog.csdn.net/fish332/article/details/128540022