一、基础知识
1 简介
Corosync是OpenAIS发展到Wilson版本后衍生出来的开放性集群引擎工程。可以说Corosync是OpenAIS工程的一部分。
2 Corosync执行高可用应用程序的通信组系统它有以下特征
2.1 一个封闭的程序组A closed process group communication model通信模式这个模式提供一种虚拟的同步方式来保证能够复制服务器的状态。
2.2 一个简单可用性管理组件A simple availability manager这个管理组件可以重新启动应用程序的进程当它失败后。
2.3 一个配置和内存数据的统计A configuration and statistics in-memory database内存数据能够被设置回复接受通知的更改信息。
2.4 一个定额的系统A quorum system,定额完成或者丢失时通知应用程序。
3 Pacemaker的关键特性
3.1 监测并恢复节点和服务级别的故障。
3.2 存储无关不需要共享存储。而drbd在里就有了用武之地。
3.3 资源无关任何能用脚本控制的资源都可作为集群服务来管理
二、案例
1 拓扑图
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648279ayqb.png"></a>
2 案例说明
通过Corosync+openais+pacemaker来实现高可用性群集通过drbd来实现存储的高可用性
3 配置步骤
3.1 配置corosync
配置node1
配置网卡参数
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648279MBph.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648286qA18.png"></a>
保持时间一致性【从主板上读取时间】
# hwclock -s
编辑主机名
# vim /etc/sysconfig/network
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_135064828662Wf.png"></a>
# hostname node1.a.com
编辑hosts文件
# vim /etc/hosts
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648287ybZq.png"></a>
配置node2
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648290mFlD.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648293LGJ1.png"></a>
保持时间一致性
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506482964Jl4.png"></a>
# hostname node2.a.com
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648300shC5.png"></a>
在node1和node2中导入相应的安装包
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648309LvGY.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506483092BLJ.png"></a>
配置node1节点的corosync
挂载光盘
# mkdir /mnt/cdrom
# mount /dev/cdrom /mnt/cdrom
使用yum安装相应的软件包
# yum localinstall -y corosync/*.rpm --nogpgcheck
通过样例文件生成corosync的配置文件
# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf
编辑corosync的配置文件
# vim /etc/corosync/corosync.conf
心跳探测
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648313DGf6.png"></a>
通过corosync启用pacemaker
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648313Ov6y.png"></a>
添加openis的一些选项
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648313BGbE.png"></a>
创建corosync日志文件
# mkdir /var/log/cluster
群集验证
# corosync-keygen
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506483149Ldf.png"></a>
启动corosync服务
# service corosync start
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648314SYqF.png"></a>
查看群集节点状态
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648315G6Ti.png"></a>
配置node2的corosync
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648315KFEp.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648315YtHt.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_135064831655CU.png"></a>
群集验证与node1的authkey必须相同
# scp node1:/etc/corosync/authkey /etc/corosync/
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506483162Org.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648320x4Cc.png"></a>
3.2 配置node1的资源只需要在一个节点上配置即可
安装httpd服务
# rpm -ivh /mnt/cdrom/Server/httpd-2.2.3-31.el5.i386.rpm
配置资源
[root@node1 ~]# crm
crm(live)# configure
禁用stonith解决stonith的错误
crm(live)configure# property stonith-enabled=false
定义群集ip资源
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=192.168.2.100
定义群集服务资源
crm(live)configure# primitive webserver lsb:httpd
做资源约束将多个资源加入到同一个组中
crm(live)configure# group web webip webserver
关闭票数功能
crm(live)configure# property no-quorum-policy=ignore
查看资源
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506483201oFC.png"></a>
提交编辑的资源
crm(live)configure# commit
配置node2的资源node2的资源不需要配置
查看node2的资源
[root@node2 ~]# crm
crm(live)configure# show
node node1.a.com
node node2.a.com
primitive webip ocf:heartbeat:IPaddr \
params ip="192.168.2.100"
primitive webserver lsb:httpd
group web webip webserver
property $id="cib-bootstrap-options" \
dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
cluster-infrastructure="openais" \
expected-quorum-votes="2" \
stonith-enabled="false" \
no-quorum-policy="ignore"
crm(live)configure# exit
3.3 配置DRBD
在node1中新建一个分区
# fdisk /dev/sda
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648320Robb.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648321J2Ox.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648324PC0E.png"></a>
使内核从新读取分区表
# partprobe /dev/sda
在node2中新建一个分区
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648336wOxN.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648339Rvjk.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648340vnwU.png"></a>
在node1和node2上安装drbd服务
导入drbd相关的软件包
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648340zawd.png"></a>
安装drbd服务
# rpm -ivh drbd83-8.3.8-1.el5.centos.i386.rpm
安装drbd的内核模块
# rpm -ivh kmod-drbd83-8.3.8-1.el5.centos.i686.rpm
在node1编辑drbd主配置文件
# vim /etc/drbd.conf
读取样例文件内容底行模式
:r /usr/share/doc/drbd83-8.3.8/drbd.conf
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648347YJmo.png"></a>
编辑通用资源
# vim /etc/drbd.d/global_common.conf
添加下面的代码
global {
usage-count yes;
# minor-count dialog-refresh disable-ip-verification
}
common {
protocol C;
startup {
wfc-timeout 120; degr-wfc-timeout 120;
} disk {
on-io-error detach; fencing resource-only;
}
net {
cram-hmac-alg "sha1"; shared-secret "mydrbdlab";
}
syncer {
rate 100M;
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648347QBSg.png"></a>
编辑详细资源
# vim /etc/drbd.d/web.res
resource web {
on node1.a.com {
device /dev/drbd0;
disk /dev/sda5;
address 192.168.2.10:7789;
meta-disk internal;
}
on node2.a.com {
address 192.168.2.20:7789;
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648350maoo.png"></a>
初始化node2的drbd
# drbdadm create-md web
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648351xoTu.png"></a>
在node2编辑drbd主配置文件
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648351WrLX.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648352ATRi.png"></a>
}
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648352DD0p.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_13506483534a99.png"></a>
共同启动node1和node2的drbd服务
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648353SzrP.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648353c6st.png"></a>
查看drbd设备状态
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648354qhJg.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648354DJEm.png"></a>
将node1的设备调整为主设备
# drbdadm -- --overwrite-data-of-peer primary web
此时node1的设备和node2的设备将处于同步状态
在node1上格式化分区/dev/drbd0
# mkfs -t ext3 -L drbdweb /dev/drbd0
将分区/dev/drbd0挂在到httpd主站点上
# mount /dev/drbd0 /var/www/html/
创建httpd站点页面
# echo "hello" >/var/www/html/index.html
4 测试
4.1 在node1为主站点时
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648354Hdi5.png"></a>
查看网卡信息
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648358pG5j.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648361pjnN.png"></a>
查看节点上分区的状态
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648362S705.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648362Ov62.png"></a>
4.2 当关闭node1的corosync服务后
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648362l3xb.png"></a>
手工将node2的/dev/drbd0调整为主设备
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648363JSaJ.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648363UKNO.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648364nuDz.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648364gQiZ.png"></a>
<a href="http://cexpert.blog.51cto.com/attachment/201210/19/5251990_1350648364bSmJ.png"></a>
本文转自 cexpert 51CTO博客原文链接:http://blog.51cto.com/cexpert/1031880