heartbeat(v1)版、(v2)版高可用web集群
实验环境:centos6.6;
172.16.249.98node1.stu7.com
172.16.249.100 node2.stu7.com
配置HA集群前提:
1、时间必须同步;
建议使用ntp协议进行;
2、节点之间必须要通过主机名互相通信;
建议使用hosts文件;
通信中使用的名字必须与其节点为上“uname -n”命令展示出的名字保持一致;
3、需要仲裁设备;
4、彼此root用户能基于ssh密钥方式进行通信;
注意:定义为集群服务中的任意资源都不能开机自动启动,因为它们将由CRM启动;
资源准备:
1、选定vip;
2、httpd:
安装好程序;
配置好httpd,本地测试完成;
关闭服务,并确保开机不会自动启动;
heartbeat(v1):
配置HA集群前提:
1、时间同步:
node1:# ntpdate 172.16.0.1
# crontab -e
*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &>/dev/null
node2:# ntpdate 172.16.0.1
# crontab -e
*/3 * * * * /usr/sbin/ntpdate 172.16.0.1 &>/dev/null 2、节点无密钥通信:
node1:#ssh-keygen -t rsa -P" "
#ssh-copy-id -i.ssh/id_rsa.pubroot@node2
node2:#ssh-keygen -t rsa -P""
# ssh-copy-id -i.ssh/id_rsa.pubroot@node1 测试于无密钥通信:
#ssh node2 ‘date’; date
Sat Jan 10 13:43:52 CST 2015
Sat Jan 10 13:43:52 CST 2015 3、节点通过主机名互相通信:
node1:#vim /etc/hosts
172.16.249.98 node1.stu7.com node1
172.16.249.100 node2.stu7.com node2
#scp /etc/hosts node2:/etc/hosts
#uname -n #确保node1节点主机名一致
node2:#cat /etc/hosts #确保文件修改成功
#uname -n #确保node2主机名一致 4、仲裁设备:(网关)172.16.0.1
安装、配置heartbeat:
(1)获取heartbeat的安装包组:
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 (2)解决依赖关系:
node1:#yum install net-snmp-libs libnet PyXML
node2:#yum install net-snmp-libs libnet PyXML
(3)安装:(node1、node2节点执行相同的安装)
#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
Preparing... ###########################################
1:heartbeat-pils ########################################### [ 33%]
2:heartbeat-stonith ########################################### [ 67%]
3:heartbeat ########################################### (4)编辑配置文件:
#cd /usr/share/doc/hearbeat-2.1.4/
#cp -p authkeys haresources ha.cf /etc/ha.d/
#cd /etc/ha.d
#chmod 600 authkeys #需要修改authkeys的权限;权限必须为600或者400
#vim ha.cf
1)#日志记录:
logfile /var/log/ha-log
# logfacility local0
2)#组播配置:
mcast eth0 228.203.101.1 6941 0
3)auto_failback on
4)#仲裁设备:
ping 172.16.0.1
5)#集群节点:
node node1.stu7.com
node node2.stu7.com
6) #bzipy压缩
compression bz2
compression_threshold 2
#vim authkeys
auth 1
1sha15ab5572e873e #可以使用`openssl rand -hex 6`生成随机数
#vim haresources;
# 配置集群资源
node1.node1stu7.com 172.16.249.212/16/eth0/172.16.255.255 httpd#vip为172.16.249.212
#把修改好的配置文件复制到node2节点一份
#scp -p authkeys haresources ha.cf node2:/etc/ha.d/ 资源准备:
1、vip:172.16.249.212
2、httpd:
node1:#vim /var/www/html/index.html
node1.stu7.com
#service httpd start
#curl #测试httpd服务是否正常
node1.stu7.com
#service httpd stop
#chkconfig httpd off #设置其开机不能自动启动
node2:#vim /var/www/html/index.html
node2.stu7.com
#service httpd start
#curl http://172.16.249.100 #测试httpd服务是否正常
node2.stu7.com
#service httpd stop
#chkconfig httpd off #设置其开机不能自动启动 启用heartbeat服务
#service heartbeat start;ssh node2 ‘service heartbeat start’
logd is already running
Starting High-Availability services:
Done.
Starting High-Availability services:
Done. 打开浏览器:172.16.249.212:
http://s3.运维网.com/wyfs02/M01/58/71/wKioL1Swyu-At9GwAABm-WVwdVk072.jpg
修改服务器的主从关系:
# cd /usr/lib64/heartbeat/
#./hb_standby(修改为从)#./hb-takeover(修改成主)
在node1上执行#./hb_standby;打开浏览器:172.16.249.212:
http://s3.运维网.com/wyfs02/M01/58/75/wKiom1SwymrQ08t0AABnp8euLVI165.jpg
测试正常,搭建完毕!
heartbeat(v2):基于heartbeart (v1)上:
(1):安装
node1:#rpm -ivh heartbeat-gui-2.1.4-12.e16.x86_64.rpm
node2:#rpm -ivh heartbeat-gui-2.1.4-12.e16.x86_64.rpm (2)在配置文件ha.cf中添加crm on;
说明:启用内置的v2版,haresources文件失效.
(3)会自动添加一个hacluster用户为用户设置密码;
#echo admin|passwd --stdin hacluster
(4)启动heartbeat服务
#service heartbeat start;ssh node2 ‘service heartbeat start’
(5)启动图形化界面
#hb_gui &
1.登陆界面
http://s3.运维网.com/wyfs02/M02/58/76/wKiom1SxIxPx8T2aAAFte62j9Hk849.jpg
http://s3.运维网.com/wyfs02/M00/58/73/wKioL1SxJCSCR965AAHJrVOdWw4196.jpg
2.定义资源组:
http://s3.运维网.com/wyfs02/M00/58/76/wKiom1SxI7agQHeyAAI56C4gsEQ150.jpg
3.定义组中资源:
http://s3.运维网.com/wyfs02/M01/58/73/wKioL1SxJMrwfmKSAAKyZBfsz-I017.jpg
http://s3.运维网.com/wyfs02/M02/58/73/wKioL1SxJRnTf3P_AAKlef6IJl8752.jpg
4.定义资源顺序约束:
http://s3.运维网.com/wyfs02/M02/58/76/wKiom1SxJJbCDZEHAANCLo9Be5M556.jpg
5.启动资源组:
http://s3.运维网.com/wyfs02/M00/58/76/wKiom1SxJNCiTOoLAALuj8endss136.jpg
http://s3.运维网.com/wyfs02/M00/58/76/wKiom1SxJP7j7vwWAAKrExmEGdE487.jpg
打开浏览器测试:172.16.249.212:
http://s3.运维网.com/wyfs02/M01/58/76/wKiom1SxJVrTxB4uAABqJj0Na2M354.jpg
修改node2节点为从:
http://s3.运维网.com/wyfs02/M02/58/73/wKioL1SxJjvQrTBJAAKPPzRvJxA881.jpg
打开浏览器:172.16.249.212:
http://s3.运维网.com/wyfs02/M02/58/76/wKiom1SxJZ2x-b1yAABonWKVGDQ787.jpg
测试结果正常,搭建完毕!
页:
[1]