首页 系统 HeartBeat单独提供高可用操作

HeartBeat单独提供高可用操作

本文目录:
1.简介
2.安装heartbeat
 2.1 编译安装Heartbeat
3.heartbeat相关配置文件
 3.1 配置文件ha.cf
 3.2 配置文件authkeys
 3.3 配置文件haresources
4.ASP站长网示例:heartbeat为httpd提供高可用服务
 
1.简介
heartbeat是人所众知高可用软件。但是在以前,heartbeat是Linux-ha项目里一大堆提供高可用组件的集合体:
 
Messaging Layer(消息传递层)
local resource manager(LRM,本地资源管理,cluster glue的一个功能)
stonith(爆头,cluster glue的一个功能)
Resource Agent(RA,资源代理)、
cluster resource manager(CRM,集群资源管理器,现在独立出去的pacemaker)。
现在,由于linux-ha将很多这些组件都分离为一个个单独的软件,heartbeat已经只代表消息层(取代它的是corosync)。而且linux-ha项目团队已经不再维护heartbeat,目前能从官方获取到的最新版本是Heartbeat 3.0.6,在epel中可获取到"Heartbeat 3.0.4"版本的rpm包。
 
虽然Heartbeat只代表高可用集群的消息传递层,但它结合cluster glue和resource agent也可以提供高可用服务,这正是本文的内容。相比于corosync+pacemaker,heartbeat要轻量级的多,配置起来也简单许多。相应的,它的功能和完整性要简陋的多,它只支持两个heartbeat节点(结合pacemaker可多于两节点),且加载资源的速度比较慢。
 
当然,既然heartbeat是消息传递层,它也能配合pacemaker,但是不建议如此。而且这样搭配时,各个组件的版本要求很严格。
 
2.安装heartbeat
如果使用yum安装,可以配置epel源。注意,在CentOS7的epel上,已经没有heartbeat了。
 
release=`grep -o "[0-9]" /etc/RedHat-release | head -1`
cat <<eof>/etc/yum.repos.d/epel.repo
[epel]
name=epelrepo
baseurl=https://mirrors.aliyun.com/epel/${release}Server/\$basearch
gpgcheck=0
enable=1
eof
 
yum -y install heartbeat
可以看到,安装heartbeat的时候,同时还会安装cluster-glue和resource-agent。
 
 
 
然后提供配置文件。
 
cp -a /usr/share/doc/heartbeat-3.0.4/{ha.cf,haresources,authkeys} /etc/ha.d/
chmod 600 /etc/ha.d/authkeys
 
2.1 编译安装heartbeat
不建议编译安装heartbeat,heartbeat这个程序本身附带的很多脚本在路径指定上很混乱,安装后很可能需要到处修改脚本中关于路径的变量。
 
如果要编译安装heartbeat,则必须先安装cluster-glue和resource-agent,建议这3个程序安装在同一路径下。
 
(1).安装依赖包。
 
yum -y install gcc gcc-c++ autoconf automake libtool glib2-devel libxml2-devel bzip2 bzip2-devel e2fsprogs-devel libxslt-devel libtool-ltdl-devel asciidoc
创建好所需组和所有者,在编译cluster-glue会设置一些文件的属组和属主分别为haclient、hacluster,因此名称必须为这两个。
 
groupadd -g 65 haclient
useradd -g 65 -u 17 hacluster
(2).编译cluster-glue。
 
tar xf Cluster\ Glue\ 1.0.12.bz2
cd Reusable-Cluster-Components-glue–0a7add1d9996/
./autogen.sh
./configure –prefix=/usr/local/heartbeat LIBS=/lib64/libuuid.so.1
make
make install
如果make时有如下错误:
 
./.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'
collect2: ld returned 1 exit status
gmake[2]: *** [ipctest] Error 1
gmake[2]: Leaving directory `/root/Reusable-Cluster-Components-glue–0a7add1d9996/lib/clplumbing'
gmake[1]: *** [all-recursive] Error 1
gmake[1]: Leaving directory `/root/Reusable-Cluster-Components-glue–0a7add1d9996/lib'
make: *** [all-recursive] Error 1
解决方法:在configure中使用LIBS指向正确的库文件,64位使用/lib64,32位使用/lib
 
./configure LIBS=/lib64/libuuid.so.1
如果是如下错误:
 
gmake[2]: a2x: Command not found
解决方法:yum install asciidoc
 
可以看下cluster-glue提供了哪些命令。
 
[root@xuexi ~]# ls /usr/local/heartbeat/sbin/
cibsecret  ha_logger  hb_report  lrmadmin    meatclient  stonith
从此不难看出,cluster-glue是整个ha的核心组件,除了crm、messageing layer、resource agent,所有的功能包括最基本的功能都是它提供的。例如,日志记录,stonith,lrm等。
 
(3).编译resource-agent。
 
tar xf  resource-agents-3.9.6.tar.gz
cd resource-agents-3.9.6
./autogen.sh
./configure –prefix=/usr/local/heartbeat
make
make install
(4).编译heartbeat。
 
tar xf heartbeat\ 3.0.6.bz2
cd Heartbeat-3-0-958e11be8686/
./bootstrap
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
./configure –prefix=/usr/local/heartbeat –with-daemon-user=hacluster –with-daemon-group=haclient LIBS=/lib64/libuuid.so.1
make
make install
如果出现如下错误:
 
【configure时错误:】
configure: error: in `/root/Heartbeat-3-0-958e11be8686':
configure: error: Core development headers were not found
 
解决方法:
export CFLAGS="$CFLAGS -I/usr/local/heartbeat/include -L/usr/local/heartbeat/lib"
 
【make时错误:】
/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
gmake[1]: Leaving directory `/root/Heartbeat-3-0-958e11be8686/replace'
make: *** [all-recursive] Error 1
 
解决方法1:
删除/usr/local/heartbeat/include/heartbeat/glue_config.h 中的第105行
#define HA_HBCONF_DIR "/etc/ha.d/"
sed -i '105d' /usr/local/heartbeat/include/heartbeat/glue_config.h
 
解决方法2:configure上加上忽略错误选项
./configure –prefix=/usr/local/heartbeat –with-daemon-user=hacluster –with-daemon-group=haclient LIBS=/lib64/libuuid.so.1 –enable-fatal-warnings=no
(5).编译后配置。
 
mkdir -p /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat
cp -a /usr/lib/ocf/lib/heartbeat/ocf-* /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/
ln -s /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/* /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/
ln -s /usr/local/heartbeat/lib64/heartbeat/plugins/* /usr/local/heartbeat/lib/heartbeat/plugins/
ln -s /usr/local/heartbeat/share/heartbeat /usr/share/heartbeat
提供配置文件:
 
cd /usr/local/heartbeat
cp -a share/doc/heartbeat/{ha.cf,haresources,authkeys} etc/ha.d/
chmod 600 etc/ha.d/authkeys
加入服务器启动列表:
 
chkconfig –add heartbeat
chkconfig –level 2345 heartbeat on
设置环境变量PATH:
 
echo 'export PATH=/usr/local/heartbeat/sbin:/usr/local/heartbeat/bin:$PATH' >/etc/profile.d/ha.sh
chmod +x /etc/profile.d/ha.sh
source /etc/profile.d/ha.sh
设置man PATH:
 
echo 'MANPATH /usr/local/heartbeat/share/man' >>/etc/man.config
3.heartbeat相关配置文件
heartbeat配置文件有3个:
 
密钥文件authkeys,用在messaging layer下各节点之间的认证,防止外界主机随意加入节点(600权限);
heartbeat核心配置文件,ha.cf;
资源管理配置文件:haresources;
它们的生效位置在/etc/ha.d/目录下,但是初始时在此目录下并没有这3个文件,它们的样例配置文件在/usr/share/docs/heartbeat-$$version/目录下,可以将它们复制到/etc/ha.d目录下。
 
#以下是yum安装,非编译安装的操作
cp /usr/share/doc/heartbeat-3.0.4/{authkeys,ha.cf,haresources} /etc/ha.d/
 
3.1 配置文件ha.cf
ha.cf的部分内容如下。该文件看起来很多,但如果不结合pacemaker,其实要修改的就几项,包括node和bcast/mcast以及auto_failback,有时还配置下ping和log。注意该文件从上往下读取,指令的配置位置很重要,因此一般不要修改它们的出现顺序。
 
#  如果logfile/debugfile/logfacility都没有设置,则等价于设置了"use_logd yes"
#  且use_logd设置为yes后,logfile/debugfile/logfacility的设置都失效
#
#      Note on logging:
#      If all of debugfile, logfile and logfacility are not defined,
#      logging is the same as use_logd yes. In other case, they are
#      respectively effective. if detering the logging to syslog,
#      logfacility must be "none".
#
#      File to write debug messages to
#debugfile /var/log/ha-debug
#
#
#      File to write other messages to
#
#logfile        /var/log/ha-log
#
#
#      Facility to use for syslog()/logger
#
logfacility    local0
#
#
#      A note on specifying "how long" times below…
#
#      The default time unit is seconds
#              10 means ten seconds
#
#      You can also specify them in milliseconds
#              1500ms means 1.5 seconds
#
#
#      keepalive: how long between heartbeats?
#  发送心跳信息的时间间隔,默认每两秒发送一次心跳信息

关于作者: dawei

【声明】:九江站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。

热门文章