DRBDプレゼン用demo1

プライマリ/セカンダリの切替え

  • z151(元プライマリ側)
[root@z151 ~]# cd /mnt
[root@z151 mnt]# ll
合計 16
drwx------ 2 root root 16384  9月 27 11:43 lost+found
[root@z151 mnt]# touch testfile
[root@z151 mnt]# ll
合計 16
drwx------ 2 root root 16384  9月 27 11:43 lost+found
-rw-r--r-- 1 root root     0  9月 27 13:32 testfile
[root@z151 mnt]# cd ../
[root@z151 ~]# umount /dev/drbd0
[root@z151 ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
.host:/ on /mnt/hgfs type vmhgfs (rw,ttl=1)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/VMware Tools type iso9660 (ro,noexec,nosuid,nodev,uid=0)
[root@z151 ~]# drbdadm secondary r0
[root@z151 ~]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r----
    ns:8685916 nr:0 dw:214940 dr:8471258 al:73 bm:558 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@z152 ~]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r----
    ns:0 nr:12 dw:12 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@z152 ~]# drbdadm primary r0
[root@z152 ~]# cat /proc/drbd
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
 0: cs:Connected ro:Primary/Secondary ds:UpToDate/UpToDate C r----
    ns:0 nr:12 dw:12 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:b oos:0
[root@z152 ~]# mount /dev/drbd0 /mnt
[root@z152 ~]# mount
/dev/mapper/VolGroup00-LogVol00 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/drbd0 on /mnt type ext3 (rw)
[root@z152 ~]# cd /mnt
[root@z152 mnt]# ll
合計 16
drwx------ 2 root root 16384  9月 27 11:43 lost+found
-rw-r--r-- 1 root root     0  9月 27 13:32 testfile
[root@z152 mnt]# df
Filesystem           1K-ブロック    使用   使用可 使用% マウント位置
/dev/mapper/VolGroup00-LogVol00
                       9014656   4453368   4096036  53% /
/dev/sda1               101086     24853     71014  26% /boot
tmpfs                   257652         0    257652   0% /dev/shm
/dev/drbd0             5154656    141440   4751368   3% /mnt
  • 元に戻す

アンマウントせずにいきなりセカンダリにしようとすると怒られる

z152側
[root@z152 ha.d]# drbdadm secondary r0
0: State change failed: (-12) Device is held open by someone
Command 'drbdsetup 0 secondary' terminated with exit code 11
[root@z152 ha.d]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C
[root@z152 ha.d]# drbdadm secondary r0
[root@z152 ha.d]# /etc/init.d/drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res  cs         ro                   ds                 p  mounted  fstype
0:r0   Connected  Secondary/Secondary  UpToDate/UpToDate  C

z151側
[root@z151 /]# drbdadm primary r0
[root@z151 /]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C
[root@z151 /]# mount /dev/drbd0 /mnt
[root@z151 /]# service drbd status
drbd driver loaded OK; device status:
version: 8.3.8 (api:88/proto:86-94)
GIT-hash: d78846e52224fd00562f7c225bcc25b2d422321d build by mockbuild@builder10.centos.org, 2010-06-04 08:04:16
m:res  cs         ro                 ds                 p  mounted  fstype
0:r0   Connected  Primary/Secondary  UpToDate/UpToDate  C  /mnt     ext3
[root@z151 /]# 

Heartbeatのインストール及び設定

# yum install heartbeat

+ha.cfの設定
# /usr/share/doc/heartbeat-*/ha.cf /etc/ha.d/
/etc/ha.d/ha.cfは最初からないので、↑のようにサンプルファイルをコピーする必要があるらしい
# vi /etc/ha.d/ha.cf
以下のように設定

crm yes
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 30
#warntime 10
initdead 120
udpport 694
#baud   19200
#serial /dev/ttyS0      # Linux
#serial /dev/cuaa0      # FreeBSD
#serial /dev/cuad0      # FreeBSD 6.x
#serial /dev/cua/a      # Solaris
#bcast  eth0            # Linux
bcast   eth1            # Linux
#bcast  le0             # Solaris
#bcast  le1 le2         # Solaris
#ucast eth0 192.168.1.2
auto_failback on
#stonith baytech /etc/ha.d/conf/stonith.baytech
#stonith_host *     baytech 10.0.0.3 mylogin mysecretpassword
#stonith_host ken3  rps10 /dev/ttyS1 kathy 0 
#stonith_host kathy rps10 /dev/ttyS1 ken3 0 
#watchdog /dev/watchdog
node    z151.drbd
node    z152.drbd
#ping 10.10.10.254
#ping_group group1 10.10.10.254 10.10.10.253
#hbaping fc-card-name
#respawn userid /path/name/to/run
#respawn hacluster /usr/lib/heartbeat/ipfail
#apiauth client-name gid=gidlist uid=uidlist
#apiauth ipfail gid=haclient uid=hacluster
#hopfudge 1
#deadping 30
#hbgenmethod time
#realtime off
#debug 1
#apiauth ipfail uid=hacluster
#apiauth ccm uid=hacluster
#apiauth cms uid=hacluster
#apiauth ping gid=haclient uid=alanr,root
#apiauth default gid=haclient
#msgfmt  classic/netstring
# use_logd yes/no
#conn_logd_time 60
#compression    bz2
#compression_threshold 2
apiauth mgmtd uid=root
respawn root /usr/lib/heartbeat/mgmtd -v
↑Pacemaker Python GUIを使用するための設定

+logd.cfの設定
# cp /usr/share/doc/heartbeat-*/logd.cf /etc/
# vi /etc/logd.cf
以下のように設定

debugfile /var/log/ha-debug
logfile /var/log/ha-log
#logfacility    daemon
logfacility     none
#entity logd
#useapphbd no
#sendqlen 256 
#recvqlen 256

+authkeysの設定
# cp /usr/share/doc/heartbeat-*/authkeys /etc/ha.d/ ← authkeysのサンプルをコピー
# vi /etc/ha.d/authkeys 
以下のように設定

auth 2
#1 crc
2 sha1 HI!
#3 md5 Hello!

# ll /etc/ha.d/authkeys
-rw-r--r-- 1 root root 39  9月 27 17:12 /etc/ha.d/authkeys
# chmod 600 /etc/ha.d/authkeys
# ll /etc/ha.d/authkeys
-rw------- 1 root root 39  9月 27 17:12 /etc/ha.d/authkeys

↑これらを相手(セカンダリ)にコピー

# scp /etc/ha.d/ha.cf 192.168.11.181:/etc/ha.d/
# scp /etc/logd.cf 192.168.11.181:/etc/
# scp /etc/ha.d/authkeys 192.168.11.181:/etc/ha.d/

これでheartbeatを起動させると、下記のエラーが出た

# /etc/init.d/heartbeat start
Starting High-Availability services: 
                                                           [失敗]
heartbeat[30911]: 2010/09/30_10:24:59 info: Version 2 support: yes
heartbeat: udpport setting must precede media statementsheartbeat[30911]: 2010/09/30_10:24:59 ERROR: Duplicate apiauth directive for API client mgmtd: [mgmtd uid=root]
heartbeat[30911]: 2010/09/30_10:24:59 ERROR: Invalid apiauth directive [mgmtd uid=root]
heartbeat[30911]: 2010/09/30_10:24:59 info: Syntax: apiauth client [uid=uidlist] [gid=gidlist]
heartbeat[30911]: 2010/09/30_10:24:59 info: Where uidlist is a comma-separated list of uids,
heartbeat[30911]: 2010/09/30_10:24:59 info: and gidlist is a comma-separated list of gids
heartbeat[30911]: 2010/09/30_10:24:59 info: One or the other must be specified.
heartbeat[30911]: 2010/09/30_10:24:59 ERROR: Heartbeat not started: configuration error.
heartbeat[30911]: 2010/09/30_10:24:59 ERROR: Configuration error, heartbeat not started.

どうやらharesourcesもサンプルをコピーしないといけないらしい
heartbeat/出遭ったエラー - PukiWiki

# cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/

heartbeat起動後、crm_monを実行すると下記のエラーが

# crm_mon
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode
Critical: Unable to connect to the CIB

hnakamur’s blog: CentOSでheartbeatを使おうとしたがうまくいかずによると、これどうやらCentOS(特に5.x系)の既知のバグらしい
やまいった。だが対処法が用意されている
Heartbeat+α - Linuxめもがっき
しかしこの通りにやると

# /usr/lib/heartbeat/haresources2cib.py /etc/ha.d/haresources > /var/lib/heartbeat/crm/cib.xml
can not parse this line:z151.drbd
can not parse this line:IPaddr2::192.168.1.180/24/eth0/192.168.1.255
can not parse this line:drbddisk::r0
can not parse this line:Filesystem::/dev/drbd0::/mnt 
cib.xml or cib.xml.sig exist in /var/lib/heartbeat/crm/
please remove them before generating new cib.xml

どうしてもcib.xmlが自動生成されてしまい邪魔
しかもharesourcesは次のように1行で書かないといけないらしい(これは恥ずかしい)

z151.drbd IPaddr2::192.168.1.180/24/eth0/192.168.1.255 drbddisk::r0 Filesystem::/dev/drbd0::/mnt

ちなみにこのharesources、両ノードとも同じ内容にしなければならないというのだが・・
hnakamur’s blog: CentOSでheartbeatでVIP引き継ぎ

/etc/ha.d/haresources
プライマリのノードと仮想IPアドレスを設定します。ですのでcent1でもcent2でも同じ内容にします。

しかしHAクラスタシステム構築(Heartbeat+DRBD+Apache) - CentOSで自宅サーバー構築では、違う内容になっている・・

[root@cl1 ~]# vi haresources ← haresources新規作成※ノード1
cl1.centossrv.com \ ← ノード1ホスト名(「uname -n」コマンドで表示される名前)
[root@cl2 ~]# vi haresources ← haresources新規作成※ノード2
cl2.centossrv.com \ ← ノード2ホスト名(「uname -n」コマンドで表示される名前)

基本的にはHAクラスタシステム構築(Heartbeat+DRBD+Apache) - CentOSで自宅サーバー構築に従えばOK

# rm -f /var/lib/heartbeat/crm/cib.xml* ; /usr/lib/heartbeat/haresources2cib.py /etc/ha.d/haresources
# cd /var/lib/heartbeat/crm/
# ll
合計 8
-rw-r--r-- 1 hacluster haclient 3962 10月  5 14:04 cib.xml
-rw-r--r-- 1 root      root     3962 10月  5 14:03 cib.xml_back
# diff -C 0  cib.xml  cib.xml_back
*** cib.xml     2010-10-05 14:04:28.000000000 +0900
--- cib.xml_back        2010-10-05 14:03:49.000000000 +0900
***************
*** 38,39 ****
!                                                       <nvpair id="IPaddr2_1_attr_1" name="nic" value="eth0"/>
!                                                       <nvpair id="IPaddr2_1_attr_2" name="cidr_netmask" value="24"/>
--- 38,39 ----
!                                                       <nvpair id="IPaddr2_1_attr_1" name="nic" value="24"/>
!                                                       <nvpair id="IPaddr2_1_attr_2" name="cidr_netmask" value="eth0"/>
# crm_verify -x /var/lib/heartbeat/crm/cib.xml
# mv /etc/ha.d/haresources /etc/ha.d/haresources_back
# /etc/rc.d/init.d/heartbeat start
Starting High-Availability services: 
                                                           [  OK  ]
# chkconfig heartbeat on
# ip addr show eth0
3: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
    link/ether 00:0c:29:af:ea:67 brd ff:ff:ff:ff:ff:ff
    inet 192.168.11.180/24 brd 192.168.11.255 scope global eth0
    inet6 fe80::20c:29ff:feaf:ea67/64 scope link 
       valid_lft forever preferred_lft forever
# crm_mon
Defaulting to one-shot mode
You need to have curses available at compile time to enable console mode


============
Last updated: Tue Oct  5 14:08:11 2010
Current DC: z152.drbd (252d3c17-5fce-4ca1-ba4d-42d3adc90b3a)
2 Nodes configured.
0 Resources configured.
============

Node: z152.drbd (252d3c17-5fce-4ca1-ba4d-42d3adc90b3a): online
Node: z151.drbd (d2c277ef-9c3f-42f0-84ad-e4575ae0390d): online

上記の「chkconfig heartbeat on」をやったところ、セカンダリのほうでリブートを何度も繰り返すというおかしな現象が

z152 heartbeat: [3791]: EMERG: Rebooting system.  Reason: /usr/lib/heartbeat/crmd

heartbeat - PukiWikiによると

ha.cfにてcrm onとする(yesでも可)。
すると起動に失敗し、システムが自動的に再起動してしまう。
調べてみると、crm respawnにすれば再起動はしない模様。

確かにこうすれば無限自動リブート現象は起きなくなったが、今回はそもそもPacemakerを使用するので、「crm respawn」ではなく「pacemaker on」とした。これでも現象は起きなくなった

※こうしてみるとDRBDのファイルをソースから理解するにはXMLの知識があるとよりよい。XMLの資格でも取るかなあ・・

  • cib.xml編集時の注意点

アナログを愛するデジタル生活室(別館) 2010年02月

/var/lib/heartbeat/cib.xml
このxmlファイルにリソースの設定や、リソースの持ち分に関する記述をしていくのですが、
この設定ファイルはheartbeatの再起動では再読み込みしてくれません。
専用のコマンドを使用します。
cibadmin -U -x /cib.xml
気をつけなければならないのは
/var/lib/heartbeat/cib.xml
を直接編集して、heartbeatを再起動した場合、cib.xmlデグレします。

yum update プラグインエラー?

yumを使おうとすると以下のようなおかしなエラーが発生

# yum install heartbeat
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 7592.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum-updatesd-he
    Memory :  15 M RSS ( 28 MB VSZ)
    Started: Mon Sep 27 15:04:02 2010 - 2:47:03 ago
    State  : Sleeping, pid: 7592

Fedora Core 6でyumが実行できない場合は − @ITに従い、下記を実行

# ps x | grep yum
 4024 ?        SN     0:00 /usr/bin/python -tt /usr/sbin/yum-updatesd
 7592 ?        SN     0:00 /usr/bin/python -tt /usr/libexec/yum-updatesd-helper --check --dbus
12234 pts/2    S+     0:00 grep yum
# kill 4024
# ps x | grep yum
 7592 ?        SN     0:00 /usr/bin/python -tt /usr/libexec/yum-updatesd-helper --check --dbus
12556 pts/2    R+     0:00 grep yum
# service yum-updatesd stop
yum-updates を停止中:                                      [失敗]
# chkconfig yum-updatesd off
# chkconfig --list yum-updatesd
yum-updatesd    0:off   1:off   2:off   3:off   4:off   5:off   6:off

ところが下記のように再び同じエラーが出るので、4024(yum-updatesd)だけでなく、7592(yum-updatesd-helper)もkillする必要があるらしい

# yum install heartbeat
Loaded plugins: fastestmirror
Existing lock /var/run/yum.pid: another copy is running as pid 7592.
Another app is currently holding the yum lock; waiting for it to exit...
  The other application is: yum-updatesd-he
    Memory :  15 M RSS ( 28 MB VSZ)
    Started: Mon Sep 27 15:04:02 2010 - 2:57:08 ago
    State  : Sleeping, pid: 7592


Exiting on user cancel.
# kill 7592
# ps x | grep yum
12644 pts/2    R+     0:00 grep yum
# yum install heartbeat