以下操作基于rhel6.5
本次实验保证其他负载均衡和高可用软件全部关掉!
server1和server4上安装Haproxy:
server1:
安装见上篇博文:
scp haproxy-1.6.11-1.x86_64.rpm 172.25.50.4:/root
scp /etc/haproxy/haproxy.cfg 172.25.50。4:/etc/haproxy
scp /etc/security/limits.conf 172.25.50.4:/etc/security
vim /etc/haproxy/haproxy.cfg
37 bind 172.25.50.100:80 name clear #设置只有访问172.25.50.100才能访问集群资源
/etc/init.d/haproxy start
测试:打开后端服务器server2和server3:
server1和server4:curl 172.25.50.100
可以看到server3的之前搭建的php页面。
server1和server4安装pacemaker和corosync:
【其中corosync在之前RHCS套件那篇博文时已经安装,因为RHCS套件的高可用也是利用corosync实现心跳检测。】
server1:
yum install -y pacemaker corosync
/etc/init.d/corosync start
[[email protected] ~]# cd /etc/corosync/
[[email protected] corosync]# cp corosync.conf.example corosync.conf
[[email protected] corosync]# vim corosync.conf
10 bindnetaddr: 172.25.50.0
11 mcastaddr: 226.94.1.50
12 mcastport: 5405
34 service{
35 name:pacemaker
36 ver:0
37 }
[[email protected] corosync]# scp corosync.conf 172.25.50.4:/etc/corosync/
[[email protected] corosync]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
[[email protected] corosync]# tail -f /var/log/messages
#如果日志中有很多error,可能是因为多播地址或者端口冲突
#健康检查:
[[email protected] ~]# crm_verify -LV 发现没有fence设备报错
#安装crm管理工具:
[[email protected] ~]# yum install crmsh-1.2.6-0.rc2.2.1.x86_64.rpm pssh-2.3.1-2.1.x86_64.rpm
#配置禁掉fence功能
在主机上:/etc/fence_virtd stop
[[email protected] ~]# crm
crm(live)# configure
crm(live)configure# property stonith-enabled=false
[[email protected] ~]# crm_verify -LV #不报错
#关闭集群对节点数量的检查,集群默认最少量台主机,如果只是一台主机不能接管资源
crm(live)configure# property no-quorum-policy=ignore
crm(live)configure# commit
#添加资源,vip
crm(live)configure# primitive vip ocf:heartbeat:IPaddr2 params ip=172.25.50.100 cidr_netmask=24 op monitor interval=20s#添加vip并设置20s对资源监察一次,监控端可以发现vip资源添加上
crm(live)configure# commit
测试:在主机上访问:curl 172.25.50.100
可以看见server3上的html页面。关掉其中一台corosnsc,vip会上到另一台主机上。
#添加资源haproxy:
crm(live)configure# primitive haproxy lsb:haproxy op monitor interval=30s
crm(live)configure# commit
#添加haproxy后可以看出来vip和haproxy不再一台主机上,资源飘移:
#解决办法:建立资源组就可以解决
crm(live)configure# group westos vip haproxy
crm(live)configure# commit
#添加资源fence:
添加fence之前首先开启主机上:systemctl start fence_virtd
yum install -y fence-virt.x86_64 fence-agents.x86_64 #两台主机上都做(server1和server4) ``!!!!! ``
crm(live)configure# property stonith-enabled=true #开启fence功能
crm(live)configure# commit
[[email protected] ~]# stonith_admin -I #查看主机支持fence的代理类型。本次使用fence_xvm
[[email protected] ~]# stonith_admin -M -a fence_xvm
crm(live)configure# primitive vmfence stonith:fence_xvm params pcmk_host_map="server1:server1;server4:server4" op monitor interval=1min
#添加fence资源,并做好集群节点名和真实server的名字映射
#测试fence功能:
首先设置:corsync在两台主机上可其自启动:chkconfig corosync on
reboot(重启动)其中一台主机,等主机开启后会自动加到集群中!
#对集群资源的管理:
crm(live)resource# show #显示资源种类,此处时只添加了一个资源vip,所以显示一个
vip (ocf::heartbeat:IPaddr2): Started #开启vip资源
crm(live)resource# stop vip
crm(live)resource# show
vip (ocf::heartbeat:IPaddr2): Stopped #停掉vip资源
#对集群节点的管理:
[[email protected] ~]# crm
crm(live)# node
crm(live)node# standby #停掉server1节点
crm(live)node# online #开启server1节点
server4:和server1是同步的,但此处作为监控
yum install -y pacemaker corosync
/etc/init.d/corosync start
#安装管理工具:
[[email protected] ~]# yum install pssh-2.3.1-2.1.x86_64.rpm crmsh-1.2.6-0.rc2.2.1.x86_64.rpm
#监控集群:
[[email protected] ~]# crm_mon
END