corosync
OpenAIS:Open Application Interface Standard 开放的应用程序接口标准
corosync 属于OpenAIS中的一类底层心跳层实现高可用集群的工具,功能与我们前面讲到的heartbeat相同
corosync版本
1.0版本:不具备投票能力;通过corosync+cman做底层心跳层实现高可用HA,cman作为corosync的插件存在,提供投票能力
2.0版本: 具备投票能力;corosync单独实现底层心跳层的功能
高可用解决方案
# packmaker 资源管理器# corosync 底层心跳层
高可用解决方案实现
架构图
#node3 172.16.13.3#node4 172.16.13.4#clinet 172.16.250.223
资源规划
VIP 172.16.13.10httpd
软件程序
corosync-1.4.1-17pacemaker-1.1.10-14crmsh-1.2.6-4pssh-2.3.1-2#1.1版本的pacemaker作为1.4.1版本corosync的插件运行#1.2.6版本的crmsh单独程序安装,并非由pacemaker安装而安装#2.3.1版本的pssh 属于crmsh安装所依赖的软件包总结:corosync 做心跳信息层 pacemaker以插件的形式作为资源管理器 crmsh 作为资源配置接口
配置过程
1 配置双节点时间同步、本地主机无需DNS可以解析主机、交换ssh密钥实现无密钥通信#以上必备步骤此处不再累述,详情请参照我的博客http://jungege.blog.51cto.com/4102814/1399829
2 各个节点安装 corosync、pacemaker、crmsh、pssh# yum -y install corosync# yum -y install pacemaker# yum -y install crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm
3 node3上编辑corosync配置文件# 提供配置文件# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf# 编辑配置文件# vim /etc/corosync/corosync.conf
以上参数分析 totem:图腾,是corosync协议;存在版本号 # version: 2 版本号2 # secauth: on 安全机制,防止组播等 # threads:0 启动的线程 # interface # ringnumber 网卡环号,防止网卡回路; # bindnetaddr 绑定的网络地址 # mcastaddr 组播地址224.0.1.0 ~ 238.255.255.255 用户可用组播地址(临时组播地址,全网有效) # mcastport 组播端口 logging:日志 # fileline: off # to_stderr: no # to_logfile: yes # to_syslog:no # logfile: /var/log/cluster/corosync.log 该目录可能不存在,需要创建 # debug : off # timestamp : off 时间戳
#编辑配置文件添加如下内容,实现pacemaker作为corosync的插件运行#vim /etc/corosync/corosync.conf
4 提供authkeys 保证节点间通信安全#corosync-keygen 生成authkeys基于HAMC单项加密算法#chmod authkey 400 设置authkeys权限为400或者600#scp -p authkey corosync.conf node4:/etc/corosync/ 拷贝authkeys和corosync.conf配置文件到node2节点上 注意#(一)corosync.conf 中的bindip绑定的网络 与 mcust组播地址 实现各个节点在心跳信息层的心跳信息与事务信息的侦听联系#(二)authkys 保证各个节点在心跳信息层传输信息和事务的安全
5 各个节点启动corosync服务# service corosync start
6 设置集群资源属性 node3上配置# crm 进入crm shell# crm(live)# configure 进入二级目录 配置目录# crm(live)configure# property stonith-enabled=false 不使用stonith设备,我们没有stonith设备即无资源隔离设备# crm(live)configure# property no-quorum-policy=ignore 忽略法定票数策略,两个节点高可用中,一个节点挂掉另一个节点依然可用# crm(live)configure# default-resource-stickiness=100 设置资源的默认粘性# crm(live)configure# verify 检测语法是否错误,没有返回信息则无错误# crm(live)configure# commit 提交任务
7 定义主资源 VIP httpd node3上配置# crm# crm(live)# configure# crm(live)configure# primitive webserver lsb:httpd ----配置一个主资源名称为webservier ,lsb为资源代理类别 httpd为资源代理 无其他参数# crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=172.16.13.10 op monitor interval=30s timeout=20s on-fail=restart 配置一个主资源名称为webip,资源代理类别为ocf:heartbeat 资源代理为IPaddr参数params ,后续的所有参数以此为VIP地址172.16.13.10,op代表动作 monitor设置一个监控 每30s检测一次,超时时间为20s,一旦故障就重启# crm(live)configure# verify# crm(live)configure# commit
8 定义组资源,即将刚刚创建的两个资源webip,webserver添加到组,实现资源绑定 node3上配置# crm# crm(live)# configure# crm(live)configure# group webservice webip webserver --组名为webservice,组中的资源为webip,webserver。# crm(live)configure# verify# crm(live)configure# commit
9 查看节点及资源状态# crm status
10 node3 node4提供web页面 # node3 # vim /var/www/html/index.htmlnode3.linux.com
# node4 # vim /var/www/html/index.htmlnode4.linux.com
客户端测试
将node4设为备用 node3上线# crm# crm(live)# node# crm(live)node# standby node4.linux.com# crm(live)node# online node3.linux.com
客户端测试
高可用集群设置成功
# 总结:通过使用corosync心跳信息工具+pacemaker资源管理器+crmsh资源配置接口实现高可用集群,请注意各个程序包的版本;
PS:水平有限,如有疑问请指出!