LoginSignup
5
3

More than 3 years have passed since last update.

pacemakerでgalera Cluster(その1)

Last updated at Posted at 2016-04-18

Pacemakerにもgaleraのresource-agentがあるので、試してみます。
先に、galeraのみでのクラスタを確認して、その後、Pacemaker配下で起動してみます。

環境

3ノード:CentOS7.2 - Ubuntu14.04のKVM上のゲスト

galeraインストール後、galeraの自動起動が有効になっています。
テスト的なクラスタの確認後は、Pacemakerでgaleraは起動・停止する為、各ノードで自動起動は無効にしておきます。

[root@ct72-xx ~]# systemctl disable mariadb.service 
Removed symlink /etc/systemd/system/multi-user.target.wants/mariadb.service.
Removed symlink /etc/systemd/system/mysql.service.
Removed symlink /etc/systemd/system/mysqld.service.

[root@ct72-xx ~]# systemctl disable mysql

galeraには詳しくないので、設定ファイルは色々とネットの情報を参考にして、以下としました。

ct72-1@/etc/my.cnf.d/server.cnf
[mysqld]
bind-address=0.0.0.0

#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='ct72-01'
wsrep_node_address = 192.168.10.10

ct72-2@/etc/my.cnf.d/server.cnf
[mysqld]
bind-address=0.0.0.0

#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://192.168.10.10'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='ct72-02'
wsrep_node_address = 192.168.10.20

ct72-3@/etc/my.cnf.d/server.cnf
[mysqld]
bind-address=0.0.0.0

#
# * Galera-related settings
#
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
#wsrep_cluster_address=
binlog_format=row
wsrep_cluster_address='gcomm://192.168.10.10'
wsrep_cluster_name='DBCLUSTER'
wsrep_node_name='ct72-03'
wsrep_node_address = 192.168.10.30

テストクラスタの起動

まずは、galeraだけでクラスタを起動してみます。

  • Master、Slaveの順で起動
[root@ct72-01 ~]# service mysql start --wsrep-new-cluster
[root@ct72-02 ~]# service mysql start
[root@ct72-03 ~]# service mysql start
  • 起動の確認
[root@ct72-01 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| wsrep_local_index | 1     |
+-------------------+-------+
[root@ct72-02 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| wsrep_local_index | 1     |
+-------------------+-------+
[root@ct72-03 ~]# mysql -u root -e "show status like 'wsrep_local_index';"
+-------------------+-------+
| Variable_name     | Value |
+-------------------+-------+
| wsrep_local_index | 1     |
+-------------------+-------+

テストクラスタの確認

  • Masterノードでdb/Table/dataの作成
[root@ct72-01 ~]# mysql -u root
MariaDB [(none)]> create database testdb3;
MariaDB [(none)]> use testdb3;
Database changed
MariaDB [testdb3]> create table tb2 ( name text, phone text, addr text );
Query OK, 0 rows affected (0.40 sec)
MariaDB [testdb3]> insert into tb2 ( name, phone, addr ) values ( 'yoshida', '012-345-6789', 'Tokyo/Japan' );
Query OK, 1 row affected (0.09 sec)

MariaDB [testdb3]> select * from tb2;
+---------+--------------+-------------+
| name    | phone        | addr        |
+---------+--------------+-------------+
| yoshida | 012-345-6789 | Tokyo/Japan |
+---------+--------------+-------------+
1 row in set (0.00 sec)
  • Slaveノード1で同期の確認
[root@ct72-02 ~]# mysql -u root
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.00 sec)
  • Slaveノード2で同期の確認
[root@ct72-03 ~]# mysql -u root
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.00 sec)

テストクラスタの停止

全てのノードでservice mysql stopを実行します

Pacemakerでのクラスタ

CLIファイルの準備

とりあえず、先の確認したgaleraの設定ファイルはそのままにしておきます。
まずは単純にgaleraだけのクラスタ用のCLIファイルを準備してみます。
一応、galeraのresource-agent内のpcsでの記述例にある3マスター構成にしてあります。
(色々、現時点のgaleraには制約があるので、3マスター構成でそのまま動作させるわけには行かないようですが・・) https://mariadb.com/kb/en/mariadb/mariadb-galera-cluster-known-limitations/

primitive db galera \
        params enable_creation=true wsrep_cluster_address="gcomm://ct72-01,ct72-02,ct72-03" \
        op start interval=0s timeout=120 \
        op stop interval=0s timeout=120 \
        op monitor interval=20 timeout=30 \
        op monitor interval=10 role=Master timeout=30 \
        op monitor interval=30 role=Slave timeout=30 \
        op promote interval=0s timeout=300 \
        op demote interval=0s timeout=120
ms db-master db \
        meta master-max=3
property cib-bootstrap-options: \
        startup-fencing=false \
        stonith-enabled=false

Pacemakerの起動

systemctlでPacemakerを3ノード全てで起動します。

CLIファイルの投入

Pacemakerの起動が安定した所で、先のCLIファイルをcrmシェルで投入します。

[root@ct72-01 ~]# crm configure load update CLIファイル

起動の確認

若干、マシン性能によっては、起動に時間がかかるようですが、暫くすると全ノードがマスターで起動します。

[root@ct72-01 ~]# crm_mon -1 -Af
Stack: corosync
Current DC: ct72-01 (version 1.1.14-90b675e) - partition with quorum
Last updated: Mon Apr 18 19:03:47 2016      
Last change: Mon Apr 18 18:55:44 2016 by root via cibadmin on ct72-01

3 nodes and 3 resources configured

Online: [ ct72-01 ct72-02 ct72-03 ]

 Master/Slave Set: db-master [db]
     Masters: [ ct72-01 ct72-02 ct72-03 ]

Node Attributes:
* Node ct72-01:
    + master-db                         : 100       
* Node ct72-02:
    + master-db                         : 100       
* Node ct72-03:
    + master-db                         : 100       

Migration Summary:
* Node ct72-01:
* Node ct72-03:
* Node ct72-02:

とりあえず、起動出来たようなので、続いて、3ノードの1ノードのみにVIPリソースを起動して、処理を受け付けるように変更していきます。

以上です。

5
3
4

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
5
3