A Simple configuration of Heartbeat v2

02/18/2017 | | Post a Comment

实验环境及软件包版本:

CentOS-6.5-x86_64-LiveDVD.iso

Kernel:2.6.32-431.el6.x86_64

rpm包:
heartbeat-2.1.4-12.el6.x86_64.rpm
heartbeat-debuginfo-2.1.4-12.el6.x86_64.rpm
heartbeat-devel-2.1.4-12.el6.x86_64.rpm
heartbeat-gui-2.1.4-12.el6.x86_64.rpm
heartbeat-ldirectord-2.1.4-12.el6.x86_64.rpm
heartbeat-pils-2.1.4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
libnet-1.1.6-2.el6.pp.x86_64.rpm
libnet-1.1.6-7.el6.x86_64.rpm

主机IP地址:

node1:10.77.7.168

node2:10.77.7.215

实验环境注意事项:

关闭防火墙,关闭selinux:
[root@node2 ~]# service iptables stop
[root@node2 ~]# setenforce 0

注意两个节点的时间要同步,如果时区不同步,执行以下命令:
更改时区
[root@node1 ~]# rm /etc/localtime
rm: remove regular file `/etc/localtime’? y
[root@node1 ~]# ln -sv /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
`/etc/localtime’ -> `/usr/share/zoneinfo/Asia/Shanghai’

通过网络时间服务器同步时间
[root@node1 ~]# ssh node2 ‘ntpdate time.windows.com’;ntpdate time.windows.com
18 Feb 17:09:07 ntpdate[3216]: adjust time server 13.79.154.18 offset 0.021834 sec
18 Feb 17:09:10 ntpdate[4211]: adjust time server 13.79.154.18 offset -0.046005 sec

检查时间是否一致
[root@node2 ~]# ssh node1 ‘date’;date
Sat Feb 18 17:02:46 CST 2017
Sat Feb 18 17:02:46 CST 2017

实验步骤:

一、首先配置主机名,配置hosts文件(不使用DNS):

[root@node1 ~]# vim /etc/sysconfig/network

NETWORKING=yes
HOSTNAME=node1

[root@node1 ~]# vim /etc/hosts

127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
10.77.7.168 node1
10.77.7.215 node2

配置完之后,确保主机名一致:

[root@node1 ~]# hostname
node1
[root@node1 ~]# uname -n
node1

二、进行双机认证

1、生成密钥对

[root@node1 ~]# ssh-keygen
Generating public/private rsa key pair.

2、复制公钥至远程主机

[root@node1 ~]# ssh-copy-id -i node2

双向认证需要在node2上做同样的操作

三、安装heartbeat

1、下载相关软件包,使用scp命令远程复制包组到node2节点上

[root@node1 ~]# scp heartbeatv2/* node2:/root/
heartbeat-2.1.4-12.el6.x86_64.rpm 100% 1388KB 1.4MB/s 00:00
heartbeat-debuginfo-2.1.4-12.el6.x86_64.rpm 100% 3505KB 3.4MB/s 00:00

2、安装heartbeat:

[root@node2 ~]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
error: Failed dependencies:
PyXML is needed by heartbeat-2.1.4-12.el6.x86_64
libnet.so.1()(64bit) is needed by heartbeat-2.1.4-12.el6.x86_64

解决软件包的关系依赖性问题:

[root@node2 ~]# yum install PyXML

[root@node2 ~]# rpm -ivh libnet-1.1.6-7.el6.x86_64.rpm(此rpm包scp复制过来的)

[root@node2 ~]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
Preparing… ########################################### [100%]
1:heartbeat-pils ########################################### [ 33%]
2:heartbeat-stonith ########################################### [ 67%]
3:heartbeat ########################################### [100%]

至此,heartbeat安装完成,下面开始进行配置,并以web服务作为资源。

3、配置heartbeat

主要配置三个文件:ha.cf  haresources  authkeys

需要将样例文件复制至/etc/ha.d/目录下,以便配置:

[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf,haresources} /etc/ha.d/

  • 配置authkeys

[root@node1 ~]# vim /etc/ha.d/authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 nashsun

需要更改权限

[root@node1 ~]# chmod 600 /etc/ha.d/authkeys

  • 配置ha.cf

logfile /var/log/ha-log
keepalive 2
deadtime 10
warntime 5
udpport 694
mcast eth0 225.0.0.1 694 1 0
auto_failback on
node node1
node node2
ping 10.77.6.192
compression bz2
compression_threshold 2

  • 配置haresources

haresources是个比较简单的Resources Agent,之后的博客还会利用CRM、pacemaker等进行实验

[root@node1 ~]# cd /etc/ha.d/haresources

node1 10.77.7.171/22/eth0:0 httpd

  • 配置完成之后将这三个文件复制到node2节点下:

[root@node1 ~]# scp -p /etc/ha.d/{authkeys,ha.cf,haresources} node2:/etc/ha.d/
authkeys 100% 644 0.6KB/s 00:00
ha.cf 100% 10KB 10.3KB/s 00:00
haresources 100% 5951 5.8KB/s 00:00

四、配置Httpd进程

[root@node1 ~]# ssh node2 ‘service httpd status’;service httpd status
httpd is stopped
httpd is stopped

编辑配置下监听地址:

[root@node1 ~]# vim /etc/httpd/conf/httpd.conf
Listen 10.77.7.171:80

建配置文件一式两份复制到远程节点:

[root@node1 ~]# scp /etc/httpd/conf/httpd.conf node2:/etc/httpd/conf/httpd.conf
httpd.conf 100% 34KB 33.6KB/s 00:00

创建测试页面:

[root@node1 ~]# echo “node1” > /var/www/html/index.html

[root@node2 ~]# echo “node2” > /var/www/html/index.html

关闭开机自动启动httpd:

[root@node1 ~]# chkconfig httpd off

五、测试实验结果

启动heartbeat服务

[root@node2 ~]# ssh node1 ‘service heartbeat start’;service heartbeat start
Starting High-Availability services:
2017/02/18_17:45:15 INFO: Resource is stopped
Done.

Starting High-Availability services:
2017/02/18_17:45:20 INFO: Resource is stopped
Done.

关闭node1的heartbeat的服务,测试节点是否failover

 

测试显示已经切换到node2节点的httpd进程

经测试failback也已经成功,不再赘述。

实验结束

实验涉及的RPM包资源

 

 



Want to say something? Post a comment

电子邮件地址不会被公开。 必填项已用*标注