Heartbeat是著名HA项目,Heartbeat在3.0之后分拆为Heartbeat和Pacemaker 两个各自独立项目。Pacemaker在后续发展中使用Corosync作为消息层,和Corosync紧密结合,同时也保留Heartbeat作为可选的消息层。所以新版Pacemaker 1.1.x 和heartbeat3.x 结合方面有些问题,安装复杂,特此记录下安装过程中的问题及解决办法,以供参考。

安装环境:

Redhat Enterprise linux 6.4 (64Bit)

安装路径:/usr/local/heartbeat

配置文件路径:/etc/heartbeat/

软件介绍:

Cluster Glue 1.0.9 (中间层,粘合heartbeat和pacemaker,提供LRM和STONITH等工具及类库)

Resource Agents 3.9.2(提供各类资源脚本以供调用)

Heartbeat 3.0.5 (消息层,负责消息传递)

注:Heartbeat 2.1.4之后原先的项目被拆分成Cluster Glue,Resource Agents,Heartbeat 3个子项目

下载:http://www.linux-ha.org/wiki/Downloads

Pacemaker 1.1.11(即Cluster Resource Manager,简称CRM,用来管理整个HA的控制中心,属于管理层,客户端通过pacemaker来配置管理监控整个集群)

注:从Pacemaker 1.1.8开始,crmsh发展成一个独立项目,Pacemaker中不再提供。我们安装好Pacemaker后,是没有crm这个命令行模式的资源管理器的,需另行下载安装。(https://savannah.nongnu.org/projects/crmsh/)

Redhat发行版提供了另一个命令行管理器pcs作为crmsh替代, pcs还提供图形界面但需另外安装。

pacemaker原理 pacemaker下载_pacemaker原理

Pacemaker内部结构

准备工作:

1.yum install或rpm -ivh安装以下依赖软件包,以免安装过程中出错

yum -y install autoconf automake libtool glib2-devel libxml2-devel bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel libuuid-devel docbook-style-xsl docbook-dtds

2.添加用户和组

新建用户hacluster属于新建组haclient,用于配置respawn,软件安装中均指定uid=hacluster,gid=haclient

# groupadd haclient # useradd -g haclient hacluster -M -s /sbin/nologin

按顺序安装软件:

1.安装Cluster Glue

# tar jxvf glue-1.0.9.tar.bz2
# cd Reusable-Cluster-Components-glue--glue-1.0.9/
# ./autogen.sh 
# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
# make && make install

注:在./configure的时候指定一下LIBS='/lib64/libuuid.so.1',同理Resource Agents,Heartbeat,Pacemaker

    在./configure的时候都指定一下,不然继续报错。

./.libs/libplumb.so: undefined reference to `uuid_parse’
 ./.libs/libplumb.so: undefined reference to `uuid_generate’
 ./.libs/libplumb.so: undefined reference to `uuid_copy’
 ./.libs/libplumb.so: undefined reference to `uuid_is_null’
 ./.libs/libplumb.so: undefined reference to `uuid_unparse’
 ./.libs/libplumb.so: undefined reference to `uuid_clear’
 ./.libs/libplumb.so: undefined reference to `uuid_compare’
...........................................................
configure: error: You do not have the libuuid development package installed

2.安装Resource Agents

# cd ClusterLabs-resource-agents-b735277/
# ./autogen.sh
# ./configure --prefix=/usr/local/heartbeat --sysconfdir=/etc/heartbeat libdir=/usr/local/heartbeat/lib64 CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1' 
# make && make install
//建立一个软连接,避免编译时找不到所需要的包.
# ln -s /usr/local/heartbeat/lib64/* /lib64/

注: 如缺少一些依赖包,会有错误提示,按照提示安装相应包即可。

docbook-style-xsl,docbook-dtds包,

     如网速慢容易出现错误,可单独下载或用yum install docbook-style-xsl docbook-dtds安装软件包,

       以提高安装速度。

无法下载docbook时会发生类似错误:

error : Operation in progress
warning: failed to load external entity "http://docbook.sourceforge.net/release/xsl/current/html/formal.xsl"
compilation error: file http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl line 46 element include
xsl:include : unable to load http://docbook.sourceforge.net/release/xsl/current/html/formal.xsl
http://docbook.sourceforge.net/release/xsl/current/html/table.xsl:1: parser error : Document is empty
http://docbook.sourceforge.net/release/xsl/current/html/table.xsl:1: parser error : Start tag expected, '<' not found
compilation error: file http://docbook.sourceforge.net/release/xsl/current/html/docbook.xsl line 47 element include
xsl:include : unable to load http://docbook.sourceforge.net/release/xsl/current/html/table.xsl

3.安装Heartbeat

# cd Heartbeat-3-0-7e3a82377fa8/
# ./bootstrap
# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient --sysconfdir=/etc/heartbeat CFLAGS=-I/usr/local/heartbeat/include  LDFLAGS=-L/usr/local/heartbeat/lib64 LIBS='/lib64/libuuid.so.1'
# make && make install

make报错:

In file included from ../include/lha_internal.h:41,
                 from strlcpy.c:1:
/usr/local/heartbeat/include/heartbeat/glue_config.h:105:1: error: "HA_HBCONF_DIR" redefined
In file included from ../include/lha_internal.h:38,
                 from strlcpy.c:1:
../include/config.h:390:1: error: this is the location of the previous definition
gmake[1]: *** [strlcpy.lo] Error 1

解决办法:

编辑/usr/local/heartbeat/include/heartbeat/glue_config.h的最后1行(105行)

将 #define HA_HBCONF_DIR "/etc/heartbeat/ha.d/"  注释掉 ,避免路径重复定义错误。

4.Pacemaker安装

Pacemaker默认使用Corosync,yum和rpm安装Pacemaker均是使用Corosync,因此下载源码包进行安装。

注:有同学曾用apt-get在ubuntu上成功安装Pacemaker+heartbeat,这说明RPM包在制作时绑定了Corosync,而deb包则没有。

https://github.com/ClusterLabs/pacemaker/

# cd pacemaker-master-1.1.11/
# ./autogen.sh
# ./configure --prefix=/usr/local/heartbeat --with-daemon-user=hacluster --with-daemon-group=haclient libdir=/usr/local/heartbeat/lib64 CFLAGS=-I/usr/local/heartbeat/include LDFLAGS=-L/usr/local/heartbeat/lib64  LIBS='/lib64/libuuid.so.1'  --with-heartbeat
# make && make install

错误:

configure: error: Version of libqb is too old: v0.13 or greater requried

解决方法:安装libqb-devel和libqb

rpm -ivh  libqb-devel-****.rpm和libqb-****.rpm

错误:

No package 'dbus-1' found

解决方法:安装dbus-devel

rpm -ivh  dbus-devel-****.rpm

错误:

checking for native corosync... try
checking for cpg... configure: error: Package requirements (libcpg) were not met:
No package 'libcpg' found

解决方法:安装corosynclib-devel

yum -y install corosynclib-devel 或 rpm -ivh corosynclib-devel-*.rpm

注:corosync,corosynclib,corosynclib-devel相互间存在依赖关系,3个软件包的版本必须相同

make出现错误:

gmake[2]: Entering directory `/tools/pacemaker-master/lib/common'
  CC     ipc.lo
  CC     utils.lo
cc1: warnings being treated as errors
utils.c: In function ‘crm_generate_uuid’:
utils.c:2515: error: implicit declaration of function ‘uuid_generate’
utils.c:2515: error: nested extern declaration of ‘uuid_generate’
utils.c:2516: error: implicit declaration of function ‘uuid_unparse’
utils.c:2516: error: nested extern declaration of ‘uuid_unparse’
gmake[2]: *** [utils.lo] Error 1

解决方法:安装libuuid-devel

rpm -ivh libuuid-devel-*.rpm

然后重新执行./configure,再重新make

因自定义路径没采用默认路径,所以安装完成后要链接一些必要库文件,以免运行时出错

ln -s /usr/local/heartbeat/usr/lib/ocf/* /usr/lib/ocf
ln -s /usr/local/heartbeat/libexec/pacemaker /usr/libexec
ln -s /usr/local/heartbeat/share/pacemaker /usr/share
ln -s /usr/local/heartbeat/var/lib/pacemaker /var/lib

ln -s /usr/local/heartbeat/lib64/pkgconfig/*.* /usr/lib64/pkgconfig/
ln -s /usr/local/heartbeat/lib64/python2.6/site-packages/*    /usr/lib64/python2.6/site-packages/

至此4个软件都已安装成功,下节介绍Heartbeat+Pacemaker+Apache+MySQL 设置和测试

FAQ

Q:为什么在/var/log/messages里看到很多下面这样的警告?

 

A :这种情况是因为部署Heartbeat是直接从其它机器上拷贝过来导致的。直接拷过来会导致两个节点上的uuid冲突,解决方法是强制某个Hearbeat重新生成uuid,先停止Heatbeat然后删除hb_uuid这个文件(可以通过find命令查找)重启就好了:

# rm –rf /usr/local/heartbeat/var/lib/heartbeat/hb_uuid

 

Q:什么是“脑裂”问题?

A :采用keepalive等心跳软件,需要注意“脑裂”问题: "在“双机热备”高可用(HA)系统中,当联系2个节点的“心跳线”断开时,本来为一整体、动作协调的HA系统,就分裂成为2个独立的个体。由于相互失去了联系,都以为是对方出了故障,2个节点上的HA软件像“裂脑人”一样,“本能”地争抢“共享资源”、争起“应用服务”,就会发生严重后果:或者共享资源被瓜分、2边“服务”都起不来了;或者2边“服务”都起来了,但同时读写“共享存储”,导致数据损坏(常见如数据库轮询着的联机日志出错)。

 

Q:启动heartbaet的时候可能会报很多库找不到的错误:

A:可以先通过find命令查找,然后通过建立软连接就可以解决了:

pacemaker使用默认路径/usr/libexec/pacemaker时 # ln -s /usr/libexec/pacemaker/* /usr/local/heartbeat/lib64/heartbeat/

pacemaker使用自定义路径/usr/local/heartbeat时 # ln -s /usr/local/heartbeat/libexec/pacemaker/* /usr/libexec

转载于:https://blog.51cto.com/ittony/1541670