从头开始搭建集群(二)

检验集群的安装

目录

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

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

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正常,我们可以开始检查其他部分是否正常.第?3?章?检验集群的安装

28

[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检查Pacemaker的安装

29

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 ]30第?4

31

使用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第?4?章?使用Pacemaker工具

32

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

33

创建一个主/备集群

目录

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

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

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

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

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

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。(作者怨念很深啊)

在我们做出任何改变之前,我们最好检查下配置文件。第?5?章?创建一个主/备集群

34

[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 ~]#

就像你看到的,这个工具发现了一些错误。

为了确保您数据的安全性 1

 ,请使用配备STONITH 2

的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

1

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

 一个常见的隔离手段。用关掉坏节点电源的办法来保证数据完整添加一个资源

35

另外一个重要的信息是 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?章?创建一个主/备集群

36

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 < 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 \防止资源在节点恢复后移动

37

? ? ? ? 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 有一个叫做 资源黏性值 的概念,它能够控制一个服务(资源)有多想呆

在它正在运行的节点上。你可以把它认为是无法提供服务的“代价”3

”。 Pacemaker为了达到最优分布

各个资源的目的,默认设置这个值为0。我们可以为每个资源定义不同的黏性值,但一般来说,更改默

认黏性值就够了。

3

 这里要注意的是Pacemaker定义的代价跟人们所想的不一样。如果管理员没有明确的指定参数(创建稳定环境所必须的),那么资

源个节点在Pacemaker处理列表中的顺序会隐式地创建参数第?5?章?创建一个主/备集群

38

[root@pcmk-2 ~]# 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