您的位置:首页 > 其它

corosync+pacemaker构建HAweb集群-----pcs资源管理器

2013-11-12 15:14 267 查看
1.实验环境
系统环境:centos6.4-i386
两个节点:172.16.15.8主机名:stu_yxm8.mageduyxm8(别名)
172.16.15.9主机名:stu_yxm9.mageduyxm9(别名)保证主机名称和对应的IP地址解析服务可以正常工作:(yxm8、yxm9)vim/etc/hosts172.16.15.8stu_yxm8.mageduyxm8172.16.15.9stu_yxm9.mageduyxm9建立双机互信:
yxm8:
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub root@yxm9
yxm9:
# ssh-keygen -t rsa
# ssh-copy-id -i ~/.ssh/id_rsa.pub yxm8@node1
2.安装软件包、配置实验环境
yxm8、yxm9上均执行
安装corosync pacemaker pcs
yum -y install corosync pacemaker pcs
# cd /etc/corosync
# cp corosync.conf.example corosync.conf
编辑corosync.conf文件,添加如下内容:在yxm8上执行
service {
ver:  0
name: pacemaker
# use_mgmtd: yes
}
aisexec {
user: root
group:  root
}
注意修改组播地址,强烈建议不要使用默认的组播地址。设定网络地址:bindnetaddr:172.16.0.0生成节点间通信用到的密匙文件:
#corosync-keygen (此处可以选择安装软件生成大量随机数)
将corosync和authkey复制至yxm9:
# scp -p corosync authkey  yxm9:/etc/corosync/
分别为两个节点创建corosync生成的日志文件所在目录:
# mkdir /var/log/cluster
# ssh yxm9  'mkdir /var/log/cluster'
启动corosync服务:#servicecorosynstart查看端口54045405是否已经开始监听#ss-uanlp启动yxm9上的corosync服务#sshyxm9servicecorosyncstart查看集群节点状态
#pcs status
Last updated: Sat Oct 26 21:21:47 2013
Last change: Sat Oct 26 14:37:04 2013 via cibadmin on stu_yxm8.magedu
Stack: classic openais (with plugin)
Current DC: stu_yxm9.magedu - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
0 Resources configured.
Online: [ stu_yxm8.magedu stu_yxm9.magedu ]
Full list of resources:
3.使用pcs资源管理器配置集群属性禁用stonith:corosync默认启用了stonith,而当前集群并没有相应的stonith设备,因此此默认配置目前尚不可用,因此需要使用如下命令禁用stonith
# pcs property set stonith-enabled=false
查看配信息
#pcs config
...... ...... ......
Cluster Properties:
dc-version: 1.1.8-7.el6-394e906
cluster-infrastructure: classic openais (with plugin)
expected-quorum-votes: 2
stonith-enabled: false
...... ...... ......
4.为集群添加资源corosync支持heartbeat,LSB和ocf等类型的资源代理,目前较为常用的类型为LSB和OCF两类,stonith类专为配置stonith设备而用;可以通过如下命令查看当前集群系统所支持的类型:
# pcs resource standards
ocf
lsb
service
stonith
查看资源代理的provider:
# pcs resource providers
heartbeat
pacemaker
redhat
为集群配置一个IP(VIP)地址,用于实现提供高可用的web服务:
# pcs resource create WebIP ocf:heartbeat:IPaddr ip=172.16.15.188 cidr_netmask=16(掩码) op monitor interval=30s
查看资源是否已经启用:
[root@stu_yxm8 ~]# pcs status
Last updated: Sat Oct 26 21:53:31 2013
Last change: Sat Oct 26 21:28:58 2013 via cibadmin on stu_yxm8.magedu
Stack: classic openais (with plugin)
Current DC: stu_yxm9.magedu - partition with quorum
Version: 1.1.8-7.el6-394e906
2 Nodes configured, 2 expected votes
2 Resources configured.
Online: [ stu_yxm8.magedu stu_yxm9.magedu ]
Full list of resources:
webip  (ocf::heartbeat:IPaddr):    Started stu_yxm8.magedu
注意:此处同样可以执行ifconfig命令查看此地址是否已经在eth0的别名上生效。通过如下的命令来修改忽略quorum(法定票数)不能满足的集群状态检查:
# pcs property set no-quorum-policy="ignore"
可以通过以下方式为资源指定默认黏性值:(防止其他节点重启后,资源被抢夺而在此段时间内服务中断)
# pcs resource rsc defaults resource-stickiness=100
5.配置web集群已经配置好的IP地址资源,将此集群配置成为一个active/passive模型的web(httpd)服务集群。首先在各节点启动httpd服务,正常访问后,停掉服务,使其开机不能自动启动:
#service httpd stop
#chkconfig httpd off
将httpd服务添加为集群资源:将httpd添加为集群资源有两处资源代理可用:lsb和ocf:heartbeat,在此使用lsb类型:
# pcs resource create webserver lsb:httpd
查看配置文件中生成的定义:
#pcs config
查看资源启动状态:
#pcs status
测试web服务:

6.资源约束资源约束:pacemaker提供了三种资源约束方法:<1>ResourceLocation(资源位置):定义资源可以、不可以或尽可能在哪些节点上运行;<2>ResourceCollocation(资源排列):排列约束用以定义集群资源可以或不可以在某个节点上同时运行;<3>ResourceOrder(资源顺序):顺序约束定义集群资源在节点上启动的顺序;排列约束对于两个资源webip、webserver运行于不同节点的问题,可以通过以下命令来解决:
# pcs constraint colocation add webserver webip INFINITY(无穷大)
查看状态信息,观察两个节点是否已经运行在同一个节点之上。顺序约束要确保webserver在某节点启动之前得先启动webip可以使用如下命令实现:
# pcs constraint order webip then webserver
查看定义结果:
#pcs constraint order
Ordering Constraints:
start webip then start webserver

位置约束:由于HA集群本身并不强制每个节点的性能相同或相近,因此若希望服务总能在某个性能较强的节点上运行,这可以通过位置约束来实现:eg:如果期望webserver倾向运行于stu_yxm8.magedu的分数为500,则可以使用类似如下命令实现:
语法:location add <id> <resource name> <node> <score>
# pcs constraint location add webserver_on_node1 webserver stu_yxm8.magedu 500
7.查看最终配置
[root@stu_yxm8 ~]# pcs config
Corosync Nodes:
Pacemaker Nodes:
stu_yxm8.magedu stu_yxm9.magedu
Resources:
Resource: webip (provider=heartbeat type=IPaddr class=ocf)
Attributes: ip=172.16.15.188 clidr_netmask=16
Operations: monitor interval=30s
Resource: webserver (type=httpd class=lsb)
Location Constraints:
Resource: webserver
Enabled on: stu_yxm8.magedu (score:500)
Ordering Constraints:
start webip then start webserver
Colocation Constraints:
webserver with webip
Cluster Properties:
dc-version: 1.1.8-7.el6-394e906
cluster-infrastructure: classic openais (with plugin)
expected-quorum-votes: 2
stonith-enabled: false
no-quorum-policy: ignore
停掉yxm8上的corosync服务

测试web服务

重新启动yxm8上的corosync服务



本文出自 “云端俯瞰” 博客,请务必保留此出处http://dreamwolf.blog.51cto.com/6365503/1323869
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: