LoginSignup
35
34

More than 5 years have passed since last update.

CentOS7 3台でクラスタ構築、仮想IPを体験

Last updated at Posted at 2014-12-14

参考

リソース設定例

ノード説明

  • n1: 192.168.100.110
  • n2: 192.168.100.111
  • n3: 192.168.100.112
  • 仮想IP: 192.168.100.100を割り振りたい

パッケージインストール

インストール
yum install -y corosync pacemaker pcs
  • corosync : クラスタ構築
  • pacemaker : リソース制御を行う。仮想IP付与とか。
  • pcs : pacemakerをcliで操作するコマンド

クラスタ構築

corosync設定

ひな形コピー
cd /etc/corosync/
cp -a corosync.conf{.example.udpu,}
/etc/corosync/corosync.conf
# Please read the corosync.conf.5 manual page
totem {
        version: 2

        crypto_cipher: none
        crypto_hash: none

        interface {
                ringnumber: 0
-               bindnetaddr: 10.16.35.0
+               bindnetaddr: 192.168.100.0
                mcastport: 5405
                ttl: 1
        }
        transport: udpu
}

logging {
        fileline: off
        to_logfile: yes
-       to_syslog: yes
+       to_syslog: no
        logfile: /var/log/cluster/corosync.log
        debug: off
        timestamp: on
        logger_subsys {
                subsys: QUORUM
                debug: off
        }
}

nodelist {
        node {
-               ring0_addr: 10.16.35.101
+               ring0_addr: 192.168.100.110
                nodeid: 1
        }

        node {
-               ring0_addr: 10.16.35.102
+               ring0_addr: 192.168.100.111
                nodeid: 2
        }

        node {
-               ring0_addr: 10.16.35.103
+               ring0_addr: 192.168.100.112
+               nodeid: 3
        }

-       node {
-               ring0_addr: 10.16.35.104
-       }

-       node {
-               ring0_addr: 10.16.35.105
-       }
}

quorum {
        # Enable and configure quorum subsystem (default: off)
        # see also corosync.conf.5 and votequorum.5
-       #provider: corosync_votequorum
+       provider: corosync_votequorum
+       expected_votes: 3
}
  • 3台とも上記設定にする。

pacemaker設定

設定できる項目は以下だが、よくわからないので今回は変更しない。

/etc/sysconfig/pacemaker
# PCMK_STACK=cman
# PCMK_debug=yes|no|crmd|pengine|cib|stonith-ng|attrd|pacemakerd
# PCMK_logfile=/var/log/pacemaker.log
# PCMK_logfacility=none|daemon|user|local0|local1|local2|local3|local4|local5|local6|local7
# PCMK_logpriority=emerg|alert|crit|error|warning|notice|info|debug
# PCMK_trace_functions=function1,function2,function3
# PCMK_trace_files=file.c,other.h
# PCMK_trace_formats="Sent delete %d"
# PCMK_trace_tags=tag1,tag2
# PCMK_trace_blackbox=fn:line,fn2:line2,...
# PCMK_blackbox=yes|no|crmd|pengine|cib|stonith-ng|attrd|pacemakerd
# PCMK_uname_is_uuid=no
# PCMK_schema_directory=/some/path
# PCMK_authkey_location=/etc/pacemaker/authkey
# PCMK_remote_port=3121
# PCMK_ipc_type=shared-mem|socket|posix|sysv
# PCMK_ipc_buffer=20480
# PCMK_valgrind_enabled=yes
# PCMK_valgrind_enabled=cib,crmd
# PCMK_callgrind_enabled=yes
# PCMK_callgrind_enabled=cib,crmd

サービス起動

systemctl start pacemaker
  • pacemakerがcorosyncを起動する

ログ

  • /var/log/pacemaker.log
  • /var/log/cluster/corosync.log
状態確認
# crm_mon -A
Last updated: Sun Dec 14 08:56:08 2014
Last change: Sun Dec 14 08:56:08 2014 via crmd on n3
Stack: corosync
Current DC: n3 (1) - partition with quorum
Version: 1.1.10-32.el7_0.1-368c726
3 Nodes configured
0 Resources configured


Online: [ n1 n2 n3 ]


Node Attributes:
* Node n1:
* Node n2:
* Node n3:

pcsコマンドで仮想IPの設定

# STONITHを無効
pcs property set stonith-enabled=false

# スプリットブレインが発生してもクォーラムが特別な動作を行わないように設定
pcs property set no-quorum-policy=ignore

# 仮想IP
pcs resource create dbvip ocf:heartbeat:IPaddr2 \
  ip=192.168.100.100 cidr_netmask=24 \
  nic="eth1" \
  op monitor interval=30s

ocfとは/usr/lib/ocf/resource.d/heartbeat/以下にあるスクリプト

crm_mon -A
 Last updated: Sun Dec 14 09:07:34 2014
 Last change: Sun Dec 14 09:06:31 2014 via cibadmin on n1
 Stack: corosync
 Current DC: n1 (1) - partition with quorum
 Version: 1.1.10-32.el7_0.1-368c726
 3 Nodes configured
 1 Resources configured


 Online: [ n2 n3 n1 ]

+dbvip   (ocf::heartbeat:IPaddr2):  Started n3

 Node Attributes:
 * Node n2:
 * Node n3:
 * Node n1:
  • n3にて192.168.100.100が付与されていることが確認できる。
  • OS再起動しても仮想IPがpacemakerによって自動で付与されることを確認。

リソースの削除はpcs resource delete dbvip

pcsコマンドでコンフィグ確認

# pcs config
Cluster Name:
Corosync Nodes:
 192.168.100.110 192.168.100.111 192.168.100.112
Pacemaker Nodes:
 n2 n3 n1

Resources:
 Resource: dbvip (class=ocf provider=heartbeat type=IPaddr2)
  Attributes: ip=192.168.100.100 cidr_netmask=24 nic=eth1
  Operations: start interval=0s timeout=20s (dbvip-start-timeout-20s)
              stop interval=0s timeout=20s (dbvip-stop-timeout-20s)
              monitor interval=30s (dbvip-monitor-interval-30s)

Stonith Devices:
Fencing Levels:

Location Constraints:
Ordering Constraints:
Colocation Constraints:

Cluster Properties:
 cluster-infrastructure: corosync
 dc-version: 1.1.10-32.el7_0.1-368c726
 no-quorum-policy: ignore
 stonith-enabled: false

設定ファイルを書き出し、読み込み

設定の書き出し
pcs cluster cib output.cib
変更
pcs -f output.cib <command>
設定の読み込み
pcs cluster cib-push output.cib
35
34
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
35
34