CentOS 6 高可用服务 Heartbeat v3 安装以及配置


系统: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服务双机热备

Heartbeat实现Web服务的高可用群集

Heartbeat+LVS+Ldirectord高可用负载均衡解决方案

DRBD+Heartbeat+NFS高可用性配置笔记

Heartbeat基于CRM使用NFS对MySQL高可用

Heartbeat高可用httpd基于Resources简单配置

--------------------------------------分割线 --------------------------------------


为了测试heartbeat ,我们现在在主备服务器上分别安装 nginx(或者 httpd),并吧默认的index.html做个小小的改动

CentOS 6 高可用服务 Heartbeat v3 安装以及配置

这是备用服务器上的 主页面。

CentOS 6 高可用服务 Heartbeat v3 安装以及配置

这是主服务器上的 主页面。

做好上述操作后,接下来捣鼓heartbeat启动脚本,默认按上述方法安装好后,会在 /etc/init.d/ 目录下创建heartbeat 启动脚本,但是并没在 chkconfig 启动列表中出现。
chkconfig --add heartbeat
chkconfig --list  //查看是否已经设置为开机启动。
service heartbeat stop  //确保未启动状态

更多详情见请继续阅读下一页的精彩内容:

  • 1
  • 2
  • 下一页

相关内容