首页 > 代码库 > heartbeat(v1)高可用web集群
heartbeat(v1)高可用web集群
实验环境:centos6.6;
172.16.249.98 node1.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,本地测试完成;
关闭服务,并确保开机不会自动启动;
配置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.pub root@node2 node2:#ssh-keygen -t rsa -P"" # ssh-copy-id -i.ssh/id_rsa.pub root@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... ########################################### [100%] 1:heartbeat-pils ########################################### [ 33%] 2:heartbeat-stonith ########################################### [ 67%] 3:heartbeat ########################################### [100%]
(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 694 1 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 1 sha1 5ab5572e873e #可以使用`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 <h1> node1.stu7.com </h1> #service httpd start #curl #测试httpd服务是否正常 node1.stu7.com #service httpd stop #chkconfig httpd off #设置其开机不能自动启动 node2:#vim /var/www/html/index.html <h1> node2.stu7.com </h1> #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:
修改服务器的主从关系:
# cd /usr/lib64/heartbeat/
#./hb_standby(修改为从) #./hb-takeover(修改成主)
在node1上执行#./hb_standby;打开浏览器:172.16.249.212:
本文出自 “小二哥Linux” 博客,请务必保留此出处http://9612520.blog.51cto.com/9602520/1601638
heartbeat(v1)高可用web集群