一、基礎知識
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
挂載CD光牒
# 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