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

简介:

部署方案二(推荐):corosync+pacemaker


利用ansible自动安装corosync和pacemaker

注:关于ansible的具体使用可参见“ansible实现自动化自动化运维

安装ansible(使用最新版的rpm包安装)

1
yum --nogpgcheck localinstall ansible-1.5.4-1.el6.noarch.rpm

配置ansible的主机列表

1
2
3
4
vi  /etc/ansible/hosts
[hanodes]
node1.lamp.com
node2.lamp.com

在ansible控制端准备安装所需的文件

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
31
32
33
34
35
36
37
38
39
40
41
42
43
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
}
1
2
3
4
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)

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
31
32
33
34
35
36
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

执行一键安装

1
ansible-playbook corosync.yaml


crmsh配置接口

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
31
32
33
34
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配置接口

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 注:配置后即刻生效,无需手动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  # 查看当前集群的配置










本文转自 xxrenzhe11 51CTO博客,原文链接:http://blog.51cto.com/xxrenzhe/1400025,如需转载请自行联系原作者
目录
相关文章
|
安全 数据安全/隐私保护
【密码学】一文读懂线性反馈移位寄存器
在正式介绍线性反馈移位寄存器(LFSR)之前,先来看一个小故事,相传在遥远的古代,住着4个奇怪的人。
2088 0
【密码学】一文读懂线性反馈移位寄存器
|
8月前
|
监控 安全 Ubuntu
从零开始学安全:服务器被入侵后的自救指南
在信息爆炸时代,服务器安全至关重要。本文针对黑客入侵问题,从应急处理、系统恢复到安全加固全面解析。发现入侵时应冷静隔离服务器,保存日志证据,深入排查痕迹;随后通过重装系统、恢复数据、更改密码完成清理;最后加强防火墙、更新软件、部署检测系统等措施防止二次入侵。服务器安全是一场持久战,需时刻警惕、不断优化防护策略。
1227 1
|
Linux 开发工具
Linux yum 使用时提示 获取 GPG 密钥失败Couldn‘t open file RPM-GPG-KEY-EPEL-7
获取 GPG 密钥失败:[Errno 14] curl#37 - “Couldn’t open file /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7” 这个就是安装的时候会检查key这个可以再repo文件中关闭即可
2980 0
|
机器学习/深度学习 Rust 算法
Python环境管理的新选择:UV和Pixi,高性能Python环境管理方案
近期Python生态系统在包管理领域发生了重要变化,Anaconda调整商业许可证政策,促使社区寻找更开放的解决方案。本文介绍两款新一代Python包管理工具:UV和Pixi。UV用Rust编写,提供高性能依赖解析和项目级环境管理;Pixi基于Conda生态系统,支持conda-forge和PyPI包管理。两者分别适用于高性能需求和深度学习项目,为开发者提供了更多选择。
2878 2
|
监控 Ubuntu Linux
在Linux中,如何使用Pacemaker和Corosync?
在Linux中,如何使用Pacemaker和Corosync?
|
网络协议 Linux 虚拟化
VMware安装Linux虚拟机之桥接模式网络配置图文详解(2)
VMware安装Linux虚拟机之桥接模式网络配置图文详解(2)
675 0
|
存储 Shell Linux
Pacemaker+corosync搭建双节点HA集群的可靠性验证
前一篇>中为确保共享资源的不被破坏,配置了3节点集群,本文想验证一下双节点时有什么风险。 Pacemaker的手册上也有描述,Pacemaker支持法定投票和资源抢占2种方式防止脑裂。
2290 0