以前の古い投稿にコメントを頂いたので、RHEL8.2の環境で再確認してみました。
Pacemakerにもgaleraのresource-agentがあるので、試してみます。
先に、galeraのみでのクラスタを確認して、その後、Pacemaker配下で起動してみます。
環境
3ノード:RHEL8.2 - Hyper-Vのゲスト
- rh82-dev01 : 192.168.3.67 (Master1)
- rh82-dev02 : 192.168.3.68 (Master2)
- rh82-dev03 : 192.168.3.76 (Master3)
- MariDB : 10.5 は以下によってリポジトリインストールしました。
- Pacemaker-2.0.5
- pcs-0,10.4
- resource-agents-4.6.1
- corosync-3.1.0.6
Pacemakerのインストール後は、pcsコマンドで3ノードでクラスタが起動できるように準備をしておいてください。
galeraインストール後、galeraの自動起動が有効になっています。
テスト的なクラスタの確認後は、Pacemakerでgaleraは起動・停止する為、各ノードで自動起動は無効にしておきます。
[root@rh82-dev01 ~]# systemctl disable mariadb.service
Removed /etc/systemd/system/multi-user.target.wants/mariadb.service.
galeraには詳しくないので、設定ファイルは色々とネットの情報を参考にして、以下としました。
[mysqld]
bind-address=0.0.0.0
(snip)
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='rh82-dev01'
wsrep_node_address = 192.168.3.67
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
[mysqld]
bind-address=0.0.0.0
(snip)
#
# * Galera-related settings
#
[galera]
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://192.168.3.67'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='rh82-dev02'
wsrep_node_address = 192.168.3.68
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
[mysqld]
bind-address=0.0.0.0
(snip)
#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera-4/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://192.168.3.67'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='rh82-dev03'
wsrep_node_address = 192.168.3.76
#default_storage_engine=InnoDB
#innodb_autoinc_lock_mode=2
テストクラスタの起動
まずは、galeraだけでクラスタを起動してみます。
- Master、Slaveの順で起動
[root@rh82-dev01 ~]# galera_new_cluster
[root@rh82-dev02 ~]# systemctl start mysql
[root@rh82-dev03 ~]# systemctl start mysql
- 起動の確認
[root@rh82-dev01 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| wsrep_local_index | 2 |
+-------------------+-------+
[root@rh82-dev02 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| wsrep_local_index | 0 |
+-------------------+-------+
[root@rh82-dev03 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name | Value |
+-------------------+-------+
| wsrep_local_index | 1 |
+-------------------+-------+
テストクラスタの確認
- Masterノードでdb/Table/dataの作成
[root@rh82-dev01 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database testdb3;
Query OK, 1 row affected (0.640 sec)
MariaDB [(none)]> use testdb3;
Database changed
MariaDB [testdb3]> create table tb2 ( name text, phone text, addr text );
Query OK, 0 rows affected (1.846 sec)
MariaDB [testdb3]> insert into tb2 ( name, phone, addr ) values ( 'yoshida', '012-345-6789', 'Tokyo/Japan' );
Query OK, 1 row affected (0.031 sec)
MariaDB [testdb3]> select * from tb2;
+---------+--------------+-------------+
| name | phone | addr |
+---------+--------------+-------------+
| yoshida | 012-345-6789 | Tokyo/Japan |
+---------+--------------+-------------+
1 row in set (0.000 sec)
- Slaveノード1で同期の確認
[root@rh82-dev02 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use testdb3;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [testdb3]> select * from tb2;
+---------+--------------+-------------+
| name | phone | addr |
+---------+--------------+-------------+
| yoshida | 012-345-6789 | Tokyo/Japan |
+---------+--------------+-------------+
1 row in set (0.000 sec)
- Slaveノード2で同期の確認
[root@rh82-dev03 ~]# mysql -u root
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.5.9-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> use testdb3;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MariaDB [testdb3]> select * from tb2;
+---------+--------------+-------------+
| name | phone | addr |
+---------+--------------+-------------+
| yoshida | 012-345-6789 | Tokyo/Japan |
+---------+--------------+-------------+
1 row in set (0.000 sec)
テストクラスタの停止
全てのノードでservice mysql stopを実行します
Pacemakerでのクラスタ
pcsの流し込み用のファイルの準備
とりあえず、先の確認したgaleraの設定ファイルはそのままにしておきます。
まずは単純にgaleraだけのクラスタ用のpcsの流し込みのファイルを準備してみます。
一応、galeraのresource-agent内のpcsでの記述例にある3マスター構成にしてあります。
(色々、現時点のgaleraには制約があるので、3マスター構成でそのまま動作させるわけには行かないようですが・・) https://mariadb.com/kb/en/mariadb/mariadb-galera-cluster-known-limitations/
(最新では、未確認ですが・・もう出来るのかも。。。)
#!/bin/sh
pcs resource create galera ocf:heartbeat:galera \
enable_creation=true wsrep_cluster_address="gcomm://rh82-dev01,rh82-dev02,rh82-dev03" \
op start interval=0s timeout=300s on-fail=restart \
op monitor interval=10s timeout=60s on-fail=restart \
op monitor role=Master interval=9s timeout=60s on-fail=restart \
op promote interval=0s timeout=300s on-fail=restart \
op demote interval=0s timeout=300s on-fail=block \
op stop interval=0s timeout=300s on-fail=block \
promotable promoted-max=3
pcs resource defaults migration-threshold=1
pcs resource defaults resource-stickiness=INFINITY
pcs property set stonith-enabled=false
Pacemakerの起動
pcsでPacemakerを3ノード全てで起動します。
※事前にRHEL8のドキュメントなどを参照にpcsで3ノードのクラスタは設定しておいてください。
[root@rh82-dev01 ~]# pcs cluster start --all
pcs設定ファイルの投入
Pacemakerの起動が安定した所で、/root/galera.shを実行します。
[root@rh82-dev01 ~]# ./galera.sh
Warning: Defaults do not apply to resources which override them with their own defined values
Warning: Defaults do not apply to resources which override them with their own defined values
起動の確認
若干、マシン性能によっては、起動に時間がかかるようですが、暫くすると全ノードがマスターで起動します。
[root@rh82-dev01 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev03 (version 2.0.5-bb4dbfc13) - partition with quorum
* Last updated: Sat Feb 27 15:06:57 2021
* Last change: Sat Feb 27 15:03:12 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 3 resource instances configured
Node List:
* Online: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Full List of Resources:
* Clone Set: galera-clone [galera] (promotable):
* Masters: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Node Attributes:
* Node: rh82-dev01:
* master-galera : 100
* Node: rh82-dev02:
* master-galera : 100
* Node: rh82-dev03:
* master-galera : 100
Migration Summary:
とりあえず、起動出来たようなので、続いて、3ノードの1ノードのみにVIPリソースを起動して、処理を受け付けるように変更していきます。
一旦、クラスタを停止します。
[root@rh82-dev01 ~]# pcs cluster stop --all
rh82-dev01: Stopping Cluster (pacemaker)...
rh82-dev02: Stopping Cluster (pacemaker)...
rh82-dev03: Stopping Cluster (pacemaker)...
rh82-dev01: Stopping Cluster (corosync)...
rh82-dev02: Stopping Cluster (corosync)...
rh82-dev03: Stopping Cluster (corosync)...
設定ファイルへのVIPの付与
galeraの場合は、どこのMasterに更新を掛けても動作可能のようですが、先に書いている制限がまだ有効かと思われますので、外部もしくはWEB/APサーバからgaleraのDBサーバクラスタに更新アクセスする為の1台のマスターに付与するVIPをクラスタ設定に追加します。
どこのMasterについても良いようにし、galeraがMasterに昇格してからVIPが開始するように設定します。
VIPは192.168.3.88とします。
以下のように設定ファイルを変更します。
#!/bin/sh
pcs resource create ipaddr-primary ocf:heartbeat:IPaddr2 \
ip="192.168.3.88" nic="eth0" cidr_netmask="24" \
op start timeout=60s on-fail=restart \
monitor timeout=60s interval=10s on-fail=restart \
stop timeout=60s on-fail=fence
pcs resource group add primary-group ipaddr-primary
pcs resource create galera ocf:heartbeat:galera \
enable_creation=true wsrep_cluster_address="gcomm://rh82-dev01,rh82-dev02,rh82-dev03" \
op start interval=0s timeout=300s on-fail=restart \
op monitor interval=10s timeout=60s on-fail=restart \
op monitor role=Master interval=9s timeout=60s on-fail=restart \
op promote interval=0s timeout=300s on-fail=restart \
op demote interval=0s timeout=300s on-fail=block \
op stop interval=0s timeout=300s on-fail=block \
promotable promoted-max=3
#promotable promoted-max=1 promoted-node-max=1 clone-max=2 clone-node-max=1 notify=true
pcs constraint colocation add primary-group with master galera-clone score=INFINITY
pcs constraint order promote galera-clone then start primary-group symmetrical=false
pcs constraint order demote galera-clone then stop primary-group kind=Optional symmetrical=false
pcs resource defaults migration-threshold=1
pcs resource defaults resource-stickiness=INFINITY
pcs property set stonith-enabled=false
~
VIP付構成の確認
VIPを付与して設定ファイルを再度クラスタを起動した後で流し込みます。
前の設定を一旦破棄する為に、/var/lib/pacemakerの下はファイルをクリーンアップしておいてください。
起動の確認-VIP付与
VIP(192.168.3.88)がrh82-dev01のMasterノードに付与されます。
[root@rh82-dev01 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev03 (version 2.0.5-bb4dbfc13) - partition with quorum
* Last updated: Thu Mar 4 12:10:26 2021
* Last change: Thu Mar 4 11:55:03 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 4 resource instances configured
Node List:
* Online: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Full List of Resources:
* Resource Group: primary-group:
* ipaddr-primary (ocf:heartbeat:IPaddr2): Started rh82-dev01
* Clone Set: galera-clone [galera] (promotable):
* Masters: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Node Attributes:
* Node: rh82-dev01:
* master-galera : 100
* Node: rh82-dev02:
* master-galera : 100
* Node: rh82-dev03:
* master-galera : 100
Migration Summary:
[root@rh82-dev01 ~]# ip a | grep 192
inet 192.168.3.67/24 brd 192.168.3.255 scope global dynamic noprefixroute eth0
inet 192.168.3.88/24 brd 192.168.3.255 scope global secondary eth0
inet 192.168.10.63/24 brd 192.168.10.255 scope global noprefixroute eth1
inet 192.168.20.63/24 brd 192.168.20.255 scope global noprefixroute eth2
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
1台目のrh82-dev01を停止すると、VIP(192.168.3.88)がrh82-dev01のMasterノードに付与されます。
[root@rh82-dev01 ~]# pcs cluster stop
Stopping Cluster (pacemaker)...
Stopping Cluster (corosync)...
[root@rh82-dev02 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev03 (version 2.0.5-bb4dbfc13) - partition with quorum
* Last updated: Thu Mar 4 12:12:53 2021
* Last change: Thu Mar 4 11:55:03 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 4 resource instances configured
Node List:
* Online: [ rh82-dev02 rh82-dev03 ]
* OFFLINE: [ rh82-dev01 ]
Full List of Resources:
* Resource Group: primary-group:
* ipaddr-primary (ocf:heartbeat:IPaddr2): Started rh82-dev02
* Clone Set: galera-clone [galera] (promotable):
* Masters: [ rh82-dev02 rh82-dev03 ]
* Stopped: [ rh82-dev01 ]
Node Attributes:
* Node: rh82-dev02:
* master-galera : 100
* Node: rh82-dev03:
* master-galera : 100
Migration Summary:
[root@rh82-dev02 ~]# ip a | grep 192
inet 192.168.3.68/24 brd 192.168.3.255 scope global dynamic noprefixroute eth0
inet 192.168.3.88/24 brd 192.168.3.255 scope global secondary eth0
inet 192.168.10.64/24 brd 192.168.10.255 scope global noprefixroute eth1
inet 192.168.20.64/24 brd 192.168.20.255 scope global noprefixroute eth2
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
さらに2台目のrh82-dev02を停止すると、VIP(192.168.3.88)は停止し、galeraのMasterもいなくなります。
これは、3台構成のクラスタが1台に縮退してQUORUMを保持しなくなった為です。
[root@rh82-dev02 ~]# pcs cluster stop --force
Stopping Cluster (pacemaker)...
Stopping Cluster (corosync)...
[root@rh82-dev03 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev03 (version 2.0.5-bb4dbfc13) - partition WITHOUT quorum
* Last updated: Thu Mar 4 12:14:16 2021
* Last change: Thu Mar 4 11:55:03 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 4 resource instances configured
Node List:
* Online: [ rh82-dev03 ]
* OFFLINE: [ rh82-dev01 rh82-dev02 ]
Full List of Resources:
* Resource Group: primary-group:
* ipaddr-primary (ocf:heartbeat:IPaddr2): Stopped
* Clone Set: galera-clone [galera] (promotable):
* Stopped: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Migration Summary:
Masterノードを1ノードに変更する
galeraの性質上、Masterは3ノードあっても問題ないようですが、クラスタ内にMasterを1ノードのみとするように設定ファイルを変更(promoted-maxを1に変更)してみます。
※以下、3ノード共galeraは起動しているように見えますが、1ノードでmysqlの起動に失敗しているようです。
※問題が設定なのか、まだ確認していません。現状は、1ノードをMasterにせず、すべてMasterで起動してVIPをどれかに割り当てる先に書いた設定の方が良いと思います。
pcs resource create galera ocf:heartbeat:galera \enable_creation=true wsrep_cluster_address="gcomm://rh82-dev01,rh82-dev02,rh82-dev03" \op start interval=0s timeout=300s on-fail=restart \op monitor interval=10s timeout=60s on-fail=restart \op monitor role=Master interval=9s timeout=60s on-fail=restart \
op promote interval=0s timeout=300s on-fail=restart \
op demote interval=0s timeout=300s on-fail=block \
op stop interval=0s timeout=300s on-fail=block \
promotable promoted-max=1
起動後、MasterとなったノードにVIPが付与されます。
[root@rh82-dev01 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev02 (version 2.0.5-bb4dbfc13) - partition with quorum
* Last updated: Sat Mar 6 10:22:10 2021
* Last change: Sat Mar 6 10:19:44 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 4 resource instances configured
Node List:
* Online: [ rh82-dev01 rh82-dev02 rh82-dev03 ]
Full List of Resources:
* Resource Group: primary-group:
* ipaddr-primary (ocf:heartbeat:IPaddr2): Started rh82-dev03
* Clone Set: galera-clone [galera] (promotable):
* Masters: [ rh82-dev03 ]
* Slaves: [ rh82-dev01 rh82-dev02 ]
Node Attributes:
* Node: rh82-dev01:
* galera-last-committed : 112
* galera-safe-to-bootstrap : 0
* master-galera : 100
* Node: rh82-dev02:
* galera-last-committed : 113
* galera-safe-to-bootstrap : 0
* master-galera : 100
* Node: rh82-dev03:
* master-galera : 100
Migration Summary:
Masterノードを停止すると残りの2ノードの1つがMasterノードになって、VIPが上がります。
[root@rh82-dev02 ~]# crm_mon -rfA1
Cluster Summary:
* Stack: corosync
* Current DC: rh82-dev02 (version 2.0.5-bb4dbfc13) - partition with quorum
* Last updated: Sat Mar 6 10:23:21 2021
* Last change: Sat Mar 6 10:19:44 2021 by root via cibadmin on rh82-dev01
* 3 nodes configured
* 4 resource instances configured
Node List:
* Online: [ rh82-dev02 rh82-dev03 ]
* OFFLINE: [ rh82-dev01 ]
Full List of Resources:
* Resource Group: primary-group:
* ipaddr-primary (ocf:heartbeat:IPaddr2): Started rh82-dev03
* Clone Set: galera-clone [galera] (promotable):
* Masters: [ rh82-dev03 ]
* Slaves: [ rh82-dev02 ]
* Stopped: [ rh82-dev01 ]
Node Attributes:
* Node: rh82-dev02:
* galera-last-committed : 113
* galera-safe-to-bootstrap : 0
* master-galera : 100
* Node: rh82-dev03:
* master-galera : 100
Migration Summary:
注意
動作確認をgalera_new_clusterで実行した場合、再度、galera_new_clusterで起動できない場合がありますが、これは最後に停止したサーバで再度Msaterを起動しない為です。
この場合は、実行するサーバで、/var/lib/mysql/grastate.datのsafe_to_bootstrapを1に変更して実行してください。
# GALERA saved state
version: 2.1
uuid: a5d0e102-78b9-11eb-aaf0-a6ba82a6ab4f
seqno: -1
safe_to_bootstrap: 1 ★ここを0から1に
以上です。