この手のインフラよりな話は苦手ですが、いろいろと読み漁って、 手元のcentos7で試してみました。
全体構成
https://dev.mysql.com/doc/refman/5.6/ja/ha-drbd.html
構成図
│192.168.63.100(VIP by pacemaker) active 192.168.63.16 ┌┴─────────┐192.168.63.17 stand by ┌──────────┴──┐ ┌─┴───────────┐ │CentOs7Ha1 │ │CentOs7Ha2 │ │┌───────────┐│ 相互監視 │┌───────────┐│ ││1-A)pacemaker+corosync│←─────→│2-A)pacemaker+corosync││ │└┬─────────┬┘│ │└┬─────────┬┘│ │┌┴────┐┌───┴┐│ │┌┴───┐┌────┴┐│ ││1-B)mysql ││1-C)DRBD││ ││2-C)DRBD││2-B)mysql ││ │└───┬─┘└───┬┘│ │└┬───┘└─┬───┘│ │ └------┐ │ │ │ │ ┌------┘ │ │┌─────┐┌┴──┴┐│一方向sync│┌┴──┴┐┌─────┐│ ││centos7 ││1-D)DISK│──────→│2-D)DISK││centos7 ││ │└─────┘└────┘│(fail back│└────┘└─────┘│ └─────────────┘ なし) └─────────────┘
pacemaker と corosync
linux-had proj で開発されていた heartbeatの後継で、 現在 ClusterLabs ( clusterlabs.org )から配布.
corosync がノード死活監視を行い、node down時に、 pacemakerがリソース制御(mysqlやdrbd等の起動や、VIPの付替え等)を行います。 (pacemaker が mysqlの起動/停止を行う為、systemctlへの登録は不要です)
drbd
node間のデータsyncに利用します。 drbdは、diskの指定したパーティションを即時にsecondaryなnodeへコピーします。 drbdが管理するパーティションに対し、本物のディスクのようにアクセスできます。
参考url
全く初めて触りましたので、いろいろと読み漁りました。
- DRBDはじめの一歩 - Qiita
- CentOS7のMariaDB(MySQL)をDRBDでHA化 | | 1Q77
- Pacemakerでかんたんクラスタリング体験してみよう!:連載|gihyo.jp … 技術評論社
- 動かして理解するPacemaker ~CRM設定編~ その1 « Linux-HA Japan
作業をすすめる上での注意点
以下に手順を記載しますが...
- 全ホストへの作業が必要な場合と、1つのホストのみへの作業があります。[ALL HOST]等と記載
- pacemakerやdrbdのinstall順には注意が必要で、間違えると、syncできないなどの問題が発生します。本エントリの順に作業すると良いと思います。(多分)
各ホスト IPアドレス等のNW系設定
今回、virtual boxで試していますが、 virtual boxのNATネットワーク + ホストオンリーアダプタを利用し、 更にcentos側で以下のようにNW設定しています。
[ALL HOST]$ sudo vi /etc/sysconfig/network-scripts/ifcfg-enp0s8 TYPE=Ethernet PROXY_METHOD=none BROWSER_ONLY=no BOOTPROTO=none #BOOTPROTO=dhcp DEFROUTE=yes IPV4_FAILURE_FATAL=no IPV6INIT=no IPV6_AUTOCONF=no IPV6_DEFROUTE=no IPV6_FAILURE_FATAL=no IPV6_ADDR_GEN_MODE=stable-privacy NAME=enp0s8 UUID=b0f60e72-6181-489e-a077-4b0d547f235a DEVICE=enp0s8 ONBOOT=yes [ALL HOST]$ sudo vi /etc/selinux/config SELINUX=disabled [ALL HOST]$ sudo systemctl stop firewalld [ALL HOST]$ sudo systemctl disable firewalld [ALL HOST]$ sudo vi /etc/hosts 192.168.63.16 centos7ha1.a5.jp 192.168.63.17 centos7ha2.a5.jp
DRDB の yum install や 設定
elrepo リポジトリの登録
公開鍵の入手と、elrepo リポジトリの登録
[ALL HOST]$ sudo rpm --import https://www.elrepo.org/RPM-GPG-KEY-elrepo.org [ALL HOST]$ sudo rpm -Uvh http://www.elrepo.org/elrepo-release-7.0-3.el7.elrepo.noarch.rpm
DRDB の yum install
- このエントリを記載する前に、sourcからのinstallを試しましたが、依存ライブラリが多い為か、エラーが頻発したので、パッケージでinstallしています。
- 2019/9時点でdrbdの最新はver.9.0ですが、私の環境(centos7)ではうまく動作させることができなかった為、ver.8.4を使用しています
[ALL HOST]$ sudo yum install kmod-drbd84 drbd84-utils
DRDB の設定 (その1/2)
以下のように global_common.conf の変更と、r0.res の新規作成を行います。
※この設定を行い、更にこの後のdisk追加を行うまで、DRDBを起動する必要はありません。
global_common.conf には、同期レプリケーションである「protocol C」の追記のみ実施
[ALL HOST]$ sudo vi /etc/drbd.d/global_common.conf global { usage-count yes; udev-always-use-vnr; # treat implicit the same as explicit volumes } common { handlers { } startup { } options { } disk { } net { protocol C; } }
diskをsyncする単位で *.resファイルを作成します。
※ 今回「r0」というリソース名にしていますが、リソース名は任意のものを設定できます。
[ALL HOST]$ sudo vi /etc/drbd.d/r0.res resource r0 { meta-disk internal; device /dev/drbd0; # ↓こちらの「/dev/sdb1」は追加したdiskのpartitionにより異なります disk /dev/sdb1; on centos7ha1.a5.jp { address 192.168.63.16:7788; } on centos7ha2.a5.jp { address 192.168.63.17:7788; } }
disk(パーティション)の追加
centos側での追加手順
「/dev/sdb (3G)」が DRBD用に追加したdiskです。 diskは認識されているが、領域(partition)が確保できていないこと (sbd1がない)が分かります。
[ALL HOST]$ lsblk -pi NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT /dev/sda 8:0 0 25G 0 disk |-/dev/sda1 8:1 0 1G 0 part /boot `-/dev/sda2 8:2 0 24G 0 part |-/dev/mapper/centos-root 253:0 0 21.5G 0 lvm / `-/dev/mapper/centos-swap 253:1 0 2.5G 0 lvm [SWAP] /dev/sdb 8:16 0 3G 0 disk /dev/sr0 11:0 1 1024M 0 rom
fdiskによるパーティション作成. (対話式PGで迷うことなく追加できます)
[ALL HOST]$ sudo fdisk /dev/sdb Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0x7ebbb270. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): p Partition number (1-4, default 1): First sector (2048-6291455, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-6291455, default 6291455): Using default value 6291455 Partition 1 of type Linux and of size 3 GiB is set Command (m for help): W The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks.
diskが認識されていることを再チェック. (diskは認識され、領域(partition)も確保済)
[ALL HOST]$ lsblk -pi NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT /dev/sda 8:0 0 25G 0 disk |-/dev/sda1 8:1 0 1G 0 part /boot `-/dev/sda2 8:2 0 24G 0 part |-/dev/mapper/centos-root 253:0 0 21.5G 0 lvm / `-/dev/mapper/centos-swap 253:1 0 2.5G 0 lvm [SWAP] /dev/sdb 8:16 0 3G 0 disk `-/dev/sdb1 8:17 0 3G 0 part /dev/sr0 11:0 1 1024M 0 rom
ただし、この時点でも df -h で /dev/sdb1 が認識されていないことが分かります。 この後の drbdadm コマンドで /dev/sdb1 認識等を行います。
[ALL HOST]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 22G 1.1G 21G 5% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.6M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 144M 871M 15% /boot tmpfs 379M 0 379M 0% /run/user/1000 tmpfs 379M 0 379M 0% /run/user/0
DRDB の設定 (その2/2)
DRDBのメタデータ作成
以下のコマンドで、/dev/sdb1内にDRDBのメタデータが作成されるようです。 (DRDBのメタデータの内容は理解できていません)
[ALL HOST]$ sudo drbdadm create-md r0 initializing activity log initializing bitmap (160 KB) to all zero Writing meta data... New drbd meta data block successfully created. success $
DRDBの起動と、CentOs7Ha1のprimary設定
以下のコマンドで DRDB を起動すると、各hostがsecondaryとして起動します。
[ALL HOST]$ sudo drbdadm up r0 --== Thank you for participating in the global usage survey ==-- The server's response is: you are the 68954th user to install this version [ALL HOST]$ cat /proc/drbd version: 8.4.11-1 (api:1/proto:86-101) GIT-hash: 66145a308421e9c124ec391a7848ac20203bb03c build by mockbuild@, ..... 0: cs:Connected ro:Secondary/Secondary ds:Inconsistent/Inconsistent C r----- ns:0 nr:0 dw:0 dr:0 al:8 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:3144572
「Thank you ~」のメッセージは、drbdadm が LINBIT と通信し、表示しているようですが 気にする必要はないはずです。
次に、centos7ha1.a5.jp で以下のコマンドを実行し、primaryに昇格させます。
[centos7ha1.a5.jp]$ sudo drbdadm primary r0 --force
systemctlにより drbdデーモンを起動します。 (本番?環境においては、pacemakerがdrbdの起動を管理する為、systemctl start は不要)
[ALL HOST]$ sudo systemctl start drbd.service
[ALL HOST]$ sudo drbdadm attach r0
deviceのフォーマットと mount
centos7ha1.a5.jp に対し、以下の各コマンドを実行すると、df -hでも認識されます。
[centos7ha1.a5.jp]$ sudo mkfs.xfs /dev/drbd0 meta-data=/dev/drbd0 isize=512 agcount=4, agsize=196536 blks = sectsz=512 attr=2, projid32bit=1 = crc=1 finobt=0, sparse=0 data = bsize=4096 blocks=786143, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=1 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 [ALL HOST]$ sudo mkdir /drbd_data [centos7ha1.a5.jp]$ sudo mount /dev/drbd0 /drbd_data [centos7ha1.a5.jp]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 22G 1.1G 21G 5% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.6M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 144M 871M 15% /boot tmpfs 379M 0 379M 0% /run/user/1000 tmpfs 379M 0 379M 0% /run/user/0 /dev/drbd0 3.0G 33M 3.0G 2% /drbd_data
/drbd_data ( /dev/drbd0 )への書込みテスト
試しに 500GBのファイルを作成します
[centos7ha1.a5.jp]$ cd /drbd_data [centos7ha1.a5.jp]$ sudo dd if=/dev/zero of=1G.dummy bs=1M count=500 [centos7ha1.a5.jp]$ df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 22G 1.1G 21G 5% / devtmpfs 1.9G 0 1.9G 0% /dev tmpfs 1.9G 0 1.9G 0% /dev/shm tmpfs 1.9G 8.5M 1.9G 1% /run tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup /dev/sda1 1014M 144M 871M 15% /boot tmpfs 379M 0 379M 0% /run/user/1000 /dev/drbd0 3.0G 533M 2.5G 18% /drbd_data
centos7ha2.a5.jp へ syncされたことを確認する為、 centos7ha1.a5.jp 側で umount や secondary化を行います。
[centos7ha1.a5.jp]$ cd / ## ← /drbd_data にいる状態では umount できない為 [centos7ha1.a5.jp]$ sudo umount /drbd_data [centos7ha1.a5.jp]$ sudo drbdadm secondary r0
次にcentos7ha2.a5.jp 側で primary化し、mount すると、syncされた結果を確認できます
[centos7ha2.a5.jp]$ sudo drbdadm primary r0 [centos7ha2.a5.jp]$ sudo mount /dev/drbd0 /drbd_data [centos7ha2.a5.jp]$ ls -l /drbd_data total 512000 -rw-r--r-- 1 root root 524288000 Sep 14 19:26 1G.dummy
sync結果を確認後、centos7ha1.a5.jp を primaryに戻しておきます
[centos7ha2.a5.jp]$ cd / ## ← /drbd_data にいる状態では umount できない為 [centos7ha2.a5.jp]$ sudo umount /drbd_data [centos7ha2.a5.jp]$ sudo drbdadm secondary r0 [centos7ha1.a5.jp]$ sudo drbdadm primary r0 [centos7ha1.a5.jp]$ sudo mount /dev/drbd0 /drbd_data
ここまでは、drbdのinstallと設定で、以降、mysql のinstallに続きます。
mysql ( mariadb ) のinstall
mysql ( mariadb ) のinstall
[ALL HOST]$ sudo yum install mariadb-server mariadb
mysql ( mariadb ) 用 datadirの準備
mysqlのdatadirの準備ができたら、最後にumount
[centos7ha1.a5.jp]$ sudo mkdir /drbd_data/mysql_data [centos7ha1.a5.jp]$ sudo mysql_install_db --datadir=/drbd_data/mysql_data --user=mysql [centos7ha1.a5.jp]$ sudo umount /drbd_data
mysql ( mariadb ) の設定
[ALL HOST]$ sudo vi /etc/my.cnf [mysqld] symbolic-links=0 bind_address = 0.0.0.0 datadir = /drbd_data/mysql_data pid_file = /var/run/mariadb/mysqld.pid socket = /var/run/mariadb/mysqld.sock [mysqld_safe] bind_address = 0.0.0.0 datadir = /drbd_data/mysql_data pid_file = /var/run/mariadb/mysqld.pid socket = /var/run/mariadb/mysqld.sock !includedir /etc/my.cnf.d
mysqlのinstallや設定は、一旦、ここまでとし、create database等は後程、行います。
pcs, pacemaker, corosync の install
installと起動
依存関係から、以下により pcs, pacemaker, corosync がまとめてinstallされます。
[ALL HSOT]$ sudo yum install pcs
先程のinstallにより hacluster ユーザが作成される為、passwdを設定します。 また、pcsd の自動起動等も設定します。
[ALL HSOT]$ sudo passwd hacluster [ALL HSOT]$ sudo systemctl enable pcsd [ALL HSOT]$ sudo systemctl start pcsd
クラスタ間の認証と、クラスタ作成
[centos7ha1.a5.jp]$ sudo pcs cluster auth centos7ha1.a5.jp centos7ha2.a5.jp \ -u hacluster -p sasa24ki centos7ha2.a5.jp: Authorized centos7ha1.a5.jp: Authorized [centos7ha1.a5.jp]$ sudo pcs cluster setup --name mycluster \ centos7ha1.a5.jp centos7ha2.a5.jp --force Destroying cluster on nodes: centos7ha1.a5.jp, centos7ha2.a5.jp... centos7ha2.a5.jp: Stopping Cluster (pacemaker)... centos7ha1.a5.jp: Stopping Cluster (pacemaker)... centos7ha2.a5.jp: Successfully destroyed cluster centos7ha1.a5.jp: Successfully destroyed cluster Sending 'pacemaker_remote authkey' to 'centos7ha1.a5.jp', 'centos7ha2.a5.jp' centos7ha2.a5.jp: successful distribution of the file 'pacemaker_remote authkey' centos7ha1.a5.jp: successful distribution of the file 'pacemaker_remote authkey' Sending cluster config files to the nodes... centos7ha1.a5.jp: Succeeded centos7ha2.a5.jp: Succeeded Synchronizing pcsd certificates on nodes centos7ha1.a5.jp, centos7ha2.a5.jp... centos7ha2.a5.jp: Success centos7ha1.a5.jp: Success Restarting pcsd on the nodes in order to reload the certificates... centos7ha2.a5.jp: Success centos7ha1.a5.jp: Success [centos7ha1.a5.jp]$ sudo pcs cluster start --all centos7ha1.a5.jp: Starting Cluster (corosync)... centos7ha2.a5.jp: Starting Cluster (corosync)... centos7ha2.a5.jp: Starting Cluster (pacemaker)... centos7ha1.a5.jp: Starting Cluster (pacemaker)... [centos7ha1.a5.jp]$ sudo pcs status Cluster name: mycluster WARNINGS: No stonith devices and stonith-enabled is not false Stack: corosync Current DC: centos7ha2.a5.jp (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum Last updated: Sat Sep 7 20:14:02 2019 Last change: Sat Sep 7 20:13:36 2019 by hacluster via crmd on centos7ha2.a5.jp 2 nodes configured 0 resources configured Online: [ centos7ha1.a5.jp centos7ha2.a5.jp ] No resources Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled
クラスタ作成により、/etc/corosync/corosync.conf が作成されます
[ALL HSOT]$ cat /etc/corosync/corosync.conf totem { version: 2 cluster_name: mycluster secauth: off transport: udpu } nodelist { node { ring0_addr: centos7ha1.a5.jp nodeid: 1 } node { ring0_addr: centos7ha2.a5.jp nodeid: 2 } } quorum { provider: corosync_votequorum two_node: 1 } logging { to_logfile: yes logfile: /var/log/cluster/corosync.log to_syslog: yes }
クラスタの起動
クラスタの起動と、その状態確認は以下の通り
[centos7ha1.a5.jp]$ sudo pcs cluster start --all centos7ha1.a5.jp: Starting Cluster (corosync)... centos7ha2.a5.jp: Starting Cluster (corosync)... centos7ha1.a5.jp: Starting Cluster (pacemaker)... centos7ha2.a5.jp: Starting Cluster (pacemaker)... [ALL HOST]$ sudo pcs status Cluster name: mycluster WARNINGS: No stonith devices and stonith-enabled is not false Stack: corosync Current DC: centos7ha2.a5.jp (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum Last updated: Sat Sep 14 20:14:39 2019 Last change: Sat Sep 14 20:14:23 2019 by hacluster via crmd on centos7ha2.a5.jp 2 nodes configured 0 resources configured Online: [ centos7ha1.a5.jp centos7ha2.a5.jp ] No resources Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled [ALL HOST]$ sudo pcs status corosync Membership information ---------------------- Nodeid Votes Name 1 1 centos7ha1.a5.jp (local) 2 1 centos7ha2.a5.jp
pacemaker の 設定
## 現在の設定をfileに保存 [centos7ha1.a5.jp]$ sudo pcs cluster cib clust_cfg ## stonith (不安定ノードの電源断による強制停止/再起動機能)は無効 [centos7ha1.a5.jp]$ pcs property set stonith-enabled=false ## quorum の無効化 ## (過半数のノードが参加しているグループに決定権を与える仕組み。 ## 2ノード構成では使えない) [centos7ha1.a5.jp]$ sudo pcs -f clust_cfg property set no-quorum-policy=ignore ## failback を抑制 ## (「failback」を有効にすると、障害復旧時のリカバリ手順?が複雑になると考えた為) [centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource defaults resource-stickiness=200
インターネットで検索すると、「resource-stickiness=INFINITY」としているケースを 多く見ますが、今後、きちんと調べた方がよいかもしれません。
DRBD の resource として r0 (/etc/drbd.d/r0.res ) を指定
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource create mysql_data ocf:linbit:drbd \ drbd_resource=r0 op monitor interval=30s [centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource master MySQLClone mysql_data \ master-max=1 master-node-max=1 \ clone-max=2 clone-node-max=1 \ notify=true
mysql_fs という名前で /dev/drbd0 を /drbd_data にマウントする resource を定義
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource create mysql_fs Filesystem \ device="/dev/drbd0" directory="/drbd_data" \ fstype="xfs"
MySQLClone には mysql_fs が必須
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint colocation add mysql_fs \ with MySQLClone INFINITY with-rsc-role=Master
MySQLClone を master に昇格させる際、 mysql_fs を開始
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint order promote MySQLClone \ then start mysql_fs
mysql_service resource の作成、mariadb (mysql) の起動設定
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource create mysql_service \ ocf:heartbeat:mysql \ binary="/usr/bin/mysqld_safe" \ config="/etc/my.cnf" \ datadir="/drbd_data/mysql_data" \ pid="/var/lib/mysql/mysql.pid" \ socket="/var/lib/mysql/mysql.sock" \ additional_parameters="--bind-address=0.0.0.0" \ op start timeout=60s \ op stop timeout=60s \ op monitor interval=20s timeout=30s
mysql_fs resource 起動しているnodeで mysql_service を起動
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint colocation add mysql_service \ with mysql_fs INFINITY
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint order mysql_fs then mysql_service Adding mysql_fs mysql_service (kind: Mandatory) (Options: first-action=start then-action=start)
VIP resource を定義
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource create mysql_VIP ocf:heartbeat:IPaddr2 \ ip=192.168.63.100 cidr_netmask=32 \ op monitor interval=30s sudo pcs -f clust_cfg resource create mysql_VIP ocf:heartbeat:IPaddr2 \ ip=192.168.63.100 cidr_netmask=24 \ op monitor interval=300s
mysql_VIP は mysql_service の実行ノードで実行
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint colocation add mysql_VIP \ with mysql_service INFINITY
mysql_service の後に mysql_VIP を開始
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint order mysql_service then mysql_VIP Adding mysql_service mysql_VIP (kind: Mandatory) (Options: first-action=start then-action=start)
設定(制約)確認
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg constraint Location Constraints: Ordering Constraints: promote MySQLClone then start mysql_fs (kind:Mandatory) start mysql_fs then start mysql_service (kind:Mandatory) start mysql_service then start mysql_VIP (kind:Mandatory) Colocation Constraints: mysql_fs with MySQLClone (score:INFINITY) (with-rsc-role:Master) mysql_service with mysql_fs (score:INFINITY) mysql_VIP with mysql_service (score:INFINITY) Ticket Constraints:
[centos7ha1.a5.jp]$ sudo pcs -f clust_cfg resource show Master/Slave Set: MySQLClone [mysql_data] Stopped: [ centos7ha1.a5.jp centos7ha2.a5.jp ] mysql_fs (ocf::heartbeat:Filesystem): Stopped mysql_service (ocf::heartbeat:mysql): Stopped mysql_VIP (ocf::heartbeat:IPaddr2): Stopped
ここまで、cluster_cfg というfileに設定を入れていたが、 cib に push することで /var/lib/pacemaker/cib/cib.xml に保存
[centos7ha1.a5.jp]$ sudo pcs cluster cib-push clust_cfg
[ALL HOST]$ sudo pcs status Cluster name: mycluster Stack: corosync Current DC: centos7ha1.a5.jp (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum Last updated: Sat Sep 14 21:07:24 2019 Last change: Sat Sep 14 21:05:47 2019 by root via cibadmin on centos7ha1.a5.jp 2 nodes configured 5 resources configured Online: [ centos7ha1.a5.jp centos7ha2.a5.jp ] Full list of resources: Master/Slave Set: MySQLClone [mysql_data] Masters: [ centos7ha1.a5.jp ] Slaves: [ centos7ha2.a5.jp ] mysql_fs (ocf::heartbeat:Filesystem): Started centos7ha1.a5.jp mysql_service (ocf::heartbeat:mysql): Started centos7ha1.a5.jp mysql_VIP (ocf::heartbeat:IPaddr2): Started centos7ha1.a5.jp Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled
起動確認
[ALL HOST]$ sudo reboot [centos7ha1.a5.jp]$ sudo pcs cluster start --all centos7ha1.a5.jp: Starting Cluster (corosync)... centos7ha2.a5.jp: Starting Cluster (corosync)... centos7ha1.a5.jp: Starting Cluster (pacemaker)... centos7ha2.a5.jp: Starting Cluster (pacemaker)... ## しばらくして、以下で確認 [ALL HOST]$ sudo pcs status Cluster name: mycluster Stack: corosync Current DC: centos7ha1.a5.jp (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum Last updated: Sat Sep 14 21:16:45 2019 Last change: Sat Sep 14 21:05:47 2019 by root via cibadmin on centos7ha1.a5.jp 2 nodes configured 5 resources configured Online: [ centos7ha1.a5.jp centos7ha2.a5.jp ] Full list of resources: Master/Slave Set: MySQLClone [mysql_data] Masters: [ centos7ha1.a5.jp ] Slaves: [ centos7ha2.a5.jp ] mysql_fs (ocf::heartbeat:Filesystem): Started centos7ha1.a5.jp mysql_service (ocf::heartbeat:mysql): Started centos7ha1.a5.jp mysql_VIP (ocf::heartbeat:IPaddr2): Started centos7ha1.a5.jp Daemon Status: corosync: active/disabled pacemaker: active/disabled pcsd: active/enabled
mysqlの createdb や create table
[centos7ha1.a5.jp]$ mysql -u root Welcome to the MariaDB monitor. Commands end with ; or \g. Server version: 5.5.60-MariaDB MariaDB Server [MariaDB]> CREATE DATABASE hatest CHARACTER SET utf8; [MariaDB]> GRANT ALL PRIVILEGES ON hatest.* to 'hauser'@'localhost' IDENTIFIED BY 'hauser'; [MariaDB]> GRANT ALL PRIVILEGES ON hatest.* to 'hauser'@'%' IDENTIFIED BY 'hauser'; [MariaDB]> use hatest; [MariaDB]> CREATE TABLE test_tbl ( id int primary key AUTO_INCREMENT, user_name varchar(10) comment 'USER NAME') COMMENT='This is test table !!'; [MariaDB]> insert into test_tbl(user_name) values('tanaka'),('suzuki'); [MariaDB]> select * from test_tbl; +----+-----------+ | id | user_name | +----+-----------+ | 1 | tanaka | | 2 | suzuki | +----+-----------+
上記のcreate databaseやcreate tableを実行し、centos7ha1.a5.jp を停止。 ativeになった centos7ha2.a5.jp でレコードを追加し、 再度、centos7ha1.a5.jp をactiveに戻したところ問題なく centos7ha2.a5.jpで追加されたレコードも確認できました。
TODO
- ざっと触ってみた程度ですので、きちんと?テストしないと怖いです
- pcs(pacemaker)が持つコマンドを殆ど知らない為、調査(勉強?)が必要です
- サーバ起動後「sudo pcs cluster start --all」を手動実行していますが、これをなくしたいです。
- pcsでVIPを設定しましたが、以下のようなエラーの原因や対処方法、影響有無が未完了です。
$ sudo pcs status Cluster name: mycluster Stack: corosync Current DC: centos7ha2.a5.jp (version 1.1.19-8.el7_6.4-c3c624ea3d) - partition with quorum : Online: [ centos7ha1.a5.jp centos7ha2.a5.jp ] : Full list of resources: Master/Slave Set: MySQLClone [mysql_data] Masters: [ centos7ha2.a5.jp ] Slaves: [ centos7ha1.a5.jp ] mysql_fs (ocf::heartbeat:Filesystem): Started centos7ha2.a5.jp mysql_service (ocf::heartbeat:mysql): Started centos7ha2.a5.jp mysql_VIP (ocf::heartbeat:IPaddr2): Stopped ←ココ!!!!! ↓ココ!! Failed Actions: * mysql_VIP_start_0 on centos7ha1.a5.jp 'unknown error' (1): call=30, status=complete, exitreason='[findif] failed', last-rc-change='Sun Sep 15 09:58:26 2019', queued=1ms, exec=144ms * mysql_VIP_start_0 on centos7ha2.a5.jp 'unknown error' (1): call=90, status=complete, exitreason='[findif] failed', last-rc-change='Sun Sep 15 12:46:55 2019', queued=0ms, exec=52ms :
pcsで使用するコマンド例
$ sudo pcs status ## クラスタの状態確認 $ sudo pcs cluster start --all ## すべてのnodeを起動 $ sudo pcs cluster start centos7ha2.a5.jp ## 特定ノードを起動 $ sudo pcs cluster stop centos7ha2.a5.jp ## 特定ノードを停止 $ sudo pcs resource move mysql_VIP centos7ha2.a5.jp ## 手動でfail over $ sudo pcs resource restart mysql_VIP ## pacemaker管理下のapacheの再起動 $ sudo pcs config ## pacemakerの設定の確認 $ sudo pcs resource list ## 使用可能なリソースの確認 $ sodo pcs resource standards ## クラスの確認 $ sudo pcs resource delete VIP # リソースの削除 ## (クラスタがstartした状態で実行) $ sudo corosync-cfgtool -s ## ノードの状態の確認 # 同じリソースの障害が何回発生するとフェイルオーバーするかを指定 $ sudo pcs resource defaults migration-threshold=1