实验环境规划:
实验环境:
CentOS release 6.6(Final) 三台
IP地址:
Node1: eth0:172.16.31.10/16
Node2: eth0:172.16.31.11/16
Client: eth0:172.16.31.12/16
集群架构图 :
一.heartbeat特性介绍:
1.实现底层心跳传递
2.启动关闭集群服务
3.工作节点多达16个节点,由一个主节点和其他备节点组成
对称和非对称节点
4.启动时心跳信息由主节点发送
基于UDP的单播(Unicast),UDP的广播(Broadcast),UDP的多播(Multicast),串行线路通信的传播(serial cable)
二.配置HA集群的前提:
1、节点之间时间必须同步;
建议使用ntp协议进行;
2、节点之间必须要通过主机名互相通信;
建议使用hosts文件;
通信中使用的名字必须与其节点为上“uname -n”命令展示出的名字保持一致;
3、如果是2个节点,需要仲裁设备;
4、节点之间彼此root用户能基于ssh密钥方式进行通信;
注意:定义为集群服务中的任意资源都不能开机自动启动,因为它们将由CRM启动;
三.资源准备:
1、选定vip;
2、httpd:
安装好程序;
配置好httpd,本地测试完成;
关闭服务,并确保开机不会自动启动;
3、shared storage:NFS
四.节点系统HA的前提条件配置
1.时间同步
参考我的博客:http://sohudrgon.blog.51cto.com/3088108/1598314
2.主机名同步
[root@node1 ~]# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
172.16.0.1 server.magelinux.com server
172.16.31.10 node1.stu31.com node1
172.16.31.11 node2.stu31.com node2
3.仲裁设备为网关172.16.0.1
4.ssh无密钥通信
node1
[root@node1 ~]# ssh-keygen -t rsa -P""
[root@node1 ~]# ssh-copy-id -i.ssh/id_rsa.pub root@node2
测试将node1的hosts文件复制到node2:
[root@node1 ~]# scp /etc/hosts root@172.16.31.11:/etc/hosts
hosts 100% 268 0.3KB/s 00:00
node2
[root@node2 ~]# ssh-keygen -t rsa -P""
[root@node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@node1
测试无密钥通信结果:
[root@node1 ~]# date ;ssh node2 'date'
Thu Jan 1 20:44:09 CST 2015
Thu Jan 1 20:44:09 CST 2015
保证时间一致!
五.安装heartbeat程序
1.安装heartbeat程序包组
获取程序包组:
[root@node1 heartbeat2]# ls
heartbeat-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
安装程序包组:
node1和node2都需要安装;
前提条件需要安装如下依赖包:
[root@node1 heartbeat2]# yum install -y net-snmp-libs libnet PyXML
安装heartbeat套件程序:
[root@node1 heartbeat2]# rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm heartbeat-stonith-2.1.4-12.el6.x86_64.rpm heartbeat-pils-2.1.4-12.el6.x86_64.rpm heartbeat-gui-2.1.4-12.el6.x86_64.rpm
Preparing... ########################################### [100%]
1:heartbeat-pils ########################################### [ 25%]
2:heartbeat-stonith ########################################### [ 50%]
3:heartbeat ########################################### [ 75%]
4:heartbeat-gui ########################################### [100%]
2.复制配置文件到/etc/ha.d目录下:
[root@node1 heartbeat2]# cd /usr/share/doc/heartbeat-2.1.4/
[root@node1 heartbeat-2.1.4]# cp ha.cf authkeys haresources /etc/ha.d/
3.配置rsyslog记录heartbeat的日志
[root@node1 ~]# vim /etc/rsyslog.conf
local0.* /var/log/heartbeat.log
拷贝一份到node2:
[root@node1 ~]# scp /etc/rsyslog.conf root@node2:/etc/rsyslog.conf
rsyslog.conf 100%3203 3.1KB/s 00:00
4.配置ha.cf主配置文件:
[root@node1 ~]# cat /etc/ha.d/ha.cf |grep-v ^#
#日志记录
logfacility local0
#组播配置
mcast eth0 225.131.31.23 694 1 0
auto_failback on
#集群节点
node node1.stu31.com
node node2.stu31.com
#仲裁设备
ping 172.16.0.1
#是否开启heartbeat v2 版本的CRM,我们使用v1版本的CRM来测试,注释掉。
#crm on
5.定义域共享密钥,认证文件权限必须是600或者400
[root@node1 ~]# openssl rand -hex 6
72907725aaf0
[root@node1 ~]# vim /etc/ha.d/authkeys
auth 2
2 sha1 72907725aaf0
6.配置集群资源
[root@node1 ~]# vim /etc/ha.d/haresources
node1.stu31.com 172.16.31.180/24/eth0/172.16.31.255 httpd
将三个配置文件复制一份拷贝到node2:
[root@node1 ha.d]# scp -p authkeys ha.cf haresources node2:/etc/ha.d/
authkeys 100% 684 0.7KB/s 00:00
ha.cf 100% 10KB 10.4KB/s 00:00
haresources 100%5964 5.8KB/s 00:00
7.确定httpd服务正常
[root@node2 ~]# echo"node2.stu31.com" > /var/www/html/index.html
[root@node1 ~]# echo"node1.stu31.com" > /var/www/html/index.html
启动httpd服务进行测试
[root@node1 ha.d]# service httpd start
Starting httpd: [ OK ]
[root@node2 ~]# service httpd start
Starting httpd: [ OK ]
访问测试:
[root@node1 ha.d]# curl http://172.16.31.10
node1.stu31.com
[root@node1 ha.d]# curl http://172.16.31.11
node2.stu31.com
完成后将服务自启动关闭,及停止httpd服务:
node1:
[root@node1 ha.d]# service httpd stop
Stopping httpd: [ OK ]
[root@node1 ha.d]# chkconfig httpd off
node2:
[root@node2 ~]# service httpd stop
Stopping httpd: [ OK ]
[root@node2 ~]# chkconfig httpd off
六.启动heartbeat集群
1.启动heartbeat服务:
[root@node1 ha.d]# service heartbeat start; ssh node2 'service heartbeat start'
logd is already running
Starting High-Availability services:
2015/01/01_21:10:33 INFO: Resource is stopped
Done.
logd is already running
Starting High-Availability services:
2015/01/01_21:10:33 INFO: Resource is stopped
Done.
2.访问测试:
[root@nfs ~]# curl http://172.16.31.180
node1.stu31.com
我们关闭node1,在进行测试:
[root@node1 ha.d]# service heartbeat stop
Stopping High-Availability services:
Done.
ip地址切换到了node2:
[root@node2 ~]# ip addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu65536 qdisc noqueue state UNKNOWN
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP>mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 08:00:27:58:d3:3e brd ff:ff:ff:ff:ff:ff
inet 172.16.31.11/16 brd 172.16.255.255 scope global eth0
inet 172.16.31.180/24 brd 172.16.31.255 scope global eth0:0
inet6 fe80::a00:27ff:fe58:d33e/64 scope link
valid_lft forever preferred_lft forever
访问测试:
[root@nfs ~]# curl http://172.16.31.180
node2.stu31.com
测试成功!
本文出自 “眼眸刻着你的微笑” 博客,请务必保留此出处http://dengaosky.blog.51cto.com/9215128/1964550