您的位置:首页 > 运维架构 > 网站架构

corosync+pacemaker实现高可用(HA)集群(二)

2014-04-22 07:29 477 查看
部署方案二(推荐):corosync+pacemaker
利用ansible自动安装corosync和pacemaker注:关于ansible的具体使用可参见“ansible实现自动化自动化运维安装ansible(使用最新版的rpm包安装)
yum --nogpgcheck localinstall ansible-1.5.4-1.el6.noarch.rpm
配置ansible的主机列表
vi /etc/ansible/hosts
[hanodes]
node1.lamp.com
node2.lamp.com
在ansible控制端准备安装所需的文件
mkdir -pv /root/autoinstall_corosync/conf
# 内含文件有:
authkeys # corosync所需的密钥文件,可通过corosync-keygen命令生成
corosync.conf # corosync的主配置文件
# corosync.conf配置文件
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 172.16.0.0 # 配置主机网卡所在的网路地址
mcastaddr: 226.0.25.10 # 配置多播地址,防止心跳信息在局域网内混乱传播
mcastport: 5405 # 配置多播地址
ttl: 1
}
}
logging {  # 日志相关的配置
fileline: off
to_stderr: no
to_logfile: yes # logfile和syslog方式二选一即可
to_syslog: no
logfile: /var/log/cluster/corosync.log
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service { # 定义一个服务,用以加载pacemaker插件
ver: 0
name: pacemaker
}
aisexec { # 定义corosync的工作用户
user: root
group: root
}
mkdir -pv /root/autoinstall_corosync/packages
# 内含程序包有:
crmsh-1.2.6-4.el6.x86_64.rpm:crmsh配置接口的程序包
pssh-2.3.1-2.el6.x86_64.rpm:并发ssh程序包,crmsh安装所依赖的包
配置corosync安装剧本(corosync.yaml)
vi /root/autoinstall_corosync/corosync.yaml
- hosts: hanodes
remote_user: root
vars:
crmsh: crmsh-1.2.6-4.el6.x86_64.rpm
pssh: pssh-2.3.1-2.el6.x86_64.rpm
tasks:
- name: corosync installing
yum: name=corosync state=present
- name: pacemaker installing
yum: name=pacemaker state=present
- name: pcs installing
yum: name=pcs state=present
- name: crmsh rpm packages
copy: src=/root/autoinstall_corosync/packages/` crmsh ` dest=/tmp/` crmsh `
- name: pssh rpm packages
copy: src=/root/autoinstall_corosync/packages/` pssh ` dest=/tmp/` pssh `
- name: crmsh installing
command: yum -y reinstall /tmp/` crmsh ` /tmp/` pssh `
- name: authkey configure file
copy: src=/root/autoinstall_corosync/conf/authkey dest=/etc/corosync/authkey
- name: authkey mode 400
file: path=/etc/corosync/authkey mode=400
notify:
- restart corosync
- name: corosync.conf configure file
copy: src=/root/autoinstall_corosync/conf/corosync.conf dest=/etc/corosync/corosync.conf
tags:
- conf
notify:
- restart corosync
- name: ensure the corosync service startup on boot
service: name=corosync state=started enabled=yes
handlers:
- name: restart corosync
service: name=corosync state=restarted
执行一键安装
ansible-playbook corosync.yaml

crmsh配置接口
crm # 进入crm命令行配置接口
configure # 进入configure模式
property stonith-enabled=false # 因为在实验环境中无stonith设备
property no-quorum-policy=ignore # 在实验的双节点环境中,配置no-quorum-policy为ignore可避免手动测试某节点下线导致整个集群不可用
rsc_defaults resource-stickiness=100 # 设置默认资源黏性值为100
verify # 验证配置是否正确
commit # 提交配置
primitive webip ocf:heartbeat:IPaddr params ip=172.16.25.51 op monitor interval=30s timeout=20s on-fail=restart # 创建资源webip,使用的RA是IPaddr,同时定义监控,检测失败则重启资源
primitive webstore ocf:heartbeat:Filesystem params device="172.16.251.163:/www/phpwind.com" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart # 创建资源webstore,使用的RA是Filesystem
primitive webserver lsb:httpd op monitor interval=30s timeout=40s on-fail=restart # 创建资源webserver,使用的RA是httpd
verify
commit
show # 显示配置结果
show xml # 以xml文件格式显示详细配置信息
edit # 可直接编辑配置文件,修改内容
group webservice webip webstore  webserver # 配置资源组webservice
verify
commit
order webip_before_webstore_before_webserver infinity: webip webstore webserver # 定义顺序约束,定义在前面的先确保运行
location webip_prefer_node1 webip inf: node1.lamp.com # 定义位置约束,使得webservice更倾向于运行于node1.lamp.com节点上
# 其它操作
ra # 切换至ra模式
list ocf heartbeat # 查看某类别(ocf heartbeat)下的所有资源代理RA
meta ocf:heartbeat:Filesystem # 查看某一具体资源代理RA的可用属性,查找哪些是必须属性
configure # 切换至configure模式
colocation webip_with_webstore_with_webserver inf: webserver webstore webip # 定义排列约束,即各资源都运行在同一个主机上的倾向,这与定义资源组效果相同;定义在最后的资源所在的主机决定排列约束内全部资源所运行的主机
monitor webserver 20s:40s # 单独定义监控资源webserver,间隔时间为20s,超时时间为40s
resource # 进入resource模式
cleanup webservice # 清理资源运行过程中的错误状态信息
stop webip # 停止资源
crm status # 显示集群状态信息
crm configure show # 显示集群配置信息
crm node standby node1.lamp.com # 手动将node1由主节点配置为从节点,使资源转移发生
crm node online node1.lamp.com # 手动使node1重新上线

pcs配置接口
# 注:配置后即刻生效,无需手动commit提交
pcs property set stonith-enabled=false # 设置参数属性
pcs property set no-quorum-policy=ignore
pcs property set default-resource-stickiness=100
pcs resurce create webip ocf:heartbeat:IPaddr ip=172.16.25.51 op monitor interval=30s timeout=20s# 创建资源webip
pcs resource create webstore ocf:heartbeat:Filesystem device="172.16.251.163:/www/phpwind.com" directory="/var/www/html" fstype="nfs" op monitor interval=20s timeout=40s op start timeout=60s op stop timeout=60s on-fail=restart # 创建资源webstore
pcs resource create webserver lsb:httpd op monitor interval=30s timeout=20s on-fail=restart # 创建资源webserver
pcs resource group add webservice webip webstore  webserver # 配置资源组webservice
pcs constraint order webip then webstore # 定义顺序约束,只能定义两两的顺序关系
pcs constraint order webstore then webserver
pcs constraint location webservice prefers node1.lamp.com=500 # 定义位置约束
pcs status # 查看集群状态
# 其它操作:
pcs resource list ocf:heartbeat # 查看某类别(ocf heartbeat)下的所有资源代理RA
pcs resource describe ocf:heartbeat:Filesystem # 查看某一具体资源代理RA的可用属性,查找哪些是必须属性
pcs resource group remove webservice webserver # 删除资源组webservice中的webserver资源
pcs resource ungroup webservice # 只删除资源组webservice,并不删除组内的资源
pcs constraint show # 显示全部约束规则
pcs constraint order show # 显示指定(如order)的约束规则
pcs constraint colocation add webstore with webip # 定义排列约束,与资源组效果相同,二者选其一即可
pcs constraint order set webip webstore webserver # 定义顺序约束,可一次指定多个资源
pcs config # 查看当前集群的配置

上一篇:corosync+pacemaker实现高可用(HA)集群(一)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息