Product SiteDocumentation Site

Pacemaker 1.1

从​头​开​始​搭​建​集​群​

在​Fedora上​面​创​建​主​/主​和​主​备​集​群​

版 3

Andrew Beekhof

作​者​ 
Red Hat

Raoul Scarazzini

意​大​利​语​翻​译​ 

法律通告

Copyright © 2010 Andrew Beekhof This material may only be distributed subject to the terms and conditions set forth in the GNU Free Documentation License (GFDL), V1.2 or later (the latest version is presently available at http://www.gnu.org/licenses/fdl.txt).
摘要
本​文​档​的​主​要​目​的​是​提​供​一​站​式​指​南​,教​您​如​何​使​用​Pacemaker创​建​一​个​主​/备​模​式​的​集​群​并​把​它​转​换​到​主​/主​模​式​。​
示​例​集​群​会​使​用​以​下​软​件​:
  1. Fedora 13 作​为​基​本​操​作​系​统​
  2. Corosync作​为​通​信​层​和​提​供​关​系​管​理​服​务​
  3. Pacemaker来​实​现​资​源​管​理​
  4. DRBD 作​为​一​个​经​济​的​共​享​存​储​方​案​
  5. GFS2 作​为​集​群​文​件​系​统​(主​/主​模​式​中​)
  6. crm shell 来​显​示​并​修​改​配​置​文​件​
虽​然​给​出​了​图​形​化​安​装​Fedora的​过​程​,并​且​有​很​多​截​图​,但​是​本​文​的​主​要​是​靠​命​令​来​操​作​,包​括​为​什​么​要​运​行​这​个​命​令​和​这​些​操​作​产​生​的​结​果​。​(译​者​注​:本​文​中​基​本​是​crm shell来​操​作​的​,这​里​应​该​是​老​版​本​文​档​的​遗​留​)

前​言​
1. 文​​​档​​​约​​​定​​​
1.1. 排​​​版​​​约​​​定​​​
1.2. 抬​​​升​​​式​​​引​​​用​​​约​​​定​​​
1.3. 备​​​注​​​及​​​警​​​告​​​
2. 我​​​们​​​需​​​要​​​您​​​的​​​反​​​馈​​​意​​​见​​​!
1. Read-Me-First
1.1. 本​文​范​围​
1.2. 什​么​是​Pacemaker?
1.3. Pacemaker 集​群​的​种​类​
1.4. Pacemaker 架​构​
1.4.1. 内​部​组​件​
2. 安​装​
2.1. 安​装​操​作​系​统​
2.2. 集​群​软​件​安​装​
2.2.1. 安​全​提​示​
2.2.2. 安​装​集​群​软​件​
2.3. 写​在​开​始​之​前​
2.4. 安​装​
2.4.1. 设​定​网​络​
2.4.2. 配​置​SSH
2.4.3. 简​化​节​点​名​称​
2.4.4. 配​置​ Corosync
2.4.5. 传​送​配​置​文​件​
3. 检​验​集​群​的​安​装​
3.1. 检​验​Corosync的​安​装​
3.2. 检​查​Pacemaker的​安​装​
4. 使​用​Pacemaker工​具​
5. 创​建​一​个​主​/备​集​群​
5.1. 浏​览​现​有​配​置​
5.2. 添​加​一​个​资​源​
5.3. 做​一​次​失​效​备​援​
5.3.1. 法​定​人​数​和​双​节​点​集​群​
5.3.2. 防​止​资​源​在​节​点​恢​复​后​移​动​
6. Apache - 添​加​更​多​的​服​务​
6.1. 安​装​Apache
6.2. 准​备​工​作​
6.3. 开​启​ Apache status URL
6.4. 更​新​配​置​文​件​
6.5. 确​保​资​源​在​同​一​个​节​点​运​行​
6.6. 控​制​资​源​的​启​动​停​止​顺​序​
6.7. 指​定​优​先​的​ Location
6.8. 在​集​群​中​手​工​地​移​动​资​源​
6.8.1. 把​控​制​权​交​还​给​集​群​
7. 用​DRBD同​步​存​储​
7.1. 安​装​DRBD软​件​包​
7.2. 配​置​DRBD
7.2.1. 为​DRBD创​建​一​个​分​区​
7.2.2. 配​置​DRBD
7.2.3. 初​始​化​并​载​入​DRBD
7.2.4. 向​DRBD中​添​加​数​据​
7.3. 在​集​群​中​配​置​DRBD
7.3.1. 迁​移​测​试​
8. 转​变​为​Active/Active
8.1. 需​求​
8.2. 安​装​一​个​集​群​文​件​系​统​ - GFS2
8.3. 整​合​ Pacemaker-GFS2
8.3.1. 添​加​ DLM 服​务​
8.3.2. 添​加​ GFS2 服​务​
8.4. 创​建​一​个​ GFS2 文​件​系​统​
8.4.1. 准​备​工​作​
8.4.2. 创​建​并​迁​移​数​据​到​ GFS2 分​区​
8.5. 8.5. 重​新​为​集​群​配​置​GFS2
8.6. 重​新​配​置​ Pacemaker 为​ Active/Active
8.6.1. 恢​复​测​试​
9. 配​置​ STONITH
9.1. 为​什​么​需​要​ STONITH
9.2. 你​该​用​什​么​样​的​STONITH设​备​。​
9.3. 配​置​STONITH
9.3.1. 例​子​
A. 配​置​扼​要​重​述​
A.1. 最​终​的​集​群​配​置​文​件​
A.2. 节​点​列​表​
A.3. 集​群​选​项​
A.4. 资​源​
A.4.1. 默​认​选​项​
A.4.2. 隔​离​
A.4.3. 服​务​地​址​
A.4.4. 分​布​式​锁​控​制​器​
A.4.5. GFS 控​制​守​护​进​程​
A.4.6. DRBD - 共​享​存​储​
A.4.7. 集​群​文​件​系​统​
A.4.8. Apache
B. Sample Corosync Configuration
C. Using CMAN for Cluster Membership and Quorum
C.1. Background
C.2. Adding CMAN Support
C.2.1. Adding CMAN Support - cluster.conf
C.2.2. Adding CMAN Support - corosync.conf
D. 延​伸​阅​读​
E. 修​订​历​史​
索引

前​言​

1. 文​​​档​​​约​​​定​​​

本​​​手​​​册​​​使​​​用​​​几​​​个​​​约​​​定​​​来​​​突​​​出​​​某​​​些​​​用​​​词​​​和​​​短​​​语​​​以​​​及​​​信​​​息​​​的​​​某​​​些​​​片​​​段​​​。​​​
在​​​ PDF 版​​​本​​​以​​​及​​​纸​​​版​​​中​​​,本​​​手​​​册​​​使​​​用​​​在​​​ Liberation 字​​​体​​​套​​​件​​​中​​​选​​​出​​​的​​​字​​​体​​​。​​​如​​​果​​​您​​​在​​​您​​​的​​​系​​​统​​​中​​​安​​​装​​​了​​​ Liberation 字​​​体​​​套​​​件​​​,它​​​还​​​可​​​用​​​于​​​ HTML 版​​​本​​​。​​​如​​​果​​​没​​​有​​​安​​​装​​​,则​​​会​​​显​​​示​​​可​​​替​​​换​​​的​​​类​​​似​​​字​​​体​​​。​​​请​​​注​​​意​​​:红​​​帽​​​企​​​业​​​ Linux 5 以​​​及​​​其​​​后​​​的​​​版​​​本​​​默​​​认​​​包​​​含​​​ Liberation 字​​​体​​​套​​​件​​​。​​​

1.1. 排​​​版​​​约​​​定​​​

我​​​们​​​使​​​用​​​四​​​种​​​排​​​版​​​约​​​定​​​突​​​出​​​特​​​定​​​用​​​词​​​和​​​短​​​语​​​。​​​这​​​些​​​约​​​定​​​及​​​其​​​使​​​用​​​环​​​境​​​如​​​下​​​。​​​
单​​​行​​​粗​​​体​​​
用​​​来​​​突​​​出​​​系​​​统​​​输​​​入​​​,其​​​中​​​包​​​括​​​ shell 命​​​令​​​、​​​文​​​件​​​名​​​以​​​及​​​路​​​径​​​。​​​还​​​可​​​用​​​来​​​突​​​出​​​按​​​键​​​以​​​及​​​组​​​合​​​键​​​。​​​例​​​如​​​:
要​​​看​​​到​​​文​​​件​​​您​​​当​​​前​​​工​​​作​​​目​​​录​​​中​​​文​​​件​​​ my_next_bestselling_novel 的​​​内​​​容​​​,请​​​在​​​ shell 提​​​示​​​符​​​后​​​输​​​入​​​ cat my_next_bestselling_novel 命​​​令​​​并​​​按​​​ Enter 键​​​执​​​行​​​该​​​命​​​令​​​。​​​
以​​​上​​​内​​​容​​​包​​​括​​​一​​​个​​​文​​​件​​​名​​​,一​​​个​​​ shell 命​​​令​​​以​​​及​​​一​​​个​​​按​​​键​​​,它​​​们​​​都​​​以​​​固​​​定​​​粗​​​体​​​形​​​式​​​出​​​现​​​,且​​​全​​​部​​​与​​​上​​​下​​​文​​​有​​​所​​​区​​​别​​​。​​​
组​​​合​​​键​​​可​​​通​​​过​​​使​​​用​​​连​​​字​​​符​​​连​​​接​​​组​​​合​​​键​​​的​​​每​​​个​​​部​​​分​​​来​​​与​​​按​​​键​​​区​​​别​​​。​​​例​​​如​​​:
按​​​ Enter 执​​​行​​​该​​​命​​​令​​​。​​​
按​​​ Ctrl+Alt+F1 切​​​换​​​到​​​第​​​一​​​个​​​虚​​​拟​​​终​​​端​​​。​​​Ctrl+Alt+F7 返​​​回​​​您​​​的​​​ X-Windows 会​​​话​​​。​​​
第​​​一​​​段​​​突​​​出​​​的​​​是​​​要​​​按​​​的​​​特​​​定​​​按​​​键​​​。​​​第​​​二​​​段​​​突​​​出​​​了​​​两​​​个​​​按​​​键​​​组​​​合​​​(每​​​个​​​组​​​合​​​都​​​要​​​同​​​时​​​按​​​)。​​​下​​​。​​​
如​​​果​​​讨​​​论​​​的​​​是​​​源​​​码​​​、​​​等​​​级​​​名​​​称​​​、​​​方​​​法​​​、​​​功​​​能​​​、​​​变​​​量​​​名​​​称​​​以​​​及​​​在​​​段​​​落​​​中​​​提​​​到​​​的​​​返​​​回​​​的​​​数​​​值​​​,那​​​么​​​都​​​会​​​以​​​上​​​述​​​形​​​式​​​出​​​现​​​,即​​​固​​​定​​​粗​​​体​​​。​​​例​​​如​​​:
与​​​文​​​件​​​相​​​关​​​的​​​等​​​级​​​包​​​括​​​用​​​于​​​文​​​件​​​系​​​统​​​的​​​ filesystem、​​​用​​​于​​​文​​​件​​​的​​​ file 以​​​及​​​用​​​于​​​目​​​录​​​的​​​ dir。​​​每​​​个​​​等​​​级​​​都​​​有​​​其​​​自​​​身​​​相​​​关​​​的​​​权​​​限​​​。​​​
比​​​例​​​粗​​​体​​​
这​​​是​​​指​​​在​​​系​​​统​​​中​​​遇​​​到​​​的​​​文​​​字​​​或​​​者​​​短​​​语​​​,其​​​中​​​包​​​括​​​应​​​用​​​程​​​序​​​名​​​称​​​、​​​对​​​话​​​框​​​文​​​本​​​、​​​标​​​记​​​的​​​按​​​钮​​​、​​​复​​​选​​​框​​​以​​​及​​​单​​​选​​​按​​​钮​​​标​​​签​​​、​​​菜​​​单​​​标​​​题​​​以​​​及​​​子​​​菜​​​单​​​标​​​题​​​。​​​例​​​如​​​:
在​​​主​​​菜​​​单​​​条​​​中​​​选​​​择​​​「​​​系​​​统​​​」​​​「​​​首​​​选​​​项​​​」​​​「​​​鼠​​​标​​​」​​​启​​​动​​​ 鼠​​​标​​​首​​​选​​​项​​​。​​​在​​​「​​​按​​​钮​​​」​​​标​​​签​​​中​​​点​​​击​​​「​​​惯​​​用​​​左​​​手​​​鼠​​​标​​​」​​​ 复​​​选​​​框​​​并​​​点​​​击​​​ 关​​​闭​​​切​​​换​​​到​​​主​​​鼠​​​标​​​按​​​钮​​​从​​​左​​​向​​​右​​​(让​​​鼠​​​标​​​适​​​合​​​左​​​手​​​使​​​用​​​)。​​​
要​​​在​​​ gedit 文​​​件​​​中​​​插​​​入​​​一​​​个​​​特​​​殊​​​字​​​符​​​,请​​​在​​​主​​​菜​​​单​​​中​​​选​​​择​​​「​​​应​​​用​​​程​​​序​​​」​​​「​​​附​​​件​​​」​​​「​​​字​​​符​​​映​​​射​​​表​​​」​​​。​​​下​​​一​​​步​​​在​​​ 字​​​符​​​映​​​射​​​表​​​菜​​​单​​​条​​​中​​​选​​​择​​​「​​​搜​​​索​​​」​​​「​​​查​​​找​​​」​​​,在​​​「​​​搜​​​索​​​」​​​字​​​段​​​输​​​入​​​字​​​符​​​名​​​称​​​并​​​点​​​击​​​ 下​​​一​​​个​​​ 按​​​钮​​​。​​​您​​​输​​​入​​​的​​​字​​​符​​​会​​​在​​​「​​​字​​​符​​​表​​​」​​​中​​​突​​​出​​​出​​​来​​​。​​​双​​​击​​​这​​​个​​​突​​​出​​​的​​​字​​​符​​​将​​​其​​​放​​​入​​​「​​​要​​​复​​​制​​​的​​​文​​​本​​​」​​​字​​​段​​​,然​​​后​​​点​​​击​​​ 复​​​制​​​ 按​​​钮​​​。​​​现​​​在​​​切​​​换​​​回​​​您​​​的​​​文​​​档​​​并​​​在​​​ gedit 菜​​​单​​​条​​​中​​​选​​​择​​​「​​​编​​​辑​​​」​​​「​​​粘​​​贴​​​」​​​。​​​
以​​​上​​​文​​​本​​​包​​​括​​​应​​​用​​​程​​​序​​​名​​​称​​​、​​​系​​​统​​​范​​​围​​​菜​​​单​​​名​​​称​​​及​​​项​​​目​​​、​​​应​​​用​​​程​​​序​​​特​​​定​​​菜​​​单​​​名​​​称​​​以​​​及​​​按​​​钮​​​和​​​ GUI 界​​​面​​​中​​​的​​​文​​​本​​​,所​​​有​​​都​​​以​​​比​​​例​​​粗​​​体​​​出​​​现​​​并​​​与​​​上​​​下​​​文​​​区​​​别​​​。​​​
固​​​定​​​粗​​​斜​​​体​​​ 或​​​者​​​ 比​​​例​​​粗​​​斜​​​体​​​
无​​​论​​​固​​​定​​​粗​​​体​​​或​​​者​​​比​​​例​​​粗​​​体​​​,附​​​加​​​的​​​斜​​​体​​​表​​​示​​​是​​​可​​​替​​​换​​​或​​​者​​​变​​​量​​​文​​​本​​​。​​​斜​​​体​​​表​​​示​​​那​​​些​​​不​​​直​​​接​​​输​​​入​​​的​​​文​​​本​​​或​​​者​​​那​​​些​​​根​​​据​​​环​​​境​​​改​​​变​​​的​​​文​​​本​​​。​​​例​​​如​​​:
要​​​使​​​用​​​ ssh 连​​​接​​​到​​​远​​​程​​​机​​​器​​​,请​​​在​​​ shell 提​​​示​​​符​​​后​​​输​​​入​​​ ssh username@domain.name。​​​如​​​果​​​远​​​程​​​机​​​器​​​是​​​ example.com 且​​​您​​​在​​​该​​​其​​​机​​​器​​​中​​​的​​​用​​​户​​​名​​​为​​​ john,请​​​输​​​入​​​ ssh john@example.com。​​​
mount -o remount file-system 命​​​令​​​会​​​重​​​新​​​挂​​​载​​​命​​​名​​​的​​​文​​​件​​​系​​​统​​​。​​​例​​​如​​​:要​​​重​​​新​​​挂​​​载​​​ /home 文​​​件​​​系​​​统​​​,则​​​命​​​令​​​为​​​ mount -o remount /home。​​​
要​​​查​​​看​​​目​​​前​​​安​​​装​​​的​​​软​​​件​​​包​​​版​​​本​​​,请​​​使​​​用​​​ rpm -q package 命​​​令​​​。​​​它​​​会​​​返​​​回​​​以​​​下​​​结​​​果​​​:package-version-release。​​​
请​​​注​​​意​​​以​​​上​​​文​​​字​​​中​​​的​​​粗​​​斜​​​体​​​字​​​ — username、​​​domain.name、​​​file-system、​​​package、​​​version 和​​​ release。​​​无​​​论​​​您​​​输​​​入​​​文​​​本​​​或​​​者​​​运​​​行​​​一​​​个​​​命​​​令​​​,还​​​是​​​该​​​系​​​统​​​显​​​示​​​的​​​文​​​本​​​,每​​​个​​​字​​​都​​​是​​​一​​​个​​​占​​​位​​​符​​​。​​​
不​​​考​​​虑​​​工​​​作​​​中​​​显​​​示​​​标​​​题​​​的​​​标​​​准​​​用​​​法​​​,斜​​​体​​​表​​​示​​​第​​​一​​​次​​​使​​​用​​​某​​​个​​​新​​​且​​​重​​​要​​​的​​​用​​​语​​​。​​​例​​​如​​​:
Publican 是​​​一​​​个​​​ DocBook 发​​​布​​​系​​​统​​​。​​​

1.2. 抬​​​升​​​式​​​引​​​用​​​约​​​定​​​

终​​​端​​​输​​​出​​​和​​​源​​​代​​​码​​​列​​​表​​​要​​​与​​​周​​​围​​​文​​​本​​​明​​​显​​​分​​​开​​​。​​​
将​​​发​​​送​​​到​​​终​​​端​​​的​​​输​​​出​​​设​​​定​​​为​​​ Mono-spaced Roman 并​​​显​​​示​​​为​​​:
books        Desktop   documentation  drafts  mss    photos   stuff  svn
books_tests  Desktop1  downloads      images  notes  scripts  svgs
源​​​码​​​列​​​表​​​也​​​设​​​为​​​ Mono-spaced Roman,但​​​添​​​加​​​下​​​面​​​突​​​出​​​的​​​语​​​法​​​:
package org.jboss.book.jca.ex1;

import javax.naming.InitialContext;

public class ExClient
{
   public static void main(String args[]) 
       throws Exception
   {
      InitialContext iniCtx = new InitialContext();
      Object         ref    = iniCtx.lookup("EchoBean");
      EchoHome       home   = (EchoHome) ref;
      Echo           echo   = home.create();

      System.out.println("Created Echo");

      System.out.println("Echo.echo('Hello') = " + echo.echo("Hello"));
   }
}

1.3. 备​​​注​​​及​​​警​​​告​​​

最​​​后​​​,我​​​们​​​使​​​用​​​三​​​种​​​视​​​觉​​​形​​​式​​​来​​​突​​​出​​​那​​​些​​​可​​​能​​​被​​​忽​​​视​​​的​​​信​​​息​​​。​​​

备​​​注​​​

备​​​注​​​是​​​对​​​手​​​头​​​任​​​务​​​的​​​提​​​示​​​、​​​捷​​​径​​​或​​​者​​​备​​​选​​​的​​​解​​​决​​​方​​​法​​​。​​​忽​​​略​​​提​​​示​​​不​​​会​​​造​​​成​​​负​​​面​​​后​​​果​​​,但​​​您​​​可​​​能​​​会​​​错​​​过​​​一​​​个​​​更​​​省​​​事​​​的​​​诀​​​窍​​​。​​​

重​​​要​​​

Important boxes detail things that are easily missed: configuration changes that only apply to the current session, or services that need restarting before an update will apply. Ignoring a box labeled 'Important' won't cause data loss but may cause irritation and frustration.

警​​​告​​​

警​​​告​​​是​​​不​​​应​​​被​​​忽​​​略​​​的​​​。​​​忽​​​略​​​警​​​告​​​信​​​息​​​很​​​可​​​能​​​导​​​致​​​数​​​据​​​丢​​​失​​​。​​​

2. 我​​​们​​​需​​​要​​​您​​​的​​​反​​​馈​​​意​​​见​​​!

您​​​应​​​该​​​创​​​建​​​您​​​自​​​己​​​的​​​本​​​地​​​ Feedback.xml 文​​​件​​​来​​​覆​​​盖​​​这​​​个​​​文​​​件​​​。​​​

第 1 章 Read-Me-First

1.1. 本​文​范​围​

本​文​的​目​的​是​透​彻​地​解​释​用​于​配​置​Pacemaker的​概​念​。​为​了​达​到​最​好​的​效​果​,本​文​会​主​要​关​注​于​用​于​配​置​CIB的​XML格​式​。​
对​于​那​些​特​别​讨​厌​XML的​人​,Pacemaker有​一​个​集​群​shell和​基​于​Python的​GUI,但​是​本​文​没​有​包​含​这​些​工​具​的​使​用​ [1] , 正​是​因​为​它​们​隐​藏​了​XML细​节​。​(译​者​注​:本​文​中​基​本​是​crm shell来​操​作​的​,这​里​应​该​是​老​版​本​文​档​的​遗​留​)
此​外​,本​文​不​是​一​个​手​把​手​地​教​你​配​置​特​定​集​群​方​案​的​how-to guide。​尽​管​有​很​多​这​样​的​内​容​,但​是​本​文​的​主​要​目​的​是​让​大​家​理​解​配​置​Pacemaker所​需​要​用​到​的​各​种​组​件​。​

1.2. 什​么​是​Pacemaker?

Pacemaker是​一​个​集​群​资​源​管​理​者​。​他​用​资​源​级​别​的​监​测​和​恢​复​来​保​证​集​群​服​务​(aka. 资​源​)的​最​大​可​用​性​。​它​可​以​用​你​所​擅​长​的​基​础​组​件​(Corosync或​者​是​Heartbeat)来​实​现​通​信​和​关​系​管​理​。​
Pacemaker's key features include:
  • 监​测​并​恢​复​节​点​和​服​务​级​别​的​故​障​
  • 存​储​无​关​,并​不​需​要​共​享​存​储​
  • 资​源​无​关​,任​何​能​用​脚​本​控​制​的​资​源​都​可​以​作​为​服​务​
  • 支​持​使​用​STONITH来​保​证​数​据​一​致​性​。​
  • 支​持​大​型​或​者​小​型​的​集​群​
  • clusters 支​持​ quorate(法​定​人​数​) 或​ resource(资​源​) 驱​动​的​集​群​
  • 支​持​任​何​的​ 冗​余​配​置​
  • 自​动​同​步​各​个​节​点​的​配​置​文​件​
  • 可​以​设​定​集​群​范​围​内​的​ordering, colocation and anti-colocation
  • 支​持​高​级​的​服​务​模​式​
    • Clones:为​那​些​要​在​多​个​节​点​运​行​的​服​务​所​准​备​的​
    • Multi-state:为​那​些​有​多​种​模​式​的​服​务​准​备​的​。​(比​如​.主​从​, 主​备​)
  • 统​一​的​,可​脚​本​控​制​的​cluster shell

1.3. Pacemaker 集​群​的​种​类​

Pacemaker对​你​的​环​境​没​有​特​定​的​要​求​,这​使​得​它​支​持​任​何​的​冗​余​配​置​,包​括​ Active/Active, Active/Passive, N+1, N+M, N-to-1 and N-to-N。​
Active/Passive 冗​余​
使​用​Pacemaker和​DRBD的​双​节​点​主​备​方​案​作​为​一​种​经​济​的​解​决​方​案​被​很​多​高​可​用​环​境​所​采​用​。​
图 1.1. Active/Passive 冗​余​

共​享​失​效​备​援​
正​是​因​为​支​持​很​多​节​点​,Pacemaker可​以​让​多​个​主​备​模​式​的​集​群​集​成​起​来​并​共​享​一​个​备​用​节​点​,从​而​大​幅​度​的​减​少​硬​件​成​本​
图 1.2. 共​享​失​效​备​援​

N to N 冗​余​
当​有​共​享​存​储​设​备​是​,每​个​节​点​都​成​为​潜​在​的​备​援​节​点​。​Pacemaker甚​至​可​以​在​不​同​的​节​点​上​跑​相​同​的​服​务​来​负​载​均​衡​。​
图 1.3. N to N 冗​余​

1.4. Pacemaker 架​构​

在​最​高​一​个​层​次​,集​群​由​三​个​部​分​组​成​:
  • 提​供​消​息​和​集​群​关​系​功​能​的​集​群​核​心​基​础​组​件​(标​红​的​部​分​)
  • 集​群​无​关​的​组​件​(蓝​色​的​部​分​)。​在​Pacemaker架​构​中​,这​部​分​不​仅​包​含​有​怎​么​样​启​动​,关​闭​,监​控​资​源​的​脚​本​,而​且​还​有​一​个​本​地​的​守​护​进​程​来​消​除​这​些​脚​本​实​现​的​(采​用​的​)不​同​标​准​之​间​的​差​异​
  • 大​脑​(绿​色​部​分​)处​理​并​响​应​来​自​集​群​和​资​源​的​事​件​(比​如​节​点​的​离​开​和​加​入​,资​源​的​失​效​) ,以​及​管​理​员​对​配​置​文​件​的​修​改​。​在​对​所​有​这​些​事​件​的​响​应​中​,Pacemaker会​计​算​集​群​理​想​的​状​态​,并​规​划​一​个​途​径​来​实​现​它​。​这​个​操​作​可​能​会​包​含​移​动​资​源​,停​止​节​点​,甚​至​使​用​远​程​电​源​管​理​来​强​制​使​他​们​下​线​。​
概​念​层​次​总​览​
集​群​概​念​层​次​总​览​
图 1.4. 概​念​层​次​总​览​

When combined with Corosync, Pacemaker also supports popular open source cluster filesystems [2] Due to recent standardization within the cluster filesystem community, they make use of a common distributed lock manager which makes use of Corosync for its messaging capabilities and Pacemaker for its membership (which nodes are up/down) and fencing services.
Pacemaker 层​次​
Pacemaker采​用​Corosync时​的​层​次​
图 1.5. Pacemaker 层​次​

1.4.1. 内​部​组​件​

Pacemaker本​身​由​四​个​关​键​组​件​组​成​:
  • CIB (aka. 集​群​信​息​基​础​)
  • CRMd (aka. 集​群​资​源​管​理​守​护​进​程​)
  • PEngine (aka. PE or 策​略​引​擎​)
  • STONITHd
内​部​组​件​
基​于​Corosync的​Pacemaker的​子​系​统​
图 1.6. 内​部​组​件​

The CIB uses XML to represent both the cluster's configuration and current state of all resources in the cluster. The contents of the CIB are automatically kept in sync across the entire cluster and are used by the PEngine to compute the ideal state of the cluster and how it should be achieved.
这​个​指​令​列​表​然​后​会​被​交​给​DC(指​定​协​调​者​)。​ Pacemaker会​推​举​一​个​CRMd实​例​作​为​master来​集​中​做​出​所​有​决​策​。​如​果​推​举​的​CRMd繁​忙​中​,或​者​这​个​节​点​不​够​稳​定​... 一​个​新​的​master会​马​上​被​推​举​出​来​。​
The DC carries out the PEngine's instructions in the required order by passing them to either the LRMd (Local Resource Management daemon) or CRMd peers on other nodes via the cluster messaging infrastructure (which in turn passes them on to their LRMd process).
节​点​会​把​他​们​所​有​操​作​的​日​志​发​给​DC,然​后​根​据​预​期​的​结​果​和​实​际​的​结​果​(之​间​的​差​异​), 执​行​下​一​个​等​待​中​的​命​令​,或​者​取​消​操​作​,并​让​PEngine根​据​非​预​期​的​结​果​重​新​计​算​集​群​的​理​想​状​态​。​
在​某​些​情​况​下​,可​能​会​需​要​关​闭​节​点​的​电​源​来​保​证​共​享​数​据​的​完​整​性​或​是​完​全​地​恢​复​资​源​。​为​此​Pacemaker引​入​了​STONITHd。​STONITH是​ Shoot-The-Other-Node-In-The-Head(爆​其​他​节​点​的​头​)的​缩​写​,并​且​通​常​是​靠​远​程​电​源​开​关​来​实​现​的​。​在​Pacemaker中​,STONITH设​备​被​当​成​资​源​(并​且​是​在​CIB中​配​置​)从​而​轻​松​地​监​控​,然​而​STONITHd会​注​意​理​解​STONITH拓​扑​,比​如​它​的​客​户​端​请​求​隔​离​一​个​节​点​,它​会​重​启​那​个​机​器​。​(译​者​注​:就​是​说​不​同​的​爆​头​设​备​驱​动​会​对​相​同​的​请​求​有​不​同​的​理​解​,这​些​都​是​在​驱​动​中​定​义​的​。​)


[1] 明​白​了​本​文​的​内​容​以​后​,会​更​容​易​理​解​那​些​工​具​的​功​能​,当​然​这​只​是​希​望​。​

[2] Even though Pacemaker also supports Heartbeat, the filesystems need to use the stack for messaging and membership and Corosync seems to be what they're standardizing on. Technically it would be possible for them to support Heartbeat as well, however there seems little interest in this.

第 2 章 安​装​

2.1. 安​装​操​作​系​统​

详​细​的​安​装​手​册​在​http://docs.fedoraproject.org/install-guide/f13/。​下​文​是​一​个​简​短​的​版​本​...
在​你​的​浏​览​器​中​打​开​ http://fedoraproject.org/en/get-fedora-all,找​到​Install Media部​分​并​下​载​适​合​你​硬​件​的​安​装​DVD文​件​。​
烧​录​一​个​DVD光​盘​ [3] 并​从​它​启​动​。​或​者​就​像​我​一​样​启​动​一​个​虚​拟​机​。​ 在​点​击​欢​迎​界​面​的​NETX后​ ,我​们​要​开​始​选​择​语​言​和​键​盘​类​型​ [4]
安​装​Fedora - 欢​迎​
安​装​Fedora: 好​的​选​择​!
图 2.1. 安​装​Fedora - 欢​迎​

安​装​Fedora - 存​储​设​备​
安​装​Fedora: 存​储​设​备​
图 2.2. 安​装​Fedora - 存​储​设​备​

给​你​的​机​器​取​个​名​字​。​[5] 我​可​以​使​用​clusterlabs.org这​个​域​名​,所​以​在​这​里​我​用​这​个​域​名​。​
安​装​Fedora -机​器​名​
安​装​Fedora: 选​择​一​个​机​器​名​
图 2.3. 安​装​Fedora -机​器​名​

然​后​你​会​被​提​示​选​择​机​器​所​在​地​并​设​定​root密​码​。​[6]
Now select where you want Fedora installed. [7] As I don’​t care about any existing data, I will accept the default and allow Fedora to use the complete drive. However I want to reserve some space for DRBD, so I'll check the Review and modify partitioning layout box.
安​装​Fedora - 安​装​类​型​
安​装​Fedora: 选​择​安​装​类​型​
图 2.4. 安​装​Fedora - 安​装​类​型​

By default, Fedora will give all the space to the / (aka. root) partition. Wel'll take some back so we can use DRBD.
安​装​Fedora - 默​认​分​区​
图 2.5. 安​装​Fedora - 默​认​分​区​

完​整​的​分​区​应​该​像​下​面​一​样​。​

重要

如​果​你​想​试​验​本​文​档​中​关​于​DRBD或​者​GFS2的​部​分​,你​要​为​每​个​节​点​保​留​至​少​1Gb的​空​间​。​
安​装​Fedora - 自​定​义​分​区​
安​装​Fedora: 创​建​一​个​网​站​存​放​数​据​用​的​分​区​
图 2.6. 安​装​Fedora - 自​定​义​分​区​

安​装​Fedora - Bootloader
安​装​Fedora: 除​非​有​非​常​强​力​的​理​由​,不​然​选​择​默​认​的​bootloader安​装​位​置​
图 2.7. 安​装​Fedora - Bootloader

Next choose which software should be installed. Change the selection to Web Server since we plan on using Apache. Don't enable updates yet, we'll do that (and install any extra software we need) later. After you click next, Fedora will begin installing.
安​装​Fedora - 软​件​
安​装​Fedora: 软​件​选​择​
图 2.8. 安​装​Fedora - 软​件​

安​装​Fedora - 安​装​中​
安​装​Fedora: 去​搞​点​东​西​喝​喝​ 这​要​一​会​儿​
图 2.9. 安​装​Fedora - 安​装​中​

安​装​Fedora - 安​装​完​成​
安​装​Fedora: Stage 1, 完​成​
图 2.10. 安​装​Fedora - 安​装​完​成​

一​旦​系​统​重​启​完​毕​你​可​以​看​到​以​下​界​面​ [8] ,然​后​配​置​用​户​和​设​定​时​间​。​
安​装​Fedora - 第​一​次​启​动​
图 2.11. 安​装​Fedora - 第​一​次​启​动​

安​装​Fedora - 创​建​非​特​权​用​户​
Fedora Installation: Creating a non-privileged user, take note of the password, you'll need it soon
图 2.12. 安​装​Fedora - 创​建​非​特​权​用​户​

注意

强​烈​建​议​开​启​NTP时​间​同​步​,这​样​可​以​使​集​群​更​好​的​同​步​配​置​文​件​以​及​使​日​志​文​件​有​更​好​的​可​读​性​。​
安​装​Fedora - 日​期​和​时​间​
安​装​Fedora : 启​用​NTP来​保​证​所​有​节​点​时​间​同​步​
图 2.13. 安​装​Fedora - 日​期​和​时​间​

点​击​next会​进​入​登​入​界​面​,点​击​你​创​建​的​用​户​并​输​入​之​前​设​定​的​密​码​。​
安​装​Fedora -自​定​义​网​络​
安​装​Fedora: 点​击​这​里​来​配​置​网​络​
图 2.14. 安​装​Fedora -自​定​义​网​络​

重要

不​要​使​用​默​认​的​网​络​设​置​,集​群​永​远​不​会​靠​DHCP来​管​理​IP,这​里​我​使​用​clusterslab的​内​部​IP。​
安​装​Fedora - 指​定​网​络​参​数​
安​装​Fedora: 设​定​你​的​网​络​,永​远​不​要​选​择​DHCP
图 2.15. 安​装​Fedora - 指​定​网​络​参​数​

安​装​Fedora - 激​活​网​络​
安​装​Fedora:点​击​绿​色​按​钮​来​应​用​你​的​更​改​
图 2.16. 安​装​Fedora - 激​活​网​络​

安​装​Fedora - 打​开​终​端​
安​装​Fedora:开​始​干​活​,打​开​终​端​
图 2.17. 安​装​Fedora - 打​开​终​端​

注意

这​是​最​后​一​个​截​屏​了​,剩​下​的​我​们​都​用​命​令​行​来​操​作​。​

2.2. 集​群​软​件​安​装​

Go to the terminal window you just opened and switch to the super user (aka. "root") account with the su command. You will need to supply the password you entered earlier during the installation process.
[beekhof@pcmk-1 ~]$ su -
Password:
[root@pcmk-1 ~]#

注意

注​意​用​户​名​ (@符​号​左​边​的​字​符​串​) 显​示​我​们​现​在​使​用​的​是​root用​户​.
[root@pcmk-1 ~]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN qlen 1000
    link/ether 00:0c:29:6f:e1:58 brd ff:ff:ff:ff:ff:ff
    inet 192.168.9.41/24 brd 192.168.9.255 scope global eth0
    inet6 ::20c:29ff:fe6f:e158/64 scope global dynamic 
       valid_lft 2591667sec preferred_lft 604467sec
    inet6 2002:57ae:43fc:0:20c:29ff:fe6f:e158/64 scope global dynamic 
       valid_lft 2591990sec preferred_lft 604790sec
    inet6 fe80::20c:29ff:fe6f:e158/64 scope link 
       valid_lft forever preferred_lft forever
[root@pcmk-1 ~]# ping -c 1 www.google.com
PING www.l.google.com (74.125.39.99) 56(84) bytes of data.
64 bytes from fx-in-f99.1e100.net (74.125.39.99): icmp_seq=1 ttl=56 time=16.7 ms

--- www.l.google.com ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 20ms
rtt min/avg/max/mdev = 16.713/16.713/16.713/0.000 ms
[root@pcmk-1 ~]# /sbin/chkconfig network on
[root@pcmk-1 ~]# 

2.2.1. 安​全​提​示​

为​了​简​化​本​文​档​并​更​好​的​关​注​集​群​方​面​的​问​题​,我​们​现​在​在​先​禁​用​防​火​墙​和​SELinux。​这​些​操​作​都​会​导​致​重​大​的​安​全​问​题​,并​不​推​荐​对​公​网​上​的​集​群​这​样​做​。​

重要

TODO: Create an Appendix that deals with (at least) re-enabling the firewall.
[root@pcmk-1 ~]# sed -i.bak "s/SELINUX=enforcing/SELINUX=permissive/g" /etc/selinux/config
[root@pcmk-1 ~]# /sbin/chkconfig --del iptables
[root@pcmk-1 ~]# service iptables stop
iptables: Flushing firewall rules:                         [  OK  ]
iptables: Setting chains to policy ACCEPT: filter          [  OK  ]
iptables: Unloading modules:                               [  OK  ]

重要

你​需​要​重​启​来​保​证​SELinux正​确​关​闭​。​不​然​你​启​动​corosync的​时​候​将​看​到​以​下​提​示​:
May  4 19:30:54 pcmk-1 setroubleshoot: SELinux is preventing /usr/sbin/corosync "getattr" access on /. For complete SELinux messages. run sealert -l 6e0d4384-638e-4d55-9aaf-7dac011f29c1
May  4 19:30:54 pcmk-1 setroubleshoot: SELinux is preventing /usr/sbin/corosync "getattr" access on /. For complete SELinux messages. run sealert -l 6e0d4384-638e-4d55-9aaf-7dac011f29c1

2.2.2. 安​装​集​群​软​件​

从​Fedora 12开​始​,你​需​要​的​东​西​都​已​经​准​备​好​了​,只​需​在​终​端​命​令​行​运​行​以​下​命​令​:
[root@pcmk-1 ~]# sed -i.bak "s/enabled=0/enabled=1/g" /etc/yum.repos.d/fedora.repo
[root@pcmk-1 ~]# sed -i.bak "s/enabled=0/enabled=1/g" /etc/yum.repos.d/fedora-updates.repo
[root@pcmk-1 ~]# yum install -y pacemaker corosync
Loaded plugins: presto, refresh-packagekit
fedora/metalink                   	                           |  22 kB     00:00     
fedora-debuginfo/metalink         	                           |  16 kB     00:00     
fedora-debuginfo                  	                           | 3.2 kB     00:00     
fedora-debuginfo/primary_db       	                           | 1.4 MB     00:04     
fedora-source/metalink            	                           |  22 kB     00:00     
fedora-source                     	                           | 3.2 kB     00:00     
fedora-source/primary_db          	                           | 3.0 MB     00:05     
updates/metalink                  	                           |  26 kB     00:00     
updates                           	                           | 2.6 kB     00:00     
updates/primary_db                	                           | 1.1 kB     00:00     
updates-debuginfo/metalink        	                           |  18 kB     00:00     
updates-debuginfo                 	                           | 2.6 kB     00:00     
updates-debuginfo/primary_db      	                           | 1.1 kB     00:00     
updates-source/metalink           	                           |  25 kB     00:00     
updates-source                    	                           | 2.6 kB     00:00     
updates-source/primary_db         	                           | 1.1 kB     00:00     
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package corosync.x86_64 0:1.2.1-1.fc13 set to be updated
--> Processing Dependency: corosynclib = 1.2.1-1.fc13 for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libquorum.so.4(COROSYNC_QUORUM_1.0)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libvotequorum.so.4(COROSYNC_VOTEQUORUM_1.0)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcpg.so.4(COROSYNC_CPG_1.0)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libconfdb.so.4(COROSYNC_CONFDB_1.0)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcfg.so.4(COROSYNC_CFG_0.82)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libpload.so.4(COROSYNC_PLOAD_1.0)(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: liblogsys.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libconfdb.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcoroipcc.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcpg.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libquorum.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcoroipcs.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libvotequorum.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libcfg.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libtotem_pg.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
--> Processing Dependency: libpload.so.4()(64bit) for package: corosync-1.2.1-1.fc13.x86_64
---> Package pacemaker.x86_64 0:1.1.5-1.fc13 set to be updated
--> Processing Dependency: heartbeat >= 3.0.0 for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: net-snmp >= 5.4 for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: resource-agents for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: cluster-glue for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libnetsnmp.so.20()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libcrmcluster.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libpengine.so.3()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libnetsnmpagent.so.20()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libesmtp.so.5()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libstonithd.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libhbclient.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libpils.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libpe_status.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libnetsnmpmibs.so.20()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libnetsnmphelpers.so.20()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libcib.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libccmclient.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libstonith.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: liblrm.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libtransitioner.so.1()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libpe_rules.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libcrmcommon.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Processing Dependency: libplumb.so.2()(64bit) for package: pacemaker-1.1.5-1.fc13.x86_64
--> Running transaction check
---> Package cluster-glue.x86_64 0:1.0.2-1.fc13 set to be updated
--> Processing Dependency: perl-TimeDate for package: cluster-glue-1.0.2-1.fc13.x86_64
--> Processing Dependency: libOpenIPMIutils.so.0()(64bit) for package: cluster-glue-1.0.2-1.fc13.x86_64
--> Processing Dependency: libOpenIPMIposix.so.0()(64bit) for package: cluster-glue-1.0.2-1.fc13.x86_64
--> Processing Dependency: libopenhpi.so.2()(64bit) for package: cluster-glue-1.0.2-1.fc13.x86_64
--> Processing Dependency: libOpenIPMI.so.0()(64bit) for package: cluster-glue-1.0.2-1.fc13.x86_64
---> Package cluster-glue-libs.x86_64 0:1.0.2-1.fc13 set to be updated
---> Package corosynclib.x86_64 0:1.2.1-1.fc13 set to be updated
--> Processing Dependency: librdmacm.so.1(RDMACM_1.0)(64bit) for package: corosynclib-1.2.1-1.fc13.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.0)(64bit) for package: corosynclib-1.2.1-1.fc13.x86_64
--> Processing Dependency: libibverbs.so.1(IBVERBS_1.1)(64bit) for package: corosynclib-1.2.1-1.fc13.x86_64
--> Processing Dependency: libibverbs.so.1()(64bit) for package: corosynclib-1.2.1-1.fc13.x86_64
--> Processing Dependency: librdmacm.so.1()(64bit) for package: corosynclib-1.2.1-1.fc13.x86_64
---> Package heartbeat.x86_64 0:3.0.0-0.7.0daab7da36a8.hg.fc13 set to be updated
--> Processing Dependency: PyXML for package: heartbeat-3.0.0-0.7.0daab7da36a8.hg.fc13.x86_64
---> Package heartbeat-libs.x86_64 0:3.0.0-0.7.0daab7da36a8.hg.fc13 set to be updated
---> Package libesmtp.x86_64 0:1.0.4-12.fc12 set to be updated
---> Package net-snmp.x86_64 1:5.5-12.fc13 set to be updated
--> Processing Dependency: libsensors.so.4()(64bit) for package: 1:net-snmp-5.5-12.fc13.x86_64
---> Package net-snmp-libs.x86_64 1:5.5-12.fc13 set to be updated
---> Package pacemaker-libs.x86_64 0:1.1.5-1.fc13 set to be updated
---> Package resource-agents.x86_64 0:3.0.10-1.fc13 set to be updated
--> Processing Dependency: libnet.so.1()(64bit) for package: resource-agents-3.0.10-1.fc13.x86_64
--> Running transaction check
---> Package OpenIPMI-libs.x86_64 0:2.0.16-8.fc13 set to be updated
---> Package PyXML.x86_64 0:0.8.4-17.fc13 set to be updated
---> Package libibverbs.x86_64 0:1.1.3-4.fc13 set to be updated
--> Processing Dependency: libibverbs-driver for package: libibverbs-1.1.3-4.fc13.x86_64
---> Package libnet.x86_64 0:1.1.4-3.fc12 set to be updated
---> Package librdmacm.x86_64 0:1.0.10-2.fc13 set to be updated
---> Package lm_sensors-libs.x86_64 0:3.1.2-2.fc13 set to be updated
---> Package openhpi-libs.x86_64 0:2.14.1-3.fc13 set to be updated
---> Package perl-TimeDate.noarch 1:1.20-1.fc13 set to be updated
--> Running transaction check
---> Package libmlx4.x86_64 0:1.0.1-5.fc13 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

==========================================================================================
 Package                Arch     Version                             Repository      Size
==========================================================================================
Installing:
 corosync               x86_64   1.2.1-1.fc13                        fedora         136 k
 pacemaker              x86_64   1.1.5-1.fc13                        fedora         543 k
Installing for dependencies:
 OpenIPMI-libs          x86_64   2.0.16-8.fc13                       fedora         474 k
 PyXML                  x86_64   0.8.4-17.fc13                       fedora         906 k
 cluster-glue           x86_64   1.0.2-1.fc13                        fedora         230 k
 cluster-glue-libs      x86_64   1.0.2-1.fc13                        fedora         116 k
 corosynclib            x86_64   1.2.1-1.fc13                        fedora         145 k
 heartbeat              x86_64   3.0.0-0.7.0daab7da36a8.hg.fc13      updates        172 k
 heartbeat-libs         x86_64   3.0.0-0.7.0daab7da36a8.hg.fc13      updates        265 k
 libesmtp               x86_64   1.0.4-12.fc12                       fedora          54 k
 libibverbs             x86_64   1.1.3-4.fc13                        fedora          42 k
 libmlx4                x86_64   1.0.1-5.fc13                        fedora          27 k
 libnet                 x86_64   1.1.4-3.fc12                        fedora          49 k
 librdmacm              x86_64   1.0.10-2.fc13                       fedora          22 k
 lm_sensors-libs        x86_64   3.1.2-2.fc13                        fedora          37 k
 net-snmp               x86_64   1:5.5-12.fc13                       fedora         295 k
 net-snmp-libs          x86_64   1:5.5-12.fc13                       fedora         1.5 M
 openhpi-libs           x86_64   2.14.1-3.fc13                       fedora         135 k
 pacemaker-libs         x86_64   1.1.5-1.fc13                        fedora         264 k
 perl-TimeDate          noarch   1:1.20-1.fc13                       fedora          42 k
 resource-agents        x86_64   3.0.10-1.fc13                       fedora         357 k

Transaction Summary
=========================================================================================
Install      21 Package(s)
Upgrade       0 Package(s)

Total download size: 5.7 M
Installed size: 20 M
Downloading Packages:
Setting up and reading Presto delta metadata
updates-testing/prestodelta                                           | 164 kB     00:00     
fedora/prestodelta                                                    |  150 B     00:00     
Processing delta metadata
Package(s) data still to download: 5.7 M
(1/21): OpenIPMI-libs-2.0.16-8.fc13.x86_64.rpm                        | 474 kB     00:00     
(2/21): PyXML-0.8.4-17.fc13.x86_64.rpm                                | 906 kB     00:01     
(3/21): cluster-glue-1.0.2-1.fc13.x86_64.rpm                          | 230 kB     00:00     
(4/21): cluster-glue-libs-1.0.2-1.fc13.x86_64.rpm                     | 116 kB     00:00     
(5/21): corosync-1.2.1-1.fc13.x86_64.rpm                              | 136 kB     00:00     
(6/21): corosynclib-1.2.1-1.fc13.x86_64.rpm                           | 145 kB     00:00     
(7/21): heartbeat-3.0.0-0.7.0daab7da36a8.hg.fc13.x86_64.rpm           | 172 kB     00:00     
(8/21): heartbeat-libs-3.0.0-0.7.0daab7da36a8.hg.fc13.x86_64.rpm      | 265 kB     00:00     
(9/21): libesmtp-1.0.4-12.fc12.x86_64.rpm                             |  54 kB     00:00     
(10/21): libibverbs-1.1.3-4.fc13.x86_64.rpm                           |  42 kB     00:00     
(11/21): libmlx4-1.0.1-5.fc13.x86_64.rpm                              |  27 kB     00:00     
(12/21): libnet-1.1.4-3.fc12.x86_64.rpm                               |  49 kB     00:00     
(13/21): librdmacm-1.0.10-2.fc13.x86_64.rpm                           |  22 kB     00:00     
(14/21): lm_sensors-libs-3.1.2-2.fc13.x86_64.rpm                      |  37 kB     00:00     
(15/21): net-snmp-5.5-12.fc13.x86_64.rpm                              | 295 kB     00:00     
(16/21): net-snmp-libs-5.5-12.fc13.x86_64.rpm                         | 1.5 MB     00:01     
(17/21): openhpi-libs-2.14.1-3.fc13.x86_64.rpm                        | 135 kB     00:00     
(18/21): pacemaker-1.1.5-1.fc13.x86_64.rpm                            | 543 kB     00:00     
(19/21): pacemaker-libs-1.1.5-1.fc13.x86_64.rpm                       | 264 kB     00:00     
(20/21): perl-TimeDate-1.20-1.fc13.noarch.rpm                         |  42 kB     00:00     
(21/21): resource-agents-3.0.10-1.fc13.x86_64.rpm                     | 357 kB     00:00     
----------------------------------------------------------------------------------------
Total                                                        539 kB/s | 5.7 MB     00:10     
warning: rpmts_HdrFromFdno: Header V3 RSA/SHA256 Signature, key ID e8e40fde: NOKEY
fedora/gpgkey                                                         | 3.2 kB     00:00 ... 
Importing GPG key 0xE8E40FDE "Fedora (13) <fedora@fedoraproject.org%gt;" from /etc/pki/rpm-gpg/RPM-GPG-KEY-fedora-x86_64
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : lm_sensors-libs-3.1.2-2.fc13.x86_64                            1/21 
  Installing     : 1:net-snmp-libs-5.5-12.fc13.x86_64                             2/21 
  Installing     : 1:net-snmp-5.5-12.fc13.x86_64                                  3/21 
  Installing     : openhpi-libs-2.14.1-3.fc13.x86_64                              4/21 
  Installing     : libibverbs-1.1.3-4.fc13.x86_64                                 5/21 
  Installing     : libmlx4-1.0.1-5.fc13.x86_64                                    6/21 
  Installing     : librdmacm-1.0.10-2.fc13.x86_64                                 7/21 
  Installing     : corosync-1.2.1-1.fc13.x86_64                                   8/21 
  Installing     : corosynclib-1.2.1-1.fc13.x86_64                                9/21 
  Installing     : libesmtp-1.0.4-12.fc12.x86_64                                 10/21 
  Installing     : OpenIPMI-libs-2.0.16-8.fc13.x86_64                            11/21 
  Installing     : PyXML-0.8.4-17.fc13.x86_64                                    12/21 
  Installing     : libnet-1.1.4-3.fc12.x86_64                                    13/21 
  Installing     : 1:perl-TimeDate-1.20-1.fc13.noarch                            14/21 
  Installing     : cluster-glue-1.0.2-1.fc13.x86_64                              15/21 
  Installing     : cluster-glue-libs-1.0.2-1.fc13.x86_64                         16/21 
  Installing     : resource-agents-3.0.10-1.fc13.x86_64                          17/21 
  Installing     : heartbeat-libs-3.0.0-0.7.0daab7da36a8.hg.fc13.x86_64          18/21 
  Installing     : heartbeat-3.0.0-0.7.0daab7da36a8.hg.fc13.x86_64               19/21 
  Installing     : pacemaker-1.1.5-1.fc13.x86_64                                 20/21 
  Installing     : pacemaker-libs-1.1.5-1.fc13.x86_64                            21/21 

Installed:
  corosync.x86_64 0:1.2.1-1.fc13                    pacemaker.x86_64 0:1.1.5-1.fc13                   

Dependency Installed:
  OpenIPMI-libs.x86_64 0:2.0.16-8.fc13                          
  PyXML.x86_64 0:0.8.4-17.fc13                                  
  cluster-glue.x86_64 0:1.0.2-1.fc13                            
  cluster-glue-libs.x86_64 0:1.0.2-1.fc13                       
  corosynclib.x86_64 0:1.2.1-1.fc13                             
  heartbeat.x86_64 0:3.0.0-0.7.0daab7da36a8.hg.fc13             
  heartbeat-libs.x86_64 0:3.0.0-0.7.0daab7da36a8.hg.fc13        
  libesmtp.x86_64 0:1.0.4-12.fc12                               
  libibverbs.x86_64 0:1.1.3-4.fc13                              
  libmlx4.x86_64 0:1.0.1-5.fc13                                 
  libnet.x86_64 0:1.1.4-3.fc12                                  
  librdmacm.x86_64 0:1.0.10-2.fc13                              
  lm_sensors-libs.x86_64 0:3.1.2-2.fc13                         
  net-snmp.x86_64 1:5.5-12.fc13                                 
  net-snmp-libs.x86_64 1:5.5-12.fc13                            
  openhpi-libs.x86_64 0:2.14.1-3.fc13                           
  pacemaker-libs.x86_64 0:1.1.5-1.fc13                          
  perl-TimeDate.noarch 1:1.20-1.fc13                            
  resource-agents.x86_64 0:3.0.10-1.fc13                        

Complete!
[root@pcmk-1 ~]# 

2.3. 写​在​开​始​之​前​

在​另​一​台​Fedora 12机​器​上​面​重​复​以​上​操​作​步​骤​,这​样​你​就​有​2台​安​装​了​集​群​软​件​的​节​点​了​。​
在​这​篇​文​档​中​, 另​外​一​个​节​点​叫​ pcmk-2 并​且​IP地​址​为​ 192.168.122.42。​

2.4. 安​装​

2.4.1. 设​定​网​络​

确​认​这​两​个​新​节​点​能​够​通​讯​:
	  ping -c 3 192.168.122.102
[root@pcmk-1 ~]# ping -c 3 192.168.122.102
PING 192.168.122.102 (192.168.122.102) 56(84) bytes of data.
64 bytes from 192.168.122.102: icmp_seq=1 ttl=64 time=0.343 ms
64 bytes from 192.168.122.102: icmp_seq=2 ttl=64 time=0.402 ms
64 bytes from 192.168.122.102: icmp_seq=3 ttl=64 time=0.558 ms

--- 192.168.122.102 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.343/0.434/0.558/0.092 ms
图 2.18. 通​过​IP地​址​来​检​查​连​接​

现​在​我​们​需​要​确​认​我​们​能​通​过​机​器​名​访​问​这​两​台​机​器​,如​果​你​有​一​个​DNS服​务​器​,为​这​两​台​节​点​做​域​名​解​析​。​
	  grep pcmk /etc/hosts
[root@pcmk-1 ~]# grep pcmk /etc/hosts
192.168.122.101 pcmk-1.clusterlabs.org pcmk-1
192.168.122.102 pcmk-2.clusterlabs.org pcmk-2
图 2.19. 否​则​,我​们​修​改​/etc/hosts文​件​来​达​到​相​同​的​效​果​:

现​在​让​我​们​ping一​下​:
	  ping -c 3 pcmk-2
[root@pcmk-1 ~]# ping -c 3 pcmk-2
PING pcmk-2.clusterlabs.org (192.168.122.101) 56(84) bytes of data.
64 bytes from pcmk-1.clusterlabs.org (192.168.122.101): icmp_seq=1 ttl=64 time=0.164 ms
64 bytes from pcmk-1.clusterlabs.org (192.168.122.101): icmp_seq=2 ttl=64 time=0.475 ms
64 bytes from pcmk-1.clusterlabs.org (192.168.122.101): icmp_seq=3 ttl=64 time=0.186 ms

--- pcmk-2.clusterlabs.org ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.164/0.275/0.475/0.141 ms
图 2.20. 通​过​机​器​名​检​查​连​接​

2.4.2. 配​置​SSH

SSH 是​一​个​方​便​又​安​全​来​的​用​来​远​程​传​输​文​件​或​运​行​命​令​ 的​工​具​. 在​这​个​文​档​中​, 我​们​创​建​ssh key(用​ -N “​”​ 选​项​)来​免​去​登​入​要​输​入​密​码​的​麻​烦​。​

警告

不​推​荐​在​公​网​的​机​器​上​采​用​未​用​密​码​保​护​的​ssh-key
创​建​一​个​密​钥​并​允​许​所​有​有​这​个​密​钥​的​用​户​登​入​
[root@pcmk-1 ~]# ssh-keygen -t dsa -f ~/.ssh/id_dsa -N ""
Generating public/private dsa key pair.
Your identification has been saved in /root/.ssh/id_dsa.
Your public key has been saved in /root/.ssh/id_dsa.pub.
The key fingerprint is:
91:09:5c:82:5a:6a:50:08:4e:b2:0c:62:de:cc:74:44 root@pcmk-1.clusterlabs.org

The key's randomart image is:
+--[ DSA 1024]----+
|==.ooEo..        |
|X O + .o o       |
| * A    +        |
|  +      .       |
| .      S        |
|                 |
|                 |
|                 |
|                 |
+-----------------+
[root@pcmk-1 ~]# cp .ssh/id_dsa.pub .ssh/authorized_keys
[root@pcmk-1 ~]#
图 2.21. 创​建​并​激​活​一​个​新​的​SSH密​钥​

在​其​他​节​点​安​装​这​个​密​钥​并​测​试​你​是​否​可​以​执​行​命​令​而​不​用​输​入​密​码​
[root@pcmk-1 ~]# scp -r .ssh pcmk-2:
The authenticity of host 'pcmk-2 (192.168.122.102)' can't be established.
RSA key fingerprint is b1:2b:55:93:f1:d9:52:2b:0f:f2:8a:4e:ae:c6:7c:9a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'pcmk-2,192.168.122.102' (RSA) to the list of known hosts.
root@pcmk-2's password: 
id_dsa.pub                           100%  616     0.6KB/s   00:00    
id_dsa                               100%  672     0.7KB/s   00:00    
known_hosts                          100%  400     0.4KB/s   00:00    
authorized_keys                      100%  616     0.6KB/s   00:00    
[root@pcmk-1 ~]# ssh pcmk-2 -- uname -n
pcmk-2
[root@pcmk-1 ~]#
图 2.22. 在​另​一​个​机​器​上​面​安​装​SSH密​钥​

2.4.3. 简​化​节​点​名​称​

在​安​装​过​程​中​,我​们​发​现​FQDN域​名​太​长​了​,不​利​于​在​日​志​或​状​态​界​面​中​查​看​,我​们​用​以​下​操​作​来​简​化​机​器​名​:
[root@pcmk-1 ~]# uname -n
pcmk-1.clusterlabs.org
[root@pcmk-1 ~]# dnsdomainname 
clusterlabs.org
第​二​个​命​令​的​输​出​是​正​常​的​,但​是​我​们​真​的​不​需​要​这​么​详​细​的​输​出​,我​们​更​改​/etc/sysconfig/network文​件​来​达​到​简​化​的​目​的​。​
[root@pcmk-1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=pcmk-1.clusterlabs.org
GATEWAY=192.168.122.1
我​们​要​做​的​只​是​要​把​域​名​后​面​的​部​分​去​掉​。​
[root@pcmk-1 ~]# sed -i.bak 's/\.[a-z].*//g' /etc/sysconfig/network
现​在​cat一​下​看​看​更​改​是​否​成​功​了​。​
[root@pcmk-1 ~]# cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=pcmk-1
GATEWAY=192.168.122.1
然​而​到​这​里​还​没​结​束​,机​器​还​没​接​受​新​的​配​置​文​件​,我​们​强​制​它​生​效​。​
[root@pcmk-1 ~]# source /etc/sysconfig/network
[root@pcmk-1 ~]# hostname $HOSTNAME
现​在​我​们​看​看​是​否​按​达​到​我​们​预​期​的​效​果​:
[root@pcmk-1 ~]# uname -n
pcmk-1
[root@pcmk-1 ~]# dnsdomainname 
clusterlabs.org
现​在​在​pcmk-2上​面​重​复​以​上​操​作​.

2.4.4. 配​置​ Corosync

选​择​一​个​组​播​[9]端​口​和​地​址​。​[10]
请​注​意​你​选​择​的​端​口​和​地​址​不​能​跟​已​存​在​的​集​群​冲​突​,关​于​组​播​地​址​的​选​择​,可​以​参​考​ http://www.29west.com/docs/THPM/multicast-address-assignment.html
在​这​个​文​档​中​,我​选​择​端​口​4000并​且​用​226.94.1.1作​为​组​播​地​址​:

重要

The instructions below only apply for a machine with a single NIC. If you have a more complicated setup, you should edit the configuration manually.
[root@pcmk-1 ~]# export ais_port=4000
[root@pcmk-1 ~]# export ais_mcast=226.94.1.1
然​后​我​们​用​下​面​的​命​令​自​动​获​得​机​器​的​地​址​。​为​了​让​配​置​文​件​能​够​在​机​器​上​面​的​各​个​机​器​通​用​,我​们​不​使​用​完​整​的​IP地​址​而​使​用​网​络​地​址​。​(译​者​注​:corosync配​置​文​件​中​的​监​听​地​址​一​项​可​以​填​写​网​络​地​址​,corosync会​自​动​匹​配​应​该​监​听​在​哪​个​地​址​而​不​是​0.0.0.0)
[root@pcmk-1 ~]# export ais_addr=`ip addr | grep "inet " | tail -n 1 | awk '{print $4}' | sed s/255/0/`
显​示​并​检​查​配​置​的​环​境​变​量​是​否​正​确​
[root@pcmk-1 ~]# env | grep ais_
ais_mcast=226.94.1.1
ais_port=4000
ais_addr=192.168.122.0
Once you're happy with the chosen values, update the Corosync configuration
[root@pcmk-1 ~]# cp /etc/corosync/corosync.conf.example /etc/corosync/corosync.conf
[root@pcmk-1 ~]# sed -i.bak "s/.*mcastaddr:.*/mcastaddr:\ $ais_mcast/g" /etc/corosync/corosync.conf
[root@pcmk-1 ~]# sed -i.bak "s/.*mcastport:.*/mcastport:\ $ais_port/g" /etc/corosync/corosync.conf
[root@pcmk-1 ~]# sed -i.bak "s/.*bindnetaddr:.*/bindnetaddr:\ $ais_addr/g" /etc/corosync/corosync.conf
Finally, tell Corosync to load the Pacemaker plugin.
[root@pcmk-1 ~]# cat <<-END >>/etc/corosync/service.d/pcmk
service {
        # Load the Pacemaker Cluster Resource Manager
        name: pacemaker
        ver:  1
}
END
The final configuration should look something like the sample in 附录 B, Sample Corosync Configuration.

重要

When run in version 1 mode, the plugin does not start the Pacemaker daemons. Instead it just sets up the quorum and messaging interfaces needed by the rest of the stack.
Starting the dameons occurs when the Pacemaker init script is invoked. This resolves two long standing issues:
  1. Forking inside a multi-threaded process like Corosync causes all sorts of pain. This has been problematic for Pacemaker as it needs a number of daemons to be spawned.
  2. Corosync was never designed for staggered shutdown - something previously needed in order to prevent the cluster from leaving before Pacemaker could stop all active resources.

2.4.5. 传​送​配​置​文​件​

然​后​我​们​把​配​置​文​件​拷​贝​到​其​他​节​点​:
[root@pcmk-1 ~]# for f in /etc/corosync/corosync.conf /etc/corosync/service.d/pcmk /etc/hosts; do scp $f pcmk-2:$f ; done
corosync.conf                            100% 1528     1.5KB/s   00:00
hosts                                    100%  281     0.3KB/s   00:00
[root@pcmk-1 ~]#

第 3 章 检​验​集​群​的​安​装​

3.1. 检​验​Corosync的​安​装​

在​第​一​个​节​点​启​动​Corosync:
[root@pcmk-1 ~]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
查​看​集​群​是​否​正​确​启​动​并​且​已​经​可​以​与​其​他​节​点​建​立​集​群​关​系​
[root@pcmk-1 ~]# grep -e "corosync.*network interface" -e "Corosync Cluster Engine" -e "Successfully read main configuration file" /var/log/messages
Aug 27 09:05:34 pcmk-1 corosync[1540]: [MAIN  ] Corosync Cluster Engine ('1.1.0'): started and ready to provide service.
Aug 27 09:05:34 pcmk-1 corosync[1540]: [MAIN  ] Successfully read main configuration file '/etc/corosync/corosync.conf'.
[root@pcmk-1 ~]# grep TOTEM /var/log/messages
Aug 27 09:05:34 pcmk-1 corosync[1540]: [TOTEM ] Initializing transport (UDP/IP).
Aug 27 09:05:34 pcmk-1 corosync[1540]: [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Aug 27 09:05:35 pcmk-1 corosync[1540]: [TOTEM ] The network interface [192.168.122.101] is now up.
Aug 27 09:05:35 pcmk-1 corosync[1540]: [TOTEM ] A processor joined or left the membership and a new membership was formed.
第​一​个​节​点​正​常​以​后​,我​们​可​以​安​全​地​启​动​第​二​个​节​点​。​
[root@pcmk-1 ~]# ssh pcmk-2 -- /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
[root@pcmk-1 ~]#
检​查​集​群​关​系​有​没​有​正​确​建​立​:
[root@pcmk-1 ~]# grep TOTEM /var/log/messages
Aug 27 09:05:34 pcmk-1 corosync[1540]: [TOTEM ] Initializing transport (UDP/IP).
Aug 27 09:05:34 pcmk-1 corosync[1540]: [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Aug 27 09:05:35 pcmk-1 corosync[1540]: [TOTEM ] The network interface [192.168.122.101] is now up.
Aug 27 09:05:35 pcmk-1 corosync[1540]: [TOTEM ] A processor joined or left the membership and a new membership was formed.
Aug 27 09:12:11 pcmk-1 corosync[1540]: [TOTEM ] A processor joined or left the membership and a new membership was formed.

3.2. 检​查​Pacemaker的​安​装​

现​在​我​们​已​经​确​认​Corosync正​常​,我​们​可​以​开​始​检​查​其​他​部​分​是​否​正​常​.
[root@pcmk-1 ~]# grep pcmk_startup /var/log/messages
Aug 27 09:05:35 pcmk-1 corosync[1540]:   [pcmk  ] info: pcmk_startup: CRM: Initialized
Aug 27 09:05:35 pcmk-1 corosync[1540]:   [pcmk  ] Logging: Initialized pcmk_startup
Aug 27 09:05:35 pcmk-1 corosync[1540]:   [pcmk  ] info: pcmk_startup: Maximum core file size is: 18446744073709551615
Aug 27 09:05:35 pcmk-1 corosync[1540]:   [pcmk  ] info: pcmk_startup: Service: 9
Aug 27 09:05:35 pcmk-1 corosync[1540]:   [pcmk  ] info: pcmk_startup: Local hostname: pcmk-1
Now try starting Pacemaker and check the necessary processes have been started
[root@pcmk-1 ~]# /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]
[root@pcmk-1 ~]# grep -e pacemakerd.*get_config_opt -e pacemakerd.*start_child -e "Starting Pacemaker" /var/log/messages
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found 'pacemaker' for option: name
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found '1' for option: ver
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Defaulting to 'no' for option: use_logd
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Defaulting to 'no' for option: use_mgmtd
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found 'on' for option: debug
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found 'yes' for option: to_logfile
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found '/var/log/corosync.log' for option: logfile
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found 'yes' for option: to_syslog
Feb  8 13:31:24 pcmk-1 pacemakerd: [13155]: info: get_config_opt: Found 'daemon' for option: syslog_facility
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: main: Starting Pacemaker 1.1.5 (Build: 31f088949239+):  docbook-manpages publican ncurses trace-logging cman cs-quorum heartbeat corosync snmp libesmtp
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14022 for process stonith-ng
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14023 for process cib
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14024 for process lrmd
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14025 for process attrd
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14026 for process pengine
Feb  8 16:50:38 pcmk-1 pacemakerd: [13990]: info: start_child: Forked child 14027 for process crmd
[root@pcmk-1 ~]# ps axf
  PID TTY      STAT   TIME COMMAND
    2 ?        S<     0:00 [kthreadd]
    3 ?        S<     0:00  \_ [migration/0]
... lots of processes ...
 13990 ?    S       0:01 pacemakerd
 14022 ?    Sa      0:00  \_ /usr/lib64/heartbeat/stonithd
 14023 ?    Sa      0:00  \_ /usr/lib64/heartbeat/cib
 14024 ?    Sa      0:00  \_ /usr/lib64/heartbeat/lrmd
 14025 ?    Sa      0:00  \_ /usr/lib64/heartbeat/attrd
 14026 ?    Sa      0:00  \_ /usr/lib64/heartbeat/pengine
 14027 ?    Sa      0:00  \_ /usr/lib64/heartbeat/crmd
Next, check for any ERRORs during startup - there shouldn’​t be any.
[root@pcmk-1 ~]# grep ERROR: /var/log/messages | grep -v unpack_resources
[root@pcmk-1 ~]#
Repeat on the other node and display the cluster's status.
[root@pcmk-1 ~]# ssh pcmk-2 -- /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Aug 27 16:54:55 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
0 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

第 4 章 使​用​Pacemaker工​具​

在​万​恶​的​旧​社​会​,配​置​Pacemaker需​要​管​理​员​具​备​读​写​XML的​能​力​。​ 根​据​UNIX精​神​,也​有​许​多​不​同​的​查​询​和​配​置​集​群​的​命​令​。​
自​从​Pacemaker 1.0,这​一​切​都​改​变​了​,我​们​有​了​一​个​集​成​的​脚​本​化​的​集​群​控​制​shell,它​把​麻​烦​的​XML配​置​隐​藏​了​起​来​。​它​甚​至​允​许​你​一​次​做​出​许​多​修​改​并​自​动​提​交​(并​检​测​是​否​合​法​)。​
让​我​们​花​点​时​间​熟​悉​一​下​它​能​做​什​么​。​
[root@pcmk-1 ~]# crm --help

usage:
    crm [-D display_type]
    crm [-D display_type] args
    crm [-D display_type] [-f file]

    Use crm without arguments for an interactive session.
    Supply one or more arguments for a "single-shot" use.
    Specify with -f a file which contains a script. Use '-' for
    standard input or use pipe/redirection.

    crm displays cli format configurations using a color scheme
    and/or in uppercase. Pick one of "color" or "uppercase", or
    use "-D color,uppercase" if you want colorful uppercase.
    Get plain output by "-D plain". The default may be set in
    user preferences (options).

Examples:

    # crm -f stopapp2.cli
    # crm < stopapp2.cli
    # crm resource stop global_www
    # crm status
监​控​集​群​状​态​的​主​要​命​令​是​ crm_mon(跟​crm status是​一​样​的​效​果​)。​它​可​以​运​行​在​很​多​模​式​下​并​且​有​许​多​输​出​选​项​。​如​果​要​查​看​Pacemaker相​应​的​工​具​,可​以​通​过​--help或​者​man pages来​查​看​。​这​些​输​出​都​是​靠​命​令​来​生​成​的​,所​以​它​总​是​会​在​各​个​节​点​和​工​具​之​间​同​步​。​
此​外​,Pacemaker的​版​本​和​支​持​的​stack(本​文​中​是​corosync)可​以​通​过​ --version选​项​看​到​
[root@pcmk-1 ~]# crm_mon --version
Pacemaker 1.1.5
Written by Andrew Beekhof
[root@pcmk-1 ~]# crm_mon --help
crm_mon - Provides a summary of cluster's current state.

Outputs varying levels of detail in a number of different formats.

Usage: crm_mon mode [options]
Options:
 -?, --help                 This text
 -$, --version              Version information
 -V, --verbose              Increase debug output

Modes:
 -h, --as-html=value        Write cluster status to the named file
 -w, --web-cgi              Web mode with output suitable for cgi
 -s, --simple-status        Display the cluster status once as a simple one line output (suitable for nagios)
 -S, --snmp-traps=value     Send SNMP traps to this station
 -T, --mail-to=value        Send Mail alerts to this user.  See also --mail-from, --mail-host, --mail-prefix

Display Options:
 -n, --group-by-node        Group resources by node
 -r, --inactive             Display inactive resources
 -f, --failcounts           Display resource fail counts
 -o, --operations           Display resource operation history
 -t, --timing-details       Display resource operation history with timing details


Additional Options:
 -i, --interval=value           Update frequency in seconds
 -1, --one-shot                 Display the cluster status once on the console and exit
 -N, --disable-ncurses          Disable the use of ncurses
 -d, --daemonize                Run in the background as a daemon
 -p, --pid-file=value           (Advanced) Daemon pid file location
 -F, --mail-from=value          Mail alerts should come from the named user
 -H, --mail-host=value          Mail alerts should be sent via the named host
 -P, --mail-prefix=value        Subjects for mail alerts should start with this string
 -E, --external-agent=value     A program to run when resource operations take place.
 -e, --external-recipient=value A recipient for your program (assuming you want the program to send something to someone).

Examples:

Display the cluster´s status on the console with updates as they occur:
        # crm_mon

Display the cluster´s status on the console just once then exit:
        # crm_mon -1

Display your cluster´s status, group resources by node, and include inactive resources in the list:
        # crm_mon --group-by-node --inactive

Start crm_mon as a background daemon and have it write the cluster´s status to an HTML file:
        # crm_mon --daemonize --as-html /path/to/docroot/filename.html

Start crm_mon as a background daemon and have it send email alerts:
        # crm_mon --daemonize --mail-to user@example.com --mail-host mail.example.com

Start crm_mon as a background daemon and have it send SNMP alerts:
        # crm_mon --daemonize --snmp-traps snmptrapd.example.com

Report bugs to pacemaker@oss.clusterlabs.org

注意

如​果​SNMP或​者​email选​项​没​有​出​现​在​选​项​中​,说​明​pacemaker编​译​的​时​候​没​有​打​开​对​他​们​的​支​持​,你​需​要​联​系​提​供​这​个​发​行​版​本​的​人​,或​者​自​己​编​译​。​

第 5 章 创​建​一​个​主​/备​集​群​

5.1. 浏​览​现​有​配​置​

当​Pacemaker启​动​的​时​候​,它​会​自​动​记​录​节​点​的​数​量​和​详​细​信​息​,以​及​基​层​软​件​(本​文​中​是​corosync)和​Pacemaker的​版​本​。​
这​是​初​始​配​置​文​件​的​模​样​:
[root@pcmk-2 ~]# crm configure show
node pcmk-1
node pcmk-2
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2"
如​果​有​谁​想​看​看​XML格​式​的​,你​可​以​添​加​xml选​项​来​看​到​原​始​的​配​置​文​件​
[root@pcmk-2 ~]# crm configure show xml
<?xml version="1.0" ?>
<cib admin_epoch="0" crm_feature_set="3.0.1" dc-uuid="pcmk-1" epoch="13" have-quorum="1" num_updates="7" validate-with="pacemaker-1.0">
  <configuration>
    <crm_config>
      <cluster_property_set id="cib-bootstrap-options">
        <nvpair id="cib-bootstrap-options-dc-version" name="dc-version" value="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f"/>
        <nvpair id="cib-bootstrap-options-cluster-infrastructure" name="cluster-infrastructure" value="openais"/>
        <nvpair id="cib-bootstrap-options-expected-quorum-votes" name="expected-quorum-votes" value="2"/>
      </cluster_property_set>
    </crm_config>
    <rsc_defaults/>
    <op_defaults/>
    <nodes>
      <node id="pcmk-1" type="normal" uname="pcmk-1"/>
      <node id="pcmk-2" type="normal" uname="pcmk-2"/>
    </nodes>
    <resources/>
    <constraints/>
  </configuration>
</cib>
这​是​本​文​档​最​后​一​次​显​示​XML。​(作​者​怨​念​很​深​啊​)
在​我​们​做​出​任​何​改​变​之​前​,我​们​最​好​检​查​下​配​置​文​件​。​
[root@pcmk-1 ~]# crm_verify -L
crm_verify[2195]: 2009/08/27_16:57:12 ERROR: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
crm_verify[2195]: 2009/08/27_16:57:12 ERROR: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
crm_verify[2195]: 2009/08/27_16:57:12 ERROR: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
  -V may provide more details
[root@pcmk-1 ~]#
就​像​你​看​到​的​,这​个​工​具​发​现​了​一​些​错​误​。​
为​了​确​保​您​数​据​的​安​全​性​ [11] ,请​使​用​配​备​STONITH [12]的​Pacemaker。​但​是​当​没​有​配​置​STONITH的​时​候​也​会​报​这​个​错​误​(因​为​当​集​群​中​某​个​节​点​需​要​被​隔​离​的​时​候​,集​群​就​无​法​工​作​了​)。​
目​前​,我​们​禁​用​这​个​特​性​,然​后​在​ 配​置​STONISH 章​节​来​配​置​它​。​这​里​要​指​出​,使​用​STONITH是​非​常​有​必​要​的​。​关​闭​这​个​特​性​就​是​告​诉​集​群​:假​装​故​障​的​节​点​已​经​安​全​的​关​机​了​。​一​些​供​应​商​甚​至​不​允​许​这​个​特​性​被​关​闭​。​
我​们​将​ stonith-enabled设​置​为​ false 来​关​闭​STONITH
crm configure property stonith-enabled=false
crm_verify -L
设​置​完​这​个​选​项​以​后​,校​验​配​置​文​件​就​正​常​了​。​

警告

The use of stonith-enabled=false is completely inappropriate for a production cluster. We use it here to defer the discussion of its configuration which can differ widely from one installation to the next. See 第 9 章 配​置​ STONITH for information on why STONITH is important and details on how to configure it.

5.2. 添​加​一​个​资​源​

首​先​要​做​的​是​配​置​一​个​IP地​址​,不​管​集​群​服​务​在​哪​运​行​,我​们​要​一​个​固​定​的​地​址​来​提​供​服​务​。​在​这​里​我​选​择​192.168.122.101作​为​浮​动​IP,给​它​取​一​个​好​记​的​名​字​ ClusterIP 并​且​告​诉​集​群​ 每​30秒​检​查​它​一​次​

重要

选​择​的​IP地​址​不​能​被​节​点​所​占​用​
crm configure primitive ClusterIP ocf:heartbeat:IPaddr2 \ 
        params ip=192.168.122.101 cidr_netmask=32 \ 
        op monitor interval=30s
另​外​一​个​重​要​的​信​息​是​ ocf:heartbeat:IPaddr2。​这​告​诉​Pacemaker三​件​事​情​,第​一​个​部​分​,ocf,指​明​了​这​个​资​源​采​用​的​标​准​(类​型​)以​及​在​哪​能​找​到​它​。​第​二​个​部​分​标​明​这​个​资​源​脚​本​的​在​OCF中​的​名​字​空​间​,在​这​个​例​子​中​是​heartbeat。​最​后​一​个​部​分​指​明​了​资​源​脚​本​的​名​称​。​
可​以​运​行​下​面​的​命​令​来​获​得​可​用​的​资​源​类​
[root@pcmk-1 ~]# crm ra classes
heartbeat
lsb
ocf / heartbeat pacemaker
stonith
找​到​OCF中​Pacemaker和​Heartbeat提​供​的​资​源​脚​本​,运​行​下​面​的​命​令​
[root@pcmk-1 ~]# crm ra list ocf pacemaker
ClusterMon     Dummy          Stateful       SysInfo        SystemHealth   controld
ping           pingd          
[root@pcmk-1 ~]# crm ra list ocf heartbeat
AoEtarget              AudibleAlarm           ClusterMon             Delay
Dummy                  EvmsSCC                Evmsd                  Filesystem
ICP                    IPaddr                 IPaddr2                IPsrcaddr
LVM                    LinuxSCSI              MailTo                 ManageRAID
ManageVE               Pure-FTPd              Raid1                  Route
SAPDatabase            SAPInstance            SendArp                ServeRAID
SphinxSearchDaemon     Squid                  Stateful               SysInfo
VIPArip                VirtualDomain          WAS                    WAS6
WinPopup               Xen                    Xinetd                 anything
apache                 db2                    drbd                   eDir88
iSCSILogicalUnit       iSCSITarget            ids                    iscsi
ldirectord             mysql                  mysql-proxy            nfsserver
oracle                 oralsnr                pgsql                  pingd
portblock              rsyncd                 scsi2reservation       sfex
tomcat                 vmware                 
[root@pcmk-1 ~]#
现​在​检​查​下​IP 资​源​是​不​是​已​经​添​加​了​,并​且​看​看​是​否​处​在​可​用​状​态​。​
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive ClusterIP ocf:heartbeat:IPaddr2 \
 params ip="192.168.122.101" cidr_netmask="32" \
 op monitor interval="30s"
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 15:23:48 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]
ClusterIP (ocf::heartbeat:IPaddr): Started pcmk-1

5.3. 做​一​次​失​效​备​援​

作​为​一​个​高​可​用​的​集​群​,我​们​在​继​续​本​文​档​之​前​,我​们​要​需​要​测​试​失​效​备​援​ 。​
首​先​,找​到​IP资​源​现​在​在​哪​个​节​点​上​运​行​。​
[root@pcmk-1 ~]# crm resource status ClusterIP
resource ClusterIP is running on: pcmk-1
[root@pcmk-1 ~]#
Shut down Pacemaker and Corosync on that machine.
[root@pcmk-1 ~]# ssh pcmk-1 -- /etc/init.d/pacemaker stop
Signaling Pacemaker Cluster Manager to terminate: [ OK ]
Waiting for cluster services to unload:. [ OK ]
[root@pcmk-1 ~]# ssh pcmk-1 -- /etc/init.d/corosync stop
Stopping Corosync Cluster Engine (corosync): [ OK ]
Waiting for services to unload: [ OK ]
[root@pcmk-1 ~]#
当​Corosync停​止​运​行​以​后​,我​们​到​另​外​一​个​节​点​用​crm_mon来​检​查​集​群​状​态​.
[root@pcmk-2 ~]# crm_mon
============
Last updated: Fri Aug 28 15:27:35 2009
Stack: openais
Current DC: pcmk-2 - partition WITHOUT quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============

Online: [ pcmk-2 ]
OFFLINE: [ pcmk-1 ]
关​于​集​群​状​态​,我​们​有​三​个​地​方​需​要​注​意​,首​先​,如​我​们​所​料​pcmk-1已​经​下​线​了​,然​而​我​们​发​现​ClusterIP不​在​任​何​地​方​运​行​!

5.3.1. 法​定​人​数​和​双​节​点​集​群​

这​是​因​为​集​群​已​经​达​不​到​“​法​定​人​数​”​了​,就​像​我​们​看​到​的​“​partition WITHOUT quorum”​ (用​绿​色​强​调​的​)。​为​了​避​免​数​据​遭​到​破​坏​,当​Pacemaker发​现​集​群​达​不​到​法​定​人​数​时​,就​会​停​止​所​有​的​资​源​。​
当​有​半​数​以​上​的​节​点​在​线​时​,这​个​集​群​就​认​为​自​己​拥​有​法​定​人​数​了​,是​“​合​法​”​的​,换​而​言​之​就​是​下​面​的​公​式​:
total_nodes - 1 < 2 * active_nodes
因​此​在​双​节​点​的​集​群​中​,只​有​当​两​者​都​在​线​时​才​是​合​法​的​。​ 这​个​规​则​会​让​ 双​节​点​的​集​群​ 毫​无​意​义​,但​是​我​们​可​以​控​制​Pacemaker发​现​集​群​达​不​到​法​定​人​数​时​候​的​行​为​。​简​单​来​说​,我​们​告​诉​集​群​忽​略​它​ 。​
[root@pcmk-1 ~]# crm configure property no-quorum-policy=ignore
[root@pcmk-1 ~]# crm configure show 
node pcmk-1
node pcmk-2
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
过​了​一​会​,集​群​会​在​剩​下​的​那​个​节​点​上​启​动​这​个​IP。​请​注​意​集​群​现​在​依​然​没​有​达​到​法​定​人​数​。​
[root@pcmk-2 ~]# crm_mon
============
Last updated: Fri Aug 28 15:30:18 2009
Stack: openais
Current DC: pcmk-2 - partition WITHOUT quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ pcmk-2 ]
OFFLINE: [ pcmk-1 ]

ClusterIP (ocf::heartbeat:IPaddr): Started pcmk-2
现​在​模​拟​节​点​恢​复​,我​们​启​动​ pcmk-1 上​面​的​Corosync服​务​,然​后​检​查​集​群​状​态​。​
[root@pcmk-1 ~]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]      
[root@pcmk-1 ~]# /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 15:32:13 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============
Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
现​在​我​们​可​以​看​到​让​某​些​人​惊​奇​的​事​情​,IP资​源​回​到​原​来​那​个​节​点​(pcmk-1)上​去​了​。​

5.3.2. 防​止​资​源​在​节​点​恢​复​后​移​动​

一​些​环​境​中​会​要​求​尽​量​避​免​资​源​在​节​点​之​间​移​动​。​移​动​资​源​通​常​意​味​着​一​段​时​间​内​无​法​提​供​服​务​,某​些​复​杂​的​服​务​,比​如​Oracle数​据​库​,这​个​时​间​可​能​会​很​长​。​
为​了​达​到​这​个​效​果​,Pacemaker 有​一​个​叫​做​ 资​源​黏​性​值​ 的​概​念​,它​能​够​控​制​一​个​服​务​(资​源​)有​多​想​呆​在​它​正​在​运​行​的​节​点​上​。​你​可​以​把​它​认​为​是​无​法​提​供​服​务​的​“​代​价​”​[13]”​。​ Pacemaker为​了​达​到​最​优​分​布​各​个​资​源​的​目​的​,默​认​设​置​这​个​值​为​0。​我​们​可​以​为​每​个​资​源​定​义​不​同​的​黏​性​值​,但​一​般​来​说​,更​改​默​认​黏​性​值​就​够​了​。​
crm configure rsc_defaults resource-stickiness=100
[root@pcmk-2 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
 resource-stickiness="100"
现​在​我​们​重​新​尝​试​失​效​援​备​测​试​,我​们​可​以​看​到​,正​如​我​们​所​料​,当​pcmk-1不​在​线​的​时​候​ClusterIP还​是​移​动​到​了​pcmk-2
[root@pcmk-1 ~]# ssh pcmk-1 -- /etc/init.d/pacemaker stop
Signaling Pacemaker Cluster Manager to terminate:          [  OK  ]
Waiting for cluster services to unload:.                   [  OK  ]
[root@pcmk-1 ~]# ssh pcmk-1 -- /etc/init.d/corosync stop
Stopping Corosync Cluster Engine (corosync):               [  OK  ]
Waiting for services to unload:                            [  OK  ]
[root@pcmk-1 ~]# ssh pcmk-2 -- crm_mon -1
============
Last updated: Fri Aug 28 15:39:38 2009
Stack: openais
Current DC: pcmk-2 - partition WITHOUT quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============

Online: [ pcmk-2 ]
OFFLINE: [ pcmk-1 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
但​是​当​我​们​把​pcmk-1恢​复​在​线​后​,ClusterIP现​在​还​是​跑​在​pcmk-2上​面​。​
[root@pcmk-1 ~]# /etc/init.d/corosync start
Starting Corosync Cluster Engine (corosync): [ OK ]
[root@pcmk-1 ~]# /etc/init.d/pacemaker start
Starting Pacemaker Cluster Manager: [ OK ]
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 15:41:23 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
1 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2


[11] 如​果​数​据​是​损​坏​的​,那​保​证​它​的​可​用​性​是​没​有​意​义​的​

[12] 一​个​常​见​的​隔​离​手​段​。​用​关​掉​坏​节​点​电​源​的​办​法​来​保​证​数​据​完​整​

[13] 这​里​要​注​意​的​是​Pacemaker定​义​的​代​价​跟​人​们​所​想​的​不​一​样​。​如​果​管​理​员​没​有​明​确​的​指​定​参​数​(创​建​稳​定​环​境​所​必​须​的​),那​么​资​源​个​节​点​在​Pacemaker处​理​列​表​中​的​顺​序​会​隐​式​地​创​建​参​数​

第 6 章 Apache - 添​加​更​多​的​服​务​

注意

现​在​我​们​有​了​一​个​基​本​的​但​是​功​能​齐​全​的​双​节​点​集​群​,我​们​已​经​可​以​往​里​面​加​些​真​的​服​务​了​。​我​们​准​备​启​动​一​个​Apache服​务​,因​为​它​是​许​多​集​群​的​主​角​,并​且​相​对​来​说​比​较​容​易​配​置​。​

6.1. 安​装​Apache

在​继​续​之​前​,我​们​先​确​保​两​个​节​点​都​安​装​了​Apache.
[root@ppcmk-1 ~]# yum install -y httpd
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.2.13-2.fc12 set to be updated
--> Processing Dependency: httpd-tools = 2.2.13-2.fc12 for package: httpd-2.2.13-2.fc12.x86_64
--> Processing Dependency: apr-util-ldap for package: httpd-2.2.13-2.fc12.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.2.13-2.fc12.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.2.13-2.fc12.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.2.13-2.fc12.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.3.9-2.fc12 set to be updated
---> Package apr-util.x86_64 0:1.3.9-2.fc12 set to be updated
---> Package apr-util-ldap.x86_64 0:1.3.9-2.fc12 set to be updated
---> Package httpd-tools.x86_64 0:2.2.13-2.fc12 set to be updated
---> Package mailcap.noarch 0:2.1.30-1.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=======================================================================================
 Package               Arch             Version                Repository         Size
=======================================================================================
Installing:
 httpd               x86_64           2.2.13-2.fc12            rawhide           735 k
Installing for dependencies:
 apr                 x86_64           1.3.9-2.fc12             rawhide           117 k
 apr-util            x86_64           1.3.9-2.fc12             rawhide            84 k
 apr-util-ldap       x86_64           1.3.9-2.fc12             rawhide            15 k
 httpd-tools         x86_64           2.2.13-2.fc12            rawhide            63 k
 mailcap             noarch           2.1.30-1.fc12            rawhide            25 k

Transaction Summary
=======================================================================================
Install       6 Package(s)
Upgrade       0 Package(s)

Total download size: 1.0 M
Downloading Packages:
(1/6): apr-1.3.9-2.fc12.x86_64.rpm                                   | 117 kB     00:00     
(2/6): apr-util-1.3.9-2.fc12.x86_64.rpm                              |  84 kB     00:00     
(3/6): apr-util-ldap-1.3.9-2.fc12.x86_64.rpm                         |  15 kB     00:00     
(4/6): httpd-2.2.13-2.fc12.x86_64.rpm                                | 735 kB     00:00     
(5/6): httpd-tools-2.2.13-2.fc12.x86_64.rpm                          |  63 kB     00:00     
(6/6): mailcap-2.1.30-1.fc12.noarch.rpm                              |  25 kB     00:00     
----------------------------------------------------------------------------------------
Total                                                       875 kB/s | 1.0 MB     00:01     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : apr-1.3.9-2.fc12.x86_64                                          1/6 
  Installing     : apr-util-1.3.9-2.fc12.x86_64                                     2/6 
  Installing     : apr-util-ldap-1.3.9-2.fc12.x86_64                                3/6 
  Installing     : httpd-tools-2.2.13-2.fc12.x86_64                                 4/6 
  Installing     : mailcap-2.1.30-1.fc12.noarch                                     5/6 
  Installing     : httpd-2.2.13-2.fc12.x86_64                                       6/6 

Installed:
  httpd.x86_64 0:2.2.13-2.fc12                                                          

Dependency Installed:
  apr.x86_64 0:1.3.9-2.fc12            apr-util.x86_64 0:1.3.9-2.fc12
  apr-util-ldap.x86_64 0:1.3.9-2.fc12  httpd-tools.x86_64 0:2.2.13-2.fc12
  mailcap.noarch 0:2.1.30-1.fc12  

Complete!
[root@pcmk-1 ~]#
同​样​的​,为​了​检​测​Apache服​务​器​,我​们​要​安​装​wget这​个​工​具​。​
[root@pcmk-1 ~]# yum install -y wget
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package wget.x86_64 0:1.11.4-5.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
 Package        Arch             Version                      Repository               Size
===========================================================================================
Installing:
 wget          x86_64          1.11.4-5.fc12                   rawhide                393 k

Transaction Summary
===========================================================================================
Install       1 Package(s)
Upgrade       0 Package(s)

Total download size: 393 k
Downloading Packages:
wget-1.11.4-5.fc12.x86_64.rpm                                            | 393 kB     00:00     
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : wget-1.11.4-5.fc12.x86_64                                            1/1 

Installed:
  wget.x86_64 0:1.11.4-5.fc12

Complete!
[root@pcmk-1 ~]#

6.2. 准​备​工​作​

首​先​我​们​为​Apache创​建​一​个​主​页​。​在​Fedora上​面​默​认​的​Apache docroot是​/var/www/html,所​以​我​们​在​这​个​目​录​下​面​建​立​一​个​主​页​。​
[root@pcmk-1 ~]# cat <<-END >/var/www/html/index.html
 <html>
 <body>My Test Site - pcmk-1</body>
 </html>
 END
[root@pcmk-1 ~]#
为​了​方​便​,我​们​简​化​所​用​的​页​面​并​人​工​地​在​两​个​节​点​直​接​同​步​数​据​。​所​以​在​pcmk-2上​面​运​行​这​个​命​令​。​
[root@pcmk-2 ~]# cat <<-END >/var/www/html/index.html
 <html>
 <body>My Test Site - pcmk-2</body>
 </html>
 END
[root@pcmk-2 ~]#

6.3. 开​启​ Apache status URL

为​了​监​控​Apache实​例​的​健​康​状​态​,并​在​它​挂​掉​的​时​候​恢​复​Apache服​务​,资​源​agent会​假​设​ server-status URL是​可​用​的​。​查​看​/etc/httpd/conf/httpd.conf并​确​保​下​面​的​选​项​没​有​被​禁​用​或​注​释​掉​。​
<Location /server-status>
   SetHandler server-status
   Order deny,allow
   Deny from all
   Allow from 127.0.0.1
</Location>

6.4. 更​新​配​置​文​件​

现​在​ ,Apache已​经​可​以​添​加​到​集​群​中​了​。​我​们​管​这​个​资​源​叫​WebSite。​我​们​需​要​用​一​个​叫​做​apache的​OCF脚​本​,这​个​脚​本​在​heartbeat这​个​名​字​空​间​里​,唯​一​一​个​需​要​设​定​的​参​数​就​是​Apache的​主​配​置​文​件​路​径​,并​且​我​们​告​诉​集​群​每​一​分​钟​检​测​一​次​Apache是​否​运​行​。​
[root@pcmk-1 ~]# crm configure primitive WebSite ocf:heartbeat:apache params configfile=/etc/httpd/conf/httpd.conf op monitor interval=1min
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
 params configfile="/etc/httpd/conf/httpd.conf" \
 op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
过​了​一​会​,我​们​可​以​看​到​集​群​把​apache启​动​起​来​了​。​
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 16:12:49 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
WebSite        (ocf::heartbeat:apache):        Started pcmk-1
等​等​!WebSite这​个​资​源​跟​IP没​有​跑​在​同​一​个​节​点​上​面​!

6.5. 确​保​资​源​在​同​一​个​节​点​运​行​

为​了​减​少​每​个​机​器​的​负​载​,Pacemaker会​智​能​地​尝​试​将​资​源​分​散​到​各​个​节​点​上​面​。​ 然​而​我​们​可​以​告​诉​集​群​某​两​个​资​源​是​有​联​系​并​且​要​在​同​一​个​节​点​运​行​(或​不​同​的​节​点​运​行​)。​这​里​我​们​告​诉​集​群​WebSite只​能​在​有​ClusterIP的​节​点​上​运​行​。​如​果​ClusterIP在​哪​个​节​点​都​不​存​在​,那​么​WebSite也​不​能​运​行​。​
[root@pcmk-1 ~]# crm configure colocation website-with-ip INFINITY: WebSite ClusterIP
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
colocation website-with-ip inf: WebSite ClusterIP
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 16:14:34 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
WebSite        (ocf::heartbeat:apache):        Started pcmk-2

6.6. 控​制​资​源​的​启​动​停​止​顺​序​

当​Apache启​动​了​,它​跟​可​用​的​IP绑​在​了​一​起​。​它​不​会​知​道​我​们​后​来​添​加​的​IP,所​以​我​们​不​仅​需​要​控​制​他​们​在​相​同​的​节​点​运​行​,也​要​确​保​ClusterIP在​WebSite之​前​就​启​动​了​。​我​们​用​添​加​ordering约​束​来​达​到​这​个​效​果​。​我​们​需​要​给​这​个​order取​个​名​字​(apache-after-ip之​类​ 描​述​性​的​),并​指​出​他​是​托​管​的​(这​样​当​ClusterIP恢​复​了​,同​时​会​触​发​WebSite的​恢​复​) 并​且​写​明​了​这​两​个​资​源​的​启​动​顺​序​。​
[root@pcmk-1 ~]# crm configure order apache-after-ip mandatory: ClusterIP WebSite
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
colocation website-with-ip inf: WebSite ClusterIP
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"

6.7. 指​定​优​先​的​ Location

Pacemaker 并​不​要​求​你​机​器​的​硬​件​配​置​是​相​同​的​,可​能​某​些​机​器​比​另​外​的​机​器​配​置​要​好​。​这​种​状​况​下​我​们​会​希​望​设​置​:当​某​个​节​点​可​用​时​,资​源​就​要​跑​在​上​面​之​类​的​规​则​。​为​了​达​到​这​个​效​果​我​们​创​建​location约​束​。​同​样​的​,我​们​给​他​取​一​个​描​述​性​的​名​字​(prefer-pcmk-1),指​明​我​们​想​在​上​面​跑​WebSite这​个​服​务​,多​想​在​上​面​跑​(我​们​现​在​指​定​分​值​为​50,但​是​在​双​节​点​的​集​群​状​态​下​,任​何​大​于​0的​值​都​可​以​达​到​想​要​的​效​果​),以​及​目​标​节​点​的​名​字​:
[root@pcmk-1 ~]# crm configure location prefer-pcmk-1 WebSite 50: pcmk-1
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation website-with-ip inf: WebSite ClusterIP
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 16:17:35 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
WebSite        (ocf::heartbeat:apache):        Started pcmk-2
等​等​,资​源​还​是​在​pcmk-2上​面​跑​的​!
即​使​我​们​更​希​望​资​源​在​pcmk-1上​面​运​行​,但​是​ 这​个​优​先​值​还​是​比​资​源​黏​性​值​要​小​。​
如​果​要​看​现​在​的​分​值​,可​以​用​ptest这​个​命​令​
ptest -sL

注意

Include output
这​里​有​个​办​法​强​制​地​移​动​资​源​

6.8. 在​集​群​中​手​工​地​移​动​资​源​

经​常​性​的​会​有​管​理​员​想​要​无​视​集​群​然​后​强​制​把​资​源​移​动​到​指​定​的​地​方​。​ 底​层​的​操​作​就​像​我​们​上​面​创​建​的​location约​束​一​样​。​只​要​提​供​资​源​和​目​标​地​址​,我​们​会​补​全​剩​余​部​分​。​
[root@pcmk-1 ~]# crm resource move WebSite pcmk-1
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 16:19:24 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
WebSite        (ocf::heartbeat:apache):        Started pcmk-1
Notice how the colocation rule we created has ensured that ClusterIP was also moved to pcmk-1.
For the curious, we can see the effect of this command by examining the configuration
crm configure show
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
location cli-prefer-WebSite WebSite \
 rule $id="cli-prefer-rule-WebSite" inf: #uname eq pcmk-1
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation website-with-ip inf: WebSite ClusterIP
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
斜​体​部​分​是​用​来​移​动​资​源​到​pcmk-1约​束​,它​是​自​动​生​成​的​。​

6.8.1. 把​控​制​权​交​还​给​集​群​

当​我​们​完​成​那​些​要​求​要​资​源​移​动​到​pcmk-1的​操​作​--在​我​们​的​例​子​里​面​啥​都​没​干​ --我​们​可​以​用​unmove命​令​把​集​群​恢​复​到​强​制​移​动​前​的​状​态​。​因​为​我​们​之​前​配​置​了​默​认​的​资​源​黏​性​值​,恢​复​了​以​后​资​源​还​是​会​在​pcmk-1上​面​。​
[root@pcmk-1 ~]# crm resource unmove WebSite
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation website-with-ip inf: WebSite ClusterIP
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes="2" \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness="100"
可​以​看​到​自​动​生​成​的​约​束​已​经​没​有​了​。​如​果​我​们​查​看​集​群​的​状​态​,我​们​也​可​以​看​到​就​如​我​们​所​预​期​的​,资​源​还​是​在​pcmk-1上​面​跑​
[root@pcmk-1 ~]# crm_mon
============
Last updated: Fri Aug 28 16:20:53 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
2 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

 ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
 WebSite        (ocf::heartbeat:apache):        Started pcmk-1

第 7 章 用​DRBD同​步​存​储​

就​算​你​用​的​是​静​态​站​点​,手​工​在​各​个​节​点​之​间​同​步​文​件​也​不​是​个​好​主​意​。​如​果​是​动​态​站​点​,那​根​本​不​会​考​虑​这​个​。​用​NAS不​是​所​有​人​都​能​负​担​得​起​,但​是​有​些​数​据​还​是​要​同​步​。​用​用​DRBD: 它​被​认​为​是​网​络​RAID-1。​访​问​ See http://www.drbd.org/获​得​更​详​细​介​绍​

7.1. 安​装​DRBD软​件​包​

在​2.6.33以​上​的​内​核​中​,所​以​DRBD要​的​东​西​都​在​ Fedora 13中​存​在​了​,你​只​要​安​装​它​就​好​了​。​
[root@pcmk-1 ~]# yum install -y drbd-pacemaker
Loaded plugins: presto, refresh-packagekit
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package drbd-pacemaker.x86_64 0:8.3.7-2.fc13 set to be updated
--> Processing Dependency: drbd-utils = 8.3.7-2.fc13 for package: drbd-pacemaker-8.3.7-2.fc13.x86_64
--> Running transaction check
---> Package drbd-utils.x86_64 0:8.3.7-2.fc13 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=================================================================================
 Package                Arch           Version              Repository      Size
=================================================================================
Installing:
 drbd-pacemaker         x86_64         8.3.7-2.fc13         fedora          19 k
Installing for dependencies:
 drbd-utils             x86_64         8.3.7-2.fc13         fedora         165 k

Transaction Summary
=================================================================================
Install       2 Package(s)
Upgrade       0 Package(s)

Total download size: 184 k
Installed size: 427 k
Downloading Packages:
Setting up and reading Presto delta metadata
fedora/prestodelta                                        | 1.7 kB     00:00     
Processing delta metadata
Package(s) data still to download: 184 k
(1/2): drbd-pacemaker-8.3.7-2.fc13.x86_64.rpm             |  19 kB     00:01     
(2/2): drbd-utils-8.3.7-2.fc13.x86_64.rpm                 | 165 kB     00:02     
---------------------------------------------------------------------------------
Total                                             45 kB/s | 184 kB     00:04     
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : drbd-utils-8.3.7-2.fc13.x86_64                            1/2 
  Installing     : drbd-pacemaker-8.3.7-2.fc13.x86_64                        2/2 

Installed:
  drbd-pacemaker.x86_64 0:8.3.7-2.fc13                                           

Dependency Installed:
  drbd-utils.x86_64 0:8.3.7-2.fc13                                               

Complete!
[root@pcmk-1 ~]#

7.2. 配​置​DRBD

在​我​们​设​置​之​前​,我​们​要​创​建​一​些​空​的​磁​盘​分​区​给​它​。​

7.2.1. 为​DRBD创​建​一​个​分​区​

如​果​你​有​1Gb以​上​的​空​间​,就​用​那​么​多​吧​, 在​这​个​指​南​中​根​本​用​不​到​这​么​多​空​间​。​
[root@pcmk-1 ~]# lvcreate -n drbd-demo -L 1G VolGroup
  Logical volume "drbd-demo" created
[root@pcmk-1 ~]# lvs
  LV        VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  drbd-demo VolGroup -wi-a- 1.00G                                      
  lv_root   VolGroup -wi-ao   7.30G                                      
  lv_swap   VolGroup -wi-ao 500.00M
在​另​外​一​个​节​点​上​面​执​行​相​同​的​操​作​,请​确​保​使​用​了​相​同​大​小​的​分​区​。​
[root@pcmk-2 ~]# lvs
  LV      VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_root VolGroup -wi-ao   7.30G                                      
  lv_swap VolGroup -wi-ao 500.00M                                      
[root@pcmk-2 ~]# lvcreate -n drbd-demo -L 1G VolGroup
  Logical volume "drbd-demo" created
[root@pcmk-2 ~]# lvs
  LV        VG       Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  drbd-demo VolGroup -wi-a- 1.00G                                      
  lv_root   VolGroup -wi-ao   7.30G                                      
  lv_swap   VolGroup -wi-ao 500.00M

7.2.2. 配​置​DRBD

没​有​命​令​来​自​动​生​成​DRBD配​置​文​件​,所​以​我​们​要​简​单​的​拷​贝​下​面​的​配​置​文​件​并​粘​贴​到​/etc/drbd.conf
想​知​道​配​置​文​件​的​详​细​信​息​,请​访​问​ http://www.drbd.org/users-guide/ch-configure.html

警告

请​注​意​要​替​换​掉​name和​address选​项​以​符​合​您​的​试​验​环​境​。​
global { 
  usage-count yes; 
}
common {
  protocol C;
}
resource wwwdata {
  meta-disk internal;
  device    /dev/drbd1;
  syncer {
    verify-alg sha1;
  }
  net { 
    allow-two-primaries; 
  }
  on pcmk-1 {
    disk      /dev/mapper/VolGroup-drbd--demo;
    address   192.168.122.101:7789; 
  }
  on 
pcmk-2 {
    disk      /dev/mapper/VolGroup-drbd--demo;
    address   192.168.122.102:7789;      
  }
}

注意

TODO: Explain the reason for the allow-two-primaries option

7.2.3. 初​始​化​并​载​入​DRBD

配​置​完​成​以​后​,我​们​可​以​来​执​行​初​始​化​了​
[root@pcmk-1 ~]# drbdadm create-md wwwdata
md_offset 12578816
al_offset 12546048
bm_offset 12541952

Found some data 
 ==> This might destroy existing data! <==

Do you want to proceed?
[need to type 'yes' to confirm] yes

Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
现​在​讲​DRBD的​模​块​载​入​内​核​并​检​测​是​不​是​都​正​常​
[root@pcmk-1 ~]# modprobe drbd
[root@pcmk-1 ~]# drbdadm up wwwdata
[root@pcmk-1 ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-90)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by root@pcmk-1, 2009-12-08 11:22:57

 1: cs:WFConnection ro:Secondary/Unknown ds:Inconsistent/DUnknown C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:12248
[root@pcmk-1 ~]# 

Repeat on the second node
drbdadm --force create-md wwwdata 
modprobe drbd
drbdadm up wwwdata
cat /proc/drbd
[root@pcmk-2 ~]# drbdadm --force create-md wwwdata
Writing meta data...
initializing activity log
NOT initialized bitmap
New drbd meta data block successfully created.
success
[root@pcmk-2 ~]# modprobe drbd
WARNING: Deprecated config file /etc/modprobe.conf, all config files belong into /etc/modprobe.d/.
[root@pcmk-2 ~]# drbdadm up wwwdata
[root@pcmk-2 ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-90)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by root@pcmk-1, 2009-12-08 11:22:57

 1: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----
    ns:0 nr:0 dw:0 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:12248
现​在​我​们​要​告​诉​DRBD要​用​那​个​数​据​(那​个​节​点​作​为​主​)。​因​为​两​边​都​有​一​些​废​数​据​,我​们​要​在​pcmk-1上​面​执​行​一​下​命​令​。​
[root@pcmk-1 ~]# drbdadm -- --overwrite-data-of-peer primary wwwdata
[root@pcmk-1 ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-90)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by root@pcmk-1, 2009-12-08 11:22:57
 1: cs:SyncSource ro:Primary/Secondary ds:UpToDate/Inconsistent C r----
    ns:2184 nr:0 dw:0 dr:2472 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:10064
        [=====>..............] sync'ed: 33.4% (10064/12248)K
        finish: 0:00:37 speed: 240 (240) K/sec
[root@pcmk-1 ~]# cat /proc/drbd
version: 8.3.6 (api:88/proto:86-90)
GIT-hash: f3606c47cc6fcf6b3f086e425cb34af8b7a81bbf build by root@pcmk-1, 2009-12-08 11:22:57
 1: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:12248 nr:0 dw:0 dr:12536 al:0 bm:1 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
pcmk-1现​在​是​处​于​Primary(主​)状​态​了​,它​允​许​写​入​了​。​这​意​味​着​可​以​在​上​面​创​建​文​件​系​统​并​把​一​些​数​据​放​进​去​,并​且​用​WebSite这​个​资​源​来​展​现​。​

7.2.4. 向​DRBD中​添​加​数​据​

[root@pcmk-1 ~]# mkfs.ext4 /dev/drbd1
mke2fs 1.41.4 (27-Jan-2009)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
3072 inodes, 12248 blocks
612 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=12582912
2 block groups
8192 blocks per group, 8192 fragments per group
1536 inodes per group
Superblock backups stored on blocks: 
        8193

Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 26 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.

Now mount the newly created filesystem so we can create our index file
mount /dev/drbd1 /mnt/
cat <<-END >/mnt/index.html
<html>
<body>My Test Site - drbd</body>
</html>
END
umount /dev/drbd1
[root@pcmk-1 ~]# mount /dev/drbd1 /mnt/
[root@pcmk-1 ~]# cat <<-END >/mnt/index.html
> <html>
> <body>My Test Site - drbd</body>
> </html>
> END
[root@pcmk-1 ~]# umount /dev/drbd1

7.3. 在​集​群​中​配​置​DRBD

crm shell一​个​便​捷​的​特​性​是​可​以​工​作​在​交​互​模​式​下​并​自​动​的​变​更​配​置​中​的​相​关​部​分​。​
首​先​我​们​打​开​shell。​提​示​会​指​出​你​现​在​是​在​交​互​模​式​下​。​
[root@pcmk-1 ~]# crm
cib crm(live)#
然​后​我​们​创​建​一​个​当​前​配​置​文​件​的​副​本​。​我​们​在​这​个​副​本​里​更​改​配​置​。​直​到​我​们​提​交​这​个​副​本​之​前​集​群​不​会​应​用​这​些​更​改​。​请​注​意​提​示​符​的​变​更​,现​在​它​指​出​我​们​看​到​的​已​经​不​是​当​前​(live)集​群​的​配​置​文​件​。​
cib crm(live)# cib new drbd
INFO: drbd shadow CIB created
crm(drbd)#
现​在​我​们​可​以​创​建​DRBD clone,然​后​看​看​修​改​过​后​的​配​置​文​件​。​
crm(drbd)# configure primitive WebData ocf:linbit:drbd params drbd_resource=wwwdata \
        op monitor interval=60s
crm(drbd)# configure ms WebDataClone WebData meta master-max=1 master-node-max=1 \
        clone-max=2 clone-node-max=1 notify=true
crm(drbd)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
 params drbd_resource="wwwdata" \
 op monitor interval="60s"
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
ms WebDataClone WebData \
 meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation website-with-ip inf: WebSite ClusterIP
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
一​旦​你​确​认​这​些​修​改​没​问​题​,我​们​就​提​交​这​个​副​本​,然​后​用​crm_mon来​看​看​修​改​是​否​生​效​了​。​
crm(drbd)# cib commit drbd
INFO: commited 'drbd' shadow CIB to the cluster
crm(drbd)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Tue Sep  1 09:37:13 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
3 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
WebSite (ocf::heartbeat:apache):        Started pcmk-1
Master/Slave Set: WebDataClone
 Masters: [ pcmk-2 ]
 Slaves: [ pcmk-1 ]

注意

Include details on adding a second DRBD resource
现​在​DRBD已​经​工​作​了​,我​们​可​以​配​置​一​个​Filesystem资​源​来​使​用​它​。​ 此​外​,对​于​这​个​文​件​系​统​的​定​义​,同​样​的​我​们​告​诉​集​群​这​个​文​件​系​统​能​在​哪​运​行​(主​DRBD运​行​的​节​点​)以​及​什​么​时​候​可​以​启​动​(在​主​DRBD启​动​以​后​)。​
我​们​再​一​次​的​使​用​交​互​模​式​的​crm shell
[root@pcmk-1 ~]# crm
crm(live)# cib new fs
INFO: fs shadow CIB created
crm(fs)# configure primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype="ext4"
crm(fs)# configure colocation fs_on_drbd inf: WebFS WebDataClone:Master
crm(fs)# configure order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
我​们​也​要​告​诉​集​群​Apache也​要​运​行​在​同​样​的​节​点​上​,而​且​文​件​系​统​要​在​Apache之​前​启​动​。​
crm(fs)# configure colocation WebSite-with-WebFS inf: WebSite WebFS
crm(fs)# configure order WebSite-after-WebFS inf: WebFS WebSite
审​视​一​下​你​的​配​置​:
[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype="ext4"
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
ms WebDataClone WebData \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation WebSite-with-WebFS inf: WebSite WebFS
colocation fs_on_drbd inf: WebFS WebDataClone:Master
colocation website-with-ip inf: WebSite ClusterIP
order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
order WebSite-after-WebFS inf: WebFS WebSite
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
看​完​以​后​,我​们​提​交​它​并​看​看​有​没​有​生​效​。​
crm(fs)# cib commit fs
INFO: commited 'fs' shadow CIB to the cluster
crm(fs)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Tue Sep  1 10:08:44 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
4 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
WebSite (ocf::heartbeat:apache): Started pcmk-1
Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 ]
        Slaves: [ pcmk-2 ]
WebFS (ocf::heartbeat:Filesystem): Started pcmk-1

7.3.1. 迁​移​测​试​

我​们​可​以​再​次​关​掉​在​运​行​的​那​个​节​点​,但​是​安​全​的​方​法​是​把​节​点​设​置​为​standby模​式​。​节​点​在​这​个​状​态​下​面​等​于​告​诉​集​群​它​不​能​运​行​任​何​资​源​,任​何​在​这​个​节​点​上​面​运​行​的​资​源​都​会​被​移​动​到​其​他​地​方​。​这​个​特​性​在​更​新​资​源​安​装​包​的​时​候​特​别​的​方​便​。​(确​实​!)
把​一​个​本​地​节​点​设​置​为​standby模​式​并​观​察​集​群​把​所​有​资​源​移​动​到​另​外​一​个​节​点​了​。​并​且​注​意​节​点​的​状​态​改​变​为​不​能​运​行​任​何​的​资​源​。​
[root@pcmk-1 ~]# crm node standby
[root@pcmk-1 ~]# crm_mon
============
Last updated: Tue Sep  1 10:09:57 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
4 Resources configured.
============

Node pcmk-1: standby
Online: [ pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
WebSite (ocf::heartbeat:apache):        Started pcmk-2
Master/Slave Set: WebDataClone
        Masters: [ pcmk-2 ]
        Stopped: [ WebData:1 ]
WebFS   (ocf::heartbeat:Filesystem):    Started pcmk-2
当​我​在​pcmk-1上​面​操​作​完​了​--本​例​中​没​有​任​何​操​作​,我​们​只​是​想​让​资​源​移​动​移​动​--我​们​可​以​让​节​点​变​回​正​常​的​集​群​成​员​。​
[root@pcmk-1 ~]# crm node online
[root@pcmk-1 ~]# crm_mon
============
Last updated: Tue Sep  1 10:13:25 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
4 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
WebSite (ocf::heartbeat:apache):        Started pcmk-2
Master/Slave Set: WebDataClone
        Masters: [ pcmk-2 ]
        Slaves: [ pcmk-1 ]
WebFS   (ocf::heartbeat:Filesystem):    Started pcmk-2
注​意​我​们​设​置​的​资​源​黏​性​值​阻​止​了​资​源​迁​移​回​pcmk-1

第 8 章 转​变​为​Active/Active

8.1. 需​求​

Active/Active集​群​一​个​主​要​的​需​求​就​是​数​据​在​两​台​机​器​上​面​都​是​可​用​并​且​是​同​步​的​。​Pacemaker没​有​要​求​你​怎​么​实​现​,你​可​以​用​SAN,但​是​自​从​DRBD支​持​多​主​模​式​,我​们​也​可​以​用​这​个​来​实​现​。​
唯​一​的​限​制​是​我​们​要​用​一​个​针​对​集​群​的​文​件​系​统​(我​们​之​前​用​的​ext4,它​并​不​是​这​样​一​个​文​件​系​统​)。​ OCFS2或​者​GFS2都​是​可​以​的​,但​是​在​Fedora 13上​面​,我​们​用​GFS2。​

8.2. 安​装​一​个​集​群​文​件​系​统​ - GFS2

首​先​我​们​在​各​个​节​点​上​面​安​装​GFS2。​
[root@pcmk-1 ~]# yum install -y gfs2-utils gfs-pcmk
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package gfs-pcmk.x86_64 0:3.0.5-2.fc12 set to be updated
--> Processing Dependency: libSaCkpt.so.3(OPENAIS_CKPT_B.01.01)(64bit) for package: gfs-pcmk-3.0.5-2.fc12.x86_64
--> Processing Dependency: dlm-pcmk for package: gfs-pcmk-3.0.5-2.fc12.x86_64
--> Processing Dependency: libccs.so.3()(64bit) for package: gfs-pcmk-3.0.5-2.fc12.x86_64
--> Processing Dependency: libdlmcontrol.so.3()(64bit) for package: gfs-pcmk-3.0.5-2.fc12.x86_64
--> Processing Dependency: liblogthread.so.3()(64bit) for package: gfs-pcmk-3.0.5-2.fc12.x86_64
--> Processing Dependency: libSaCkpt.so.3()(64bit) for package: gfs-pcmk-3.0.5-2.fc12.x86_64
---> Package gfs2-utils.x86_64 0:3.0.5-2.fc12 set to be updated
--> Running transaction check
---> Package clusterlib.x86_64 0:3.0.5-2.fc12 set to be updated
---> Package dlm-pcmk.x86_64 0:3.0.5-2.fc12 set to be updated
---> Package openaislib.x86_64 0:1.1.0-1.fc12 set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================
 Package                Arch               Version                   Repository        Size
===========================================================================================
Installing:
 gfs-pcmk               x86_64             3.0.5-2.fc12              custom           101 k
 gfs2-utils             x86_64             3.0.5-2.fc12              custom           208 k
Installing for dependencies:
 clusterlib             x86_64             3.0.5-2.fc12              custom            65 k
 dlm-pcmk               x86_64             3.0.5-2.fc12              custom            93 k
 openaislib             x86_64             1.1.0-1.fc12              fedora            76 k

Transaction Summary
===========================================================================================
Install       5 Package(s)
Upgrade       0 Package(s)

Total download size: 541 k
Downloading Packages:
(1/5): clusterlib-3.0.5-2.fc12.x86_64.rpm                                |  65 kB     00:00
(2/5): dlm-pcmk-3.0.5-2.fc12.x86_64.rpm                                  |  93 kB     00:00
(3/5): gfs-pcmk-3.0.5-2.fc12.x86_64.rpm                                  | 101 kB     00:00
(4/5): gfs2-utils-3.0.5-2.fc12.x86_64.rpm                                | 208 kB     00:00
(5/5): openaislib-1.1.0-1.fc12.x86_64.rpm                                |  76 kB     00:00
-------------------------------------------------------------------------------------------
Total                                                           992 kB/s | 541 kB     00:00
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
  Installing     : clusterlib-3.0.5-2.fc12.x86_64                                       1/5 
  Installing     : openaislib-1.1.0-1.fc12.x86_64                                       2/5 
  Installing     : dlm-pcmk-3.0.5-2.fc12.x86_64                                         3/5 
  Installing     : gfs-pcmk-3.0.5-2.fc12.x86_64                                         4/5 
  Installing     : gfs2-utils-3.0.5-2.fc12.x86_64                                       5/5 

Installed:
  gfs-pcmk.x86_64 0:3.0.5-2.fc12                    gfs2-utils.x86_64 0:3.0.5-2.fc12

Dependency Installed:
  clusterlib.x86_64 0:3.0.5-2.fc12   dlm-pcmk.x86_64 0:3.0.5-2.fc12 
  openaislib.x86_64 0:1.1.0-1.fc12  

Complete!
[root@pcmk-1 x86_64]#

警告

If this step fails, it is likely that your version/distribution does not ship the "Pacemaker" versions of dlm_controld and/or gfs_controld. Normally these files would be called dlm_controld.pcmk and gfs_controld.pcmk and live in the /usr/sbin directory.
If you cannot locate an installation source for these files, you will need to install a package called cman and reconfigure Corosync to use it as outlined in 附录 C, Using CMAN for Cluster Membership and Quorum.
When using CMAN, you can skip 第 8.3 节 “整​合​ Pacemaker-GFS2” where dlm-clone and gfs-clone are created, and proceed directly to 第 8.4 节 “创​建​一​个​ GFS2 文​件​系​统​”.

8.3. 整​合​ Pacemaker-GFS2

GFS2要​求​运​行​两​个​服​务​,首​先​是​用​户​空​间​访​问​内​核​的​分​布​式​锁​管​理​(DLM)的​接​口​。​ DLM是​用​来​统​筹​哪​个​节​点​可​以​处​理​某​个​特​定​的​文​件​,并​且​与​Pacemaker集​成​来​得​到​节​点​之​间​的​关​系​[14]和​隔​离​能​力​。​
另​外​一​个​服​务​是​GFS2自​身​的​控​制​进​程​,也​是​与​Pacemaker集​成​来​得​到​节​点​之​间​的​关​系​。​

8.3.1. 添​加​ DLM 服​务​

DLM控​制​进​程​需​要​在​所​有​可​用​的​集​群​节​点​上​面​运​行​,所​以​我​们​用​shell交​互​模​式​来​添​加​一​个​cloned类​型​的​资​源​。​
[root@pcmk-1 ~]# crm
crm(live)# cib new stack-glue
INFO: stack-glue shadow CIB created
crm(stack-glue)# configure primitive dlm ocf:pacemaker:controld op monitor interval=120s
crm(stack-glue)# configure clone dlm-clone dlm meta interleave=true
crm(stack-glue)# configure show xml
crm(stack-glue)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype="ext4"
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
 op monitor interval="120s"
ms WebDataClone WebData \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone dlm-clone dlm \
 meta interleave="true"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation WebSite-with-WebFS inf: WebSite WebFS
colocation fs_on_drbd inf: WebFS WebDataClone:Master
colocation website-with-ip inf: WebSite ClusterIP
order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
order WebSite-after-WebFS inf: WebFS WebSite
order apache-after-ip inf: ClusterIP WebSite
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”

注意

TODO: Explain the meaning of the interleave option
看​看​配​置​文​件​有​没​有​错​误​,然​后​退​出​shell看​看​集​群​的​反​应​。​
crm(stack-glue)# cib commit stack-glue
INFO: commited 'stack-glue' shadow CIB to the cluster
crm(stack-glue)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Sep  3 20:49:54 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
5 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

WebSite (ocf::heartbeat:apache):        Started pcmk-2
Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 ]
        Slaves: [ pcmk-2 ]
ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
Clone Set: dlm-clone
 Started: [ pcmk-2 pcmk-1 ]
WebFS   (ocf::heartbeat:Filesystem):    Started pcmk-2

8.3.2. 添​加​ GFS2 服​务​

一​旦​DLM启​动​了​,我​们​可​以​加​上​GFS2的​控​制​进​程​了​。​
用​crm shell来​创​建​gfs-control这​个​集​群​资​源​:
[root@pcmk-1 ~]# crm
crm(live)# cib new gfs-glue --force
INFO: gfs-glue shadow CIB created
crm(gfs-glue)# configure primitive gfs-control ocf:pacemaker:controld params daemon=gfs_controld.pcmk args="-g 0" op monitor interval=120s
crm(gfs-glue)# configure clone gfs-clone gfs-control meta interleave=true
现​在​确​保​Pacemaker只​在​有​dlm服​务​运​行​的​节​点​上​面​启​动​ gfs-control 服​务​
crm(gfs-glue)# configure colocation gfs-with-dlm INFINITY: gfs-clone dlm-clone
crm(gfs-glue)# configure order start-gfs-after-dlm mandatory: dlm-clone gfs-clone
看​看​配​置​文​件​有​没​有​错​误​,然​后​退​出​shell看​看​集​群​的​反​应​。​
crm(gfs-glue)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype="ext4"
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
 params daemon=”​gfs_controld.pcmk”​ args=”​-g 0”​ \
 op monitor interval="120s"
ms WebDataClone WebData \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
 meta interleave="true"
location prefer-pcmk-1 WebSite 50: pcmk-1
colocation WebSite-with-WebFS inf: WebSite WebFS
colocation fs_on_drbd inf: WebFS WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSite ClusterIP
order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
order WebSite-after-WebFS inf: WebFS WebSite
order apache-after-ip inf: ClusterIP WebSite
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
crm(gfs-glue)# cib commit gfs-glue
INFO: commited 'gfs-glue' shadow CIB to the cluster
crm(gfs-glue)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Sep  3 20:49:54 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
6 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

WebSite (ocf::heartbeat:apache):        Started pcmk-2
Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 ]
        Slaves: [ pcmk-2 ]
ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
Clone Set: dlm-clone
        Started: [ pcmk-2 pcmk-1 ]
Clone Set: gfs-clone
 Started: [ pcmk-2 pcmk-1 ]
WebFS   (ocf::heartbeat:Filesystem):    Started pcmk-1

8.4. 创​建​一​个​ GFS2 文​件​系​统​

8.4.1. 准​备​工​作​

在​我​们​对​一​个​已​存​在​的​分​区​做​任​何​操​作​之​前​,我​们​要​确​保​它​没​有​被​挂​载​。​我​们​告​诉​集​群​停​止​WebFS这​个​资​源​来​确​保​这​一​点​。​这​可​以​确​保​其​他​使​用​WebFS的​资​源​会​正​确​的​依​次​关​闭​。​
[root@pcmk-1 ~]# crm_resource --resource WebFS --set-parameter target-role --meta --parameter-value Stopped
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Sep  3 15:18:06 2009
Stack: openais
Current DC: pcmk-1 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
6 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 ]
        Slaves: [ pcmk-2 ]
ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-1
Clone Set: dlm-clone
        Started: [ pcmk-2 pcmk-1 ]
Clone Set: gfs-clone
        Started: [ pcmk-2 pcmk-1 ]

注意

注​意​ Apache and WebFS 两​者​都​已​经​停​止​了​。​

8.4.2. 创​建​并​迁​移​数​据​到​ GFS2 分​区​

现​在​集​群​的​基​层​和​集​成​部​分​都​正​常​运​行​,我​们​现​在​创​建​一​个​GFS2分​区​

警告

这​个​操​作​会​清​除​DRBD分​区​上​面​的​所​有​数​据​,请​备​份​重​要​的​数​据​。​
我​们​要​为​GFS2分​区​指​定​一​系​列​附​加​的​参​数​。​
首​先​我​们​要​用​ -p选​项​来​指​定​我​们​用​的​是​内​核​的​DLM,然​后​我​们​用​-j来​表​示​我​们​为​两​个​日​志​保​留​足​够​的​空​间​(每​个​操​作​文​件​系​统​的​节​点​各​一​个​)。​
最​后​,我​们​用​-t来​指​定​lock table的​名​称​。​这​个​字​段​的​格​式​是​ clustername:fsname(集​群​名​称​:文​件​系​统​名​称​)。​fsname的​话​,我​们​只​要​用​一​个​唯​一​的​并​且​能​描​述​我​们​这​个​集​群​的​名​称​就​好​了​,我​们​用​默​认​的​pcmk。​
如​果​要​更​改​集​群​的​名​称​,找​到​包​含​name:pacemaker的​配​置​文​件​区​域​,然​后​添​加​如​下​所​示​的​选​项​即​可​。​
clustername: myname
在​每​个​节​点​都​执​行​以​下​命​令​。​
mkfs.gfs2 -p lock_dlm -j 2 -t pcmk:web /dev/drbd1
[root@pcmk-1 ~]# mkfs.gfs2 -t pcmk:web -p lock_dlm -j 2 /dev/vdb 
This will destroy any data on /dev/vdb.
It appears to contain: data

Are you sure you want to proceed? [y/n] y

Device:                    /dev/vdb
Blocksize:                 4096
Device Size                1.00 GB (131072 blocks)
Filesystem Size:           1.00 GB (131070 blocks)
Journals:                  2
Resource Groups:           2
Locking Protocol:          "lock_dlm"
Lock Table:                "pcmk:web"
UUID:                      6B776F46-177B-BAF8-2C2B-292C0E078613

[root@pcmk-1 ~]#
然​后​再​迁​移​数​据​到​这​个​新​的​文​件​系​统​。​现​在​我​们​创​建​一​个​跟​上​次​不​一​样​的​主​页​。​
[root@pcmk-1 ~]# mount /dev/drbd1 /mnt/
[root@pcmk-1 ~]# cat <<-END >/mnt/index.html
<html>
<body>My Test Site - GFS2</body>
</html>
END
[root@pcmk-1 ~]# umount /dev/drbd1
[root@pcmk-1 ~]# drbdadm verify wwwdata
[root@pcmk-1 ~]#

8.5. 8.5. 重​新​为​集​群​配​置​GFS2

[root@pcmk-1 ~]# crm
crm(live)# cib new GFS2
INFO: GFS2 shadow CIB created
crm(GFS2)# configure delete WebFS
crm(GFS2)# configure primitive WebFS ocf:heartbeat:Filesystem params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”​gfs2”​
现​在​我​们​重​新​创​建​这​个​资​源​, 我​们​也​要​重​建​跟​这​个​资​源​相​关​的​约​束​条​件​,因​为​shell会​自​动​删​除​跟​WebFS相​关​的​约​束​条​件​。​
crm(GFS2)# configure colocation WebSite-with-WebFS inf: WebSite WebFS
crm(GFS2)# configure colocation fs_on_drbd inf: WebFS WebDataClone:Master
crm(GFS2)# configure order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
crm(GFS2)# configure order WebSite-after-WebFS inf: WebFS WebSite
crm(GFS2)# configure colocation WebFS-with-gfs-control INFINITY: WebFS gfs-clone
crm(GFS2)# configure order start-WebFS-after-gfs-control mandatory: gfs-clone WebFS
crm(GFS2)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
 params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”​gfs2”​
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip="192.168.122.101" cidr_netmask="32" \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
ms WebDataClone WebData \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation WebFS-with-gfs-control inf: WebFS gfs-clone
colocation WebSite-with-WebFS inf: WebSite WebFS
colocation fs_on_drbd inf: WebFS WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSite ClusterIP
order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
order WebSite-after-WebFS inf: WebFS WebSite
order apache-after-ip inf: ClusterIP WebSite
order start-WebFS-after-gfs-control inf: gfs-clone WebFS
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
看​看​配​置​文​件​有​没​有​错​误​,然​后​退​出​shell看​看​集​群​的​反​应​。​
crm(GFS2)# cib commit GFS2
INFO: commited 'GFS2' shadow CIB to the cluster
crm(GFS2)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Sep  3 20:49:54 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
6 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

WebSite (ocf::heartbeat:apache):        Started pcmk-2
Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 ]
        Slaves: [ pcmk-2 ]
ClusterIP        (ocf::heartbeat:IPaddr):        Started pcmk-2
Clone Set: dlm-clone
        Started: [ pcmk-2 pcmk-1 ]
Clone Set: gfs-clone
        Started: [ pcmk-2 pcmk-1 ]
WebFS (ocf::heartbeat:Filesystem): Started pcmk-1

8.6. 重​新​配​置​ Pacemaker 为​ Active/Active

基​本​上​所​有​的​事​情​都​已​经​准​备​就​绪​了​。​最​新​的​DRBD是​支​持​ Primary/Primary(主​/主​)模​式​的​,并​且​我​们​的​文​件​系​统​的​是​针​对​集​群​的​。​所​有​我​们​要​做​的​事​情​就​是​重​新​配​置​我​们​的​集​群​来​使​用​它​们​(的​先​进​功​能​)。​
这​次​操​作​会​改​很​多​东​西​,所​以​我​们​再​次​使​用​交​互​模​式​
[root@pcmk-1 ~]# crm
[root@pcmk-1 ~]# cib new active
如​果​我​们​不​能​访​问​这​些​服​务​,那​做​成​ Active/Active是​没​有​必​要​的​,所​以​我​们​要​先​clone这​个​IP地​址​,克​隆​的​IPaddr2资​源​用​的​是​iptables规​则​来​保​证​每​个​请​求​都​只​由​一​个​节​点​来​处​理​。​附​件​的​meta选​项​告​诉​集​群​我​们​要​克​隆​多​少​个​实​例​(每​个​节​点​一​个​"请​求​桶​")。​并​且​如​果​其​他​节​点​挂​了​,剩​下​的​节​点​可​以​处​理​所​有​的​请​求​。​否​则​这​些​请​求​都​会​被​丢​弃​。​
[root@pcmk-1 ~]# configure clone WebIP ClusterIP  \
        meta globally-unique=”​true”​ clone-max=”​2”​ clone-node-max=”​2”​
现​在​我​们​要​告​诉​集​群​如​何​决​定​请​求​怎​样​分​配​给​节​点​。​我​们​要​设​置​ clusterip_hash这​个​参​数​来​实​现​它​。​
打​开​ClusterIP的​配​置​
[root@pcmk-1 ~]# configure edit  ClusterIP
在​参​数​行​添​加​以​下​内​容​:
clusterip_hash="sourceip"
完​整​的​定​义​就​像​下​面​一​样​:
primitive ClusterIP ocf:heartbeat:IPaddr2 \ 
        params ip="192.168.122.101" cidr_netmask="32" clusterip_hash="sourceip" \
        op monitor interval="30s"
以​下​是​完​整​的​配​置​
[root@pcmk-1 ~]# crm 
crm(live)# cib new active
INFO: active shadow CIB created
crm(active)# configure clone WebIP ClusterIP  \
        meta globally-unique=”true” clone-max=”2” clone-node-max=”2”
crm(active)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”gfs2”
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip=”192.168.122.101” cidr_netmask=”32” clusterip_hash=”sourceip” \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
ms WebDataClone WebData \
        meta master-max="1" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone WebIP ClusterIP \
 meta globally-unique=”​true”​ clone-max=”​2”​ clone-node-max=”​2”​
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation WebFS-with-gfs-control inf: WebFS gfs-clone
colocation WebSite-with-WebFS inf: WebSite WebFS
colocation fs_on_drbd inf: WebFS WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSite WebIP
order WebFS-after-WebData inf: WebDataClone:promote WebFS:start
order WebSite-after-WebFS inf: WebFS WebSite
order apache-after-ip inf: WebIP WebSite
order start-WebFS-after-gfs-control inf: gfs-clone WebFS
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
请​注​意​所​有​跟​ClusterIP相​关​的​限​制​都​已​经​被​更​新​到​与​WebIP相​关​,这​是​使​用​crm shell的​另​一​个​好​处​。​
然​后​我​们​要​把​文​件​系​统​和​apache资​源​变​成​clones。​同​样​的​ crm shell会​自​动​更​新​相​关​约​束​。​
crm(active)# configure clone WebFSClone WebFS
crm(active)# configure clone WebSiteClone WebSite
最​后​要​告​诉​集​群​现​在​允​许​把​两​个​节​点​都​提​升​为​ Primary(换​句​话​说​ Master).
crm(active)# configure edit WebDataClone
把​ master-max 改​为​ 2
crm(active)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”gfs2”
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip=”192.168.122.101” cidr_netmask=”32” clusterip_hash=”sourceip” \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
ms WebDataClone WebData \
        meta master-max="2" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone WebFSClone WebFS
clone WebIP ClusterIP  \
        meta globally-unique=”true” clone-max=”2” clone-node-max=”2”
clone WebSiteClone WebSite
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation WebFS-with-gfs-control inf: WebFSClone gfs-clone
colocation WebSite-with-WebFS inf: WebSiteClone WebFSClone
colocation fs_on_drbd inf: WebFSClone WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSiteClone WebIP
order WebFS-after-WebData inf: WebDataClone:promote WebFSClone:start
order WebSite-after-WebFS inf: WebFSClone WebSiteClone
order apache-after-ip inf: WebIP WebSiteClone
order start-WebFS-after-gfs-control inf: gfs-clone WebFSClone
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="false" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”
看​看​配​置​文​件​有​没​有​错​误​,然​后​退​出​shell看​看​集​群​的​反​应​。​
crm(active)# cib commit active
INFO: commited 'active' shadow CIB to the cluster
crm(active)# quit
bye
[root@pcmk-1 ~]# crm_mon
============
Last updated: Thu Sep  3 21:37:27 2009
Stack: openais
Current DC: pcmk-2 - partition with quorum
Version: 1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f
2 Nodes configured, 2 expected votes
6 Resources configured.
============

Online: [ pcmk-1 pcmk-2 ]

Master/Slave Set: WebDataClone
        Masters: [ pcmk-1 pcmk-2 ]
Clone Set: dlm-clone
        Started: [ pcmk-2 pcmk-1 ]
Clone Set: gfs-clone
        Started: [ pcmk-2 pcmk-1 ]
Clone Set: WebIP
 Started: [ pcmk-1 pcmk-2 ]
Clone Set: WebFSClone
 Started: [ pcmk-1 pcmk-2 ]
Clone Set: WebSiteClone
 Started: [ pcmk-1 pcmk-2 ]

8.6.1. 恢​复​测​试​

注意

TODO: Put one node into standby to demonstrate failover


[14] The list of nodes the cluster considers to be available

第 9 章 配​置​ STONITH

9.1. 为​什​么​需​要​ STONITH

STONITH 是​爆​其​他​节​点​的​头​( Shoot-The-Other-Node-In-The-Head)的​缩​写​,它​能​保​护​你​的​数​据​不​被​不​正​常​的​节​点​破​坏​或​是​并​发​写​入​。​
因​为​如​果​一​个​节​点​没​有​相​应​,但​并​不​代​表​它​没​有​在​操​作​你​的​数​据​,100%保​证​数​据​安​全​的​做​法​就​是​在​允​许​另​外​一​个​节​点​操​作​数​据​之​前​,使​用​STONITH来​保​证​节​点​真​的​下​线​了​。​
STONITH另​外​一​个​用​场​是​在​当​集​群​服​务​无​法​停​止​的​时​候​。​这​个​时​候​,集​群​可​以​用​STONITH来​强​制​使​节​点​下​线​,从​而​可​以​安​全​的​得​在​其​他​地​方​启​动​服​务​。​

9.2. 你​该​用​什​么​样​的​STONITH设​备​。​

重​要​的​一​点​是​STONITH设​备​可​以​让​集​群​区​分​节​点​故​障​和​网​络​故​障​。​
人​们​常​常​犯​得​一​个​错​误​就​是​选​择​远​程​电​源​开​关​作​为​STONITH设​备​(比​如​许​多​主​板​自​带​的​IPMI控​制​器​) 。​在​那​种​情​况​下​,集​群​不​能​分​辨​节​点​是​真​正​的​下​线​了​,还​是​网​络​无​法​连​通​了​。​
同​样​地​, 任​何​依​靠​可​用​节​点​的​设​备​(比​如​测​试​用​的​基​于​SSH的​“​设​备​”​)都​是​不​适​当​的​。​

9.3. 配​置​STONITH

  1. 找​到​正​确​的​STONITH驱​动​: stonith -L
  2. 因​为​设​备​的​不​同​, 配​置​的​参​数​也​不​一​样​。​ 想​看​设​备​所​需​设​置​的​参​数​,可​以​用​: stonith -t {type} -n
希​望​开​发​者​选​择​了​合​适​的​名​称​,如​果​不​是​这​样​,你​可​以​在​活​动​的​机​器​上​面​执​行​以​下​命​令​来​获​得​更​多​信​息​。​
lrmadmin -M stonith {type} pacemaker
输​出​应​该​是​XML格​式​的​文​本​文​件​,它​包​含​了​更​详​细​的​描​述​
  1. 创​建​stonith.xml文​件​ 包​含​了​一​个​原​始​的​源​,它​定​义​了​资​stonith类​下​面​的​某​个​type和​这​个​type所​需​的​参​数​。​
  2. 如​果​这​个​设​备​可​以​击​杀​多​个​设​备​并​且​支​持​从​多​个​节​点​连​接​过​来​,那​我​们​从​这​个​原​始​资​源​创​建​一​个​克​隆​。​
  3. 使​用​cibadmin来​更​新​CIB配​置​文​件​:cibadmin -C -o resources --xml-file stonith.xml

9.3.1. 例​子​

假​设​我​们​有​一​个​ 包​含​两​个​节​点​的​IBM BladeCenter,控​制​界​面​的​IP是​192.168.122.31,然​后​我​们​选​择​ external/ibmrsa作​为​驱​动​,然​后​配​置​下​面​列​表​当​中​的​参​数​。​
stonith -t external/ibmrsa -n
[root@pcmk-1 ~]# stonith -t external/ibmrsa -n
hostname  ipaddr  userid  passwd  type
假​设​我​们​知​道​管​理​界​面​的​用​户​名​和​密​码​,我​们​要​创​建​一​个​STONITH的​资​源​:
[root@pcmk-1 ~]# crm 
crm(live)# cib new stonith
INFO: stonith shadow CIB created
crm(stonith)# configure primitive rsa-fencing stonith::external/ibmrsa \
        params hostname=”​pcmk-1 pcmk-2" ipaddr=192.168.122.31 userid=mgmt passwd=abc123 type=ibm \
        op monitor interval="60s"
crm(stonith)# configure clone Fencing rsa-fencing
最​后​,我​们​要​重​新​打​开​之​前​禁​用​的​STONITH:
crm(stonith)# configure property stonith-enabled="true"
crm(stonith)# configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”gfs2”
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip=”192.168.122.101” cidr_netmask=”32” clusterip_hash=”sourceip” \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
primitive rsa-fencing stonith::external/ibmrsa \
 params hostname=”​pcmk-1 pcmk-2" ipaddr=192.168.122.31 userid=mgmt passwd=abc123 type=ibm \
 op monitor interval="60s"
ms WebDataClone WebData \
        meta master-max="2" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone Fencing rsa-fencing 
clone WebFSClone WebFS
clone WebIP ClusterIP  \
        meta globally-unique=”true” clone-max=”2” clone-node-max=”2”
clone WebSiteClone WebSite
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation WebFS-with-gfs-control inf: WebFSClone gfs-clone
colocation WebSite-with-WebFS inf: WebSiteClone WebFSClone
colocation fs_on_drbd inf: WebFSClone WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSiteClone WebIP
order WebFS-after-WebData inf: WebDataClone:promote WebFSClone:start
order WebSite-after-WebFS inf: WebFSClone WebSiteClone
order apache-after-ip inf: WebIP WebSiteClone
order start-WebFS-after-gfs-control inf: gfs-clone WebFSClone
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled="true" \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”

配​置​扼​要​重​述​

A.1. 最​终​的​集​群​配​置​文​件​

[root@pcmk-1 ~]# crm configure show
node pcmk-1
node pcmk-2
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”gfs2”
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip=”192.168.122.101” cidr_netmask=”32” clusterip_hash=”sourceip” \
        op monitor interval="30s"
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
primitive rsa-fencing stonith::external/ibmrsa \
        params hostname=”pcmk-1 pcmk-2" ipaddr=192.168.122.31 userid=mgmt passwd=abc123 type=ibm \
        op monitor interval="60s"
ms WebDataClone WebData \
        meta master-max="2" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"
clone Fencing rsa-fencing 
clone WebFSClone WebFS
clone WebIP ClusterIP  \
        meta globally-unique=”true” clone-max=”2” clone-node-max=”2”
clone WebSiteClone WebSite
clone dlm-clone dlm \
        meta interleave="true"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation WebFS-with-gfs-control inf: WebFSClone gfs-clone
colocation WebSite-with-WebFS inf: WebSiteClone WebFSClone
colocation fs_on_drbd inf: WebFSClone WebDataClone:Master
colocation gfs-with-dlm inf: gfs-clone dlm-clone
colocation website-with-ip inf: WebSiteClone WebIP
order WebFS-after-WebData inf: WebDataClone:promote WebFSClone:start
order WebSite-after-WebFS inf: WebFSClone WebSiteClone
order apache-after-ip inf: WebIP WebSiteClone
order start-WebFS-after-gfs-control inf: gfs-clone WebFSClone
order start-gfs-after-dlm inf: dlm-clone gfs-clone
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled=”true” \
        no-quorum-policy="ignore"
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”

A.2. 节​点​列​表​

这​个​列​表​中​的​集​群​节​点​是​集​群​自​动​添​加​的​。​
node pcmk-1
node pcmk-2

A.3. 集​群​选​项​

这​是​集​群​自​动​存​储​集​群​信​息​的​地​方​
  1. dc-version - DC使​用​的​Pacemaker的​版​本​(包​括​源​代​码​的​hash)
  2. 集​群​-基​层​ - 集​群​使​用​的​基​层​软​件​ (heartbeat or openais/corosync)
  3. expected-quorum-votes - 预​期​的​集​群​最​大​成​员​数​
以​及​管​理​员​设​置​集​群​操​作​的​方​法​选​项​
  1. stonith-enabled=true - 使​用​STONITH
  2. no-quorum-policy=ignore - 忽​略​达​不​到​法​定​人​数​的​情​况​,继​续​运​行​资​源​
property $id="cib-bootstrap-options" \
        dc-version="1.1.5-bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
        cluster-infrastructure="openais" \
        expected-quorum-votes=”2” \
        stonith-enabled=”true” \
        no-quorum-policy="ignore"

A.4. 资​源​

A.4.1. 默​认​选​项​

这​里​我​们​设​置​所​有​资​源​共​用​的​集​群​选​项​
  1. resource-stickiness - 资​源​粘​稠​值​
rsc_defaults $id="rsc-options" \
        resource-stickiness=”100”

A.4.2. 隔​离​

注意

TODO: Add text here
primitive rsa-fencing stonith::external/ibmrsa \
        params hostname=”pcmk-1 pcmk-2" ipaddr=192.168.122.31 userid=mgmt passwd=abc123 type=ibm \
        op monitor interval="60s"
clone Fencing rsa-fencing

A.4.3. 服​务​地​址​

用​户​需​要​一​个​不​变​的​地​址​来​访​问​集​群​所​提​供​的​服​务​。​此​外​,我​们​clone了​地​址​,以​便​在​两​个​节​点​上​都​使​用​这​个​IP。​一​个​iptables规​则​(resource agent的​一​部​分​)是​用​来​确​保​每​个​请​求​只​能​由​两​个​节​点​中​的​某​一​个​处​理​。​这​些​额​外​的​集​群​选​项​告​诉​我​们​想​要​两​个​clone(每​个​节​点​一​个​“​请​求​桶​”​)实​例​,如​果​一​个​节​点​失​效​,那​么​剩​下​的​节​点​处​理​这​两​个​请​求​桶​。​
primitive ClusterIP ocf:heartbeat:IPaddr2 \
        params ip=”192.168.122.101” cidr_netmask=”32” clusterip_hash=”sourceip” \
        op monitor interval="30s"
clone WebIP ClusterIP  
        meta globally-unique=”true” clone-max=”2” clone-node-max=”2”

注意

TODO: The RA should check for globally-unique=true when cloned

A.4.4. 分​布​式​锁​控​制​器​

像​GFS2集​群​文​件​系​统​需​要​一​个​锁​管​理​。​该​服​务​启​动​守​护​进​程​,提​供​了​访​问​内​核​中​的​锁​管​理​器​的​用​户​空​间​应​用​程​序​(如​GFS2守​护​进​程​)。​因​为​我​们​需​要​它​在​集​群​中​的​所​有​可​用​节​点​中​运​行​,我​们​把​它​clone。​
primitive dlm ocf:pacemaker:controld \
        op monitor interval="120s"
clone dlm-clone dlm \
        meta interleave="true

注意

TODO: Confirm interleave is no longer needed

A.4.5. GFS 控​制​守​护​进​程​

GFS2还​需​要​一​个​user-space到​kernel的​桥​梁​,每​个​节​点​上​要​运​行​。​所​以​在​这​里​我​们​还​有​一​个​clone,但​是​这​一​次​我​们​还​必​须​指​定​它​只​能​运​行​在​有​DLM的​机​器​上​(colocation 约​束​),它​只​能​在​DLM后​启​动​ (order约​束​)。​此​外​,gfs-control clone应​该​只​关​系​与​其​配​对​的​DLM实​例​,所​以​我​们​还​要​设​置​interleave 选​项​
primitive gfs-control ocf:pacemaker:controld \
   params daemon=”gfs_controld.pcmk” args=”-g 0” \
        op monitor interval="120s"
clone gfs-clone gfs-control \
        meta interleave="true"
colocation gfs-with-dlm inf: gfs-clone dlm-clone
order start-gfs-after-dlm inf: dlm-clone gfs-clone

A.4.6. DRBD - 共​享​存​储​

在​这​里​,我​们​定​义​了​DRBD技​术​服​务​,并​指​定​DRBD应​该​管​理​的​资​源​(从​drbd.conf)。​我​们​让​它​作​为​主​/从​资​源​,并​且​为​了​active/active,用​设​置​master-max=2来​允​许​两​者​都​晋​升​为​master。​我​们​还​可​以​设​置​通​知​选​项​,这​样​,当​时​集​群​的​节​点​的​状​态​发​生​改​变​时​,该​集​群​将​告​诉​DRBD的​agent。​
primitive WebData ocf:linbit:drbd \
        params drbd_resource="wwwdata" \
        op monitor interval="60s"
ms WebDataClone WebData \
        meta master-max="2" master-node-max="1" clone-max="2" clone-node-max="1" notify="true"

A.4.7. 集​群​文​件​系​统​

群​集​文​件​系​统​可​确​保​文​件​读​写​正​确​。​我​们​需​要​指​定​我​们​想​挂​载​并​使​用​GFS2的​块​设​备​(由​DRBD提​供​)。​这​又​是​一​个​clone,因​为​它​的​目​的​是​在​两​个​节​点​上​都​可​用​。​这​些​额​外​的​限​制​确​保​它​只​在​有​gfs-control和​drbd 实​例​的​节​点​上​运​行​。​
primitive WebFS ocf:heartbeat:Filesystem \
        params device="/dev/drbd/by-res/wwwdata" directory="/var/www/html" fstype=”gfs2”
clone WebFSClone WebFS
colocation WebFS-with-gfs-control inf: WebFSClone gfs-clone
colocation fs_on_drbd inf: WebFSClone WebDataClone:Master
order WebFS-after-WebData inf: WebDataClone:promote WebFSClone:start
order start-WebFS-after-gfs-control inf: gfs-clone WebFSClone

A.4.8. Apache

最​后​我​们​有​了​真​正​的​服​务​,Apache,我​们​只​需​要​告​诉​集​群​在​哪​里​可​以​找​到​它​的​主​配​置​文​件​,并​限​制​其​只​在​挂​载​了​文​件​系​统​和​有​可​用​IP节​点​上​运​行​
primitive WebSite ocf:heartbeat:apache \
        params configfile="/etc/httpd/conf/httpd.conf" \
        op monitor interval="1min"
clone WebSiteClone WebSite
colocation WebSite-with-WebFS inf: WebSiteClone WebFSClone
colocation website-with-ip inf: WebSiteClone WebIP
order apache-after-ip inf: WebIP WebSiteClone
order WebSite-after-WebFS inf: WebFSClone WebSiteClone

Sample Corosync Configuration

	
# Please read the Corosync.conf.5 manual page
compatibility: whitetank

totem {
        version: 2

        # How long before declaring a token lost (ms)
        token:          5000

        # How many token retransmits before forming a new configuration
        token_retransmits_before_loss_const: 10

        # How long to wait for join messages in the membership protocol (ms)
        join:           1000

        # How long to wait for consensus to be achieved before starting a new
        # round of membership configuration (ms)
        consensus:      6000

        # Turn off the virtual synchrony filter
        vsftype:        none

        # Number of messages that may be sent by one processor on receipt of the token
        max_messages:   20

        # Stagger sending the node join messages by 1..send_join ms
        send_join: 45

        # Limit generated nodeids to 31-bits (positive signed integers)
        clear_node_high_bit: yes

        # Disable encryption
        secauth:        off

        # How many threads to use for encryption/decryption
        threads:           0

        # Optionally assign a fixed node id (integer)
        # nodeid:         1234

        interface {
                ringnumber: 0

                # The following values need to be set based on your environment
                bindnetaddr: 192.168.122.0
                mcastaddr: 226.94.1.1
                mcastport: 4000
        }
}

logging {
        debug: off
        fileline: off
        to_syslog: yes
        to_stderr: off
        syslog_facility: daemon
        timestamp: on
}

amf {
        mode: disabled
}
	
例 B.1. Sample Corosync.conf for a two-node cluster

Using CMAN for Cluster Membership and Quorum

C.1. Background

CMAN v3 is a Corsync plugin that monitors the names and number of active cluster nodes in order to deliver membership and quorum information to clients (such as the Pacemaker daemons).
In a traditional Corosync-Pacemaker cluster, a Pacemaker plugin is loaded to provide membership and quorum information. The motivation for wanting to use CMAN for this instead, is to ensure all elements of the cluster stack are making decisions based on the same membership and quorum data. [15]
CMAN has been around longer than Pacemaker and is part of the Red Hat cluster stack, so it is available and supported by many distributions and other pieces of software (such as OCFS2 and GFS2). For this reason it makes sense to support it.

C.2. Adding CMAN Support

警告

Be sure to disable the Pacemaker plugin before continuing with this section. In most cases, this can be achieved by removing /etc/corosync/service.d/pcmk and stopping Corosync.

C.2.1. Adding CMAN Support - cluster.conf

The preferred approach for enabling CMAN is to configure cluster.conf and use the /etc/init.d/cman script to start Corosync. Its far easier to maintain and start automatically starts the necessary pieces for using GFS2.
You can find some documentation on Installing CMAN and Creating a Basic Cluster Configuration File at the Red Hat website. However please ignore the parts about Fencing, Failover Domains, or HA Services and anything to do with rgmanager and fenced. All these continue to be handled by Pacemaker in the normal manner.
	
<?xml version="1.0"?>
<cluster config_version="1" name="beekhof">
  <fence_daemon clean_start="0" post_fail_delay="0" post_join_delay="3"/>
  <clusternodes>
    <clusternode name="pcmk-1" nodeid="1">
      <fence/>
    </clusternode>
    <clusternode name="pcmk-2" nodeid="2">
      <fence/>
    </clusternode>
  </clusternodes>
  <cman/>
  <fencedevices/>
  <rm/>
</cluster>
	
例 C.1. Sample cluster.conf for a two-node cluster

C.2.2. Adding CMAN Support - corosync.conf

The alternative is to add the necessary cman configuration elements to corosync.conf. We recommend you place these directives in /etc/corosync/service.d/cman as they will differ between machines.
If you choose this approach, you would continue to start and stop Corosync with it's init script as previously described in this document.
[root@pcmk-1 ~]# cat <<-END >>/etc/corosync/service.d/cman
cluster {
    name: beekhof

    clusternodes {
            clusternode {
                    votes: 1
                    nodeid: 1
                    name: pcmk-1
            }
            clusternode {
                    votes: 1
                    nodeid: 2
                    name: pcmk-2
            }
    }
    cman {
            expected_votes: 2
            cluster_id: 123
            nodename: `uname -n`
            two_node: 1
            max_queued: 10
    }
}

service {
    name: corosync_cman
    ver: 0
}

quorum {
    provider: quorum_cman
}
END
例 C.2. Sample corosync.conf extensions for a two-node cluster

警告

Verify that nodename was set appropriately on each host.


[15] A failure to do this can lead to what is called internal split-brain - a situation where different parts of the stack disagree about whether some nodes are alive or dead - which quickly leads to unnecssary down-time and/or data corruption.

延​伸​阅​读​

Project Website
Cluster Commands
一​个​综​合​的​指​南​,包​含​了​Novell所​写​的​集​群​命​令​,可​以​在​这​里​被​找​到​:
Corosync

修​订​历​史​

修订历史
修订 1Mon May 17 2010Andrew Beekhof
Import from Pages.app

索引