wewe22 发表于 2015-1-12 09:41:57

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、时间同步:


1
2
3
4
5
6
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、节点无密钥通信:

1
2
3
4
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




测试于无密钥通信:

1
2
3
#ssh node2 ‘date’; date
Sat Jan 10 13:43:52 CST 2015
Sat Jan 10 13:43:52 CST 2015




3、节点通过主机名互相通信:

1
2
3
4
5
6
7
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的安装包组:

1
2
3
4
5
6
7
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)解决依赖关系:

1
2
node1:#yum install net-snmp-libs libnet PyXML
node2:#yum install net-snmp-libs libnet PyXML





(3)安装:(node1、node2节点执行相同的安装)


1
2
3
4
5
#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)编辑配置文件:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#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:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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服务

1
2
3
4
5
6
7
#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:

测试正常,搭建完毕!


heartbeat(v2):基于heartbeart (v1)上:
(1):安装


1
2
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.登陆界面




2.定义资源组:

3.定义组中资源:


4.定义资源顺序约束:

5.启动资源组:


打开浏览器测试:172.16.249.212:


修改node2节点为从:

打开浏览器:172.16.249.212:


测试结果正常,搭建完毕!



页: [1]
查看完整版本: heartbeat(v1)版、(v2)版高可用web集群