Contents
yum
でインストールします。同期に使う
XtraBackup
は公式ページからRPMをダウンロードします。
公式
http://galeracluster.com/products/
方針
- MariaDBとGalera Clusterをインストールする
- 3ノード構築する
- 同期方法は
xtrabackup
を使う - 一先ず、同期が取れたところまで確認する
環境
項目 | バージョン |
---|---|
OS | CentOS 7.2 |
MariaDB | 10.0.27-1 |
galera | 25.3.17(r3619) |
構築手順
パッケージインストール
必要なパッケージをインストールします。
本手順は、対象のサーバ全てで実施します。
(1) MariaDBのリポジトリを登録します。
1 2 3 4 5 6 7 8 9 |
[root@sql1 ~]# vi /etc/yum.repos.d/MariaDB.repo # MariaDB 10.0 CentOS repository list - created 2016-10-10 09:09 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.0/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 |
リポジトリは、以下から作成できます。
https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university&distro=CentOS&distro_release=centos7-amd64–centos7&version=10.0
(2) 必要なパッケージをインストールします。
1 2 |
[root@sql1 ~]# yum -y install MariaDB-Galera-server MariaDB-client galera socat libev perl-DBD-mysql nc |
XtraBackupインストール
本手順は、対象のサーバ全てで実施します。
(1) XtraBackupをダウンロードします。
1 2 |
[root@sql1 ~]# curl -L https://www.percona.com/downloads/XtraBackup/Percona-XtraBackup-2.4.4/binary/redhat/7/x86_64/percona-xtrabackup-24-2.4.4-1.el7.x86_64.rpm -O |
(2) インストールします。
1 2 |
[root@sql1 ~]# rpm -ivh percona-xtrabackup-24-2.4.4-1.el7.x86_64.rpm |
設定
SQL1の設定
(1) SQL1(ドナー)の設定をします。
設定内容は公式ドキュメントを、ほぼそのまま流用しています。
細かな設定は環境に合わせてください。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
[root@sql1 ~]# vi /etc/my.cnf.d/server.cnf (snip) [mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql binlog_format=ROW bind-address=0.0.0.0 default_storage_engine=innodb innodb_autoinc_lock_mode=2 innodb_flush_log_at_trx_commit=0 innodb_buffer_pool_size=122M wsrep_provider_options="gcache.size=300M; gcache.page_size=300M" wsrep_cluster_name="MariaDB" wsrep_cluster_address="gcomm://172.31.1.2" wsrep_node_address=172.31.1.1 wsrep_sst_auth = <user>:<password> wsrep_sst_method = xtrabackup wsrep_provider='/usr/lib64/galera/libgalera_smm.so' log-error=/var/log/mysqld.log (snip) |
注意
wsrep_sst_auth
の内容は変更してください。
SQL2の設定
(1) SQL2(ジョイナー)の設定をします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
[mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql binlog_format=ROW bind-address=0.0.0.0 default_storage_engine=innodb innodb_autoinc_lock_mode=2 innodb_flush_log_at_trx_commit=0 innodb_buffer_pool_size=122M wsrep_provider_options="gcache.size=300M; gcache.page_size=300M" wsrep_cluster_name="MariaDB" wsrep_cluster_address="gcomm://172.31.1.1" wsrep_node_address=172.31.1.2 wsrep_sst_auth = <user>:<password> wsrep_sst_method = xtrabackup datadir = /var/lib/mysql wsrep_provider='/usr/lib64/galera/libgalera_smm.so' log-error=/var/log/mysqld.log |
注意
wsrep_sst_auth
の内容は変更してください。
SQL3の設定
(1) SQL3(ジョイナー)の設定をします。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
mysqld] datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql binlog_format=ROW bind-address=0.0.0.0 default_storage_engine=innodb innodb_autoinc_lock_mode=2 innodb_flush_log_at_trx_commit=0 innodb_buffer_pool_size=122M wsrep_provider_options="gcache.size=300M; gcache.page_size=300M" wsrep_cluster_name="MariaDB" wsrep_cluster_address="gcomm://172.31.1.1" wsrep_node_address=172.31.1.3 wsrep_sst_auth = <user>:<password> wsrep_sst_method = xtrabackup datadir = /var/lib/mysql wsrep_provider='/usr/lib64/galera/libgalera_smm.so' log-error=/var/log/mysqld.log |
注意
wsrep_sst_auth
の内容は変更してください。
起動
SQL1の起動
(1) SQL1(ドナー)の起動をします。
1 2 3 |
[root@sql1 ~]# service mysql start --wsrep_cluster_address=gcomm:// Starting MySQL.. SUCCESS! |
(2) セキュリティのスクリプトを実行します。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
[root@sql1 ~]# mysql_secure_installation NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY! In order to log into MariaDB to secure it, we'll need the current password for the root user. If you've just installed MariaDB, and you haven't set the root password yet, the password will be blank, so you should just press enter here. Enter current password for root (enter for none): OK, successfully used password, moving on... Setting the root password ensures that nobody can log into the MariaDB root user without the proper authorisation. Set root password? [Y/n] New password: Re-enter new password: Password updated successfully! Reloading privilege tables.. ... Success! By default, a MariaDB installation has an anonymous user, allowing anyone to log into MariaDB without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? [Y/n] ... Success! Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? [Y/n] ... Success! By default, MariaDB comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? [Y/n] - Dropping test database... ... Success! - Removing privileges on test database... ... Success! Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? [Y/n] ... Success! Cleaning up... All done! If you've completed all of the above steps, your MariaDB installation should now be secure. Thanks for using MariaDB! |
SQL2,3の起動
(1) SQL2(ジョイナー)を起動します。
1 2 3 |
[root@sql2 mysql]# service mysql start Starting MySQL...SST in progress, setting sleep higher. SUCCESS! |
(2) SQL3(ジョイナー)を起動します。
1 2 3 |
[root@sql3 ~]# service mysql start Starting MySQL...SST in progress, setting sleep higher. SUCCESS! |
ステータス確認
(1) Galera Clusterの全体ステータスを確認してみます。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
[root@sql1 ~]# mysql -u root -p -e "show status like 'wsrep_%';" Enter password: +------------------------------+-------------------------------------------------+ | Variable_name | Value | +------------------------------+-------------------------------------------------+ | wsrep_local_state_uuid | 1d3c9c31-8ecb-11e6-8199-2b41ed216b7c | | wsrep_protocol_version | 7 | | wsrep_last_committed | 3 | | wsrep_replicated | 0 | | wsrep_replicated_bytes | 0 | | wsrep_repl_keys | 0 | | wsrep_repl_keys_bytes | 0 | | wsrep_repl_data_bytes | 0 | | wsrep_repl_other_bytes | 0 | | wsrep_received | 10 | | wsrep_received_bytes | 740 | | wsrep_local_commits | 0 | | wsrep_local_cert_failures | 0 | | wsrep_local_replays | 0 | | wsrep_local_send_queue | 0 | | wsrep_local_send_queue_max | 1 | | wsrep_local_send_queue_min | 0 | | wsrep_local_send_queue_avg | 0.000000 | | wsrep_local_recv_queue | 0 | | wsrep_local_recv_queue_max | 2 | | wsrep_local_recv_queue_min | 0 | | wsrep_local_recv_queue_avg | 0.100000 | | wsrep_local_cached_downto | 18446744073709551615 | | wsrep_flow_control_paused_ns | 0 | | wsrep_flow_control_paused | 0.000000 | | wsrep_flow_control_sent | 0 | | wsrep_flow_control_recv | 0 | | wsrep_cert_deps_distance | 0.000000 | | wsrep_apply_oooe | 0.000000 | | wsrep_apply_oool | 0.000000 | | wsrep_apply_window | 0.000000 | | wsrep_commit_oooe | 0.000000 | | wsrep_commit_oool | 0.000000 | | wsrep_commit_window | 0.000000 | | wsrep_local_state | 4 | | wsrep_local_state_comment | Synced | | wsrep_cert_index_size | 0 | | wsrep_causal_reads | 0 | | wsrep_cert_interval | 0.000000 | | wsrep_incoming_addresses | 172.31.1.3:3306,172.31.1.1:3306,172.31.1.2:3306 | | wsrep_desync_count | 0 | | wsrep_evs_delayed | | | wsrep_evs_evict_list | | | wsrep_evs_repl_latency | 0/0/0/0/0 | | wsrep_evs_state | OPERATIONAL | | wsrep_gcomm_uuid | d951d75c-8ecb-11e6-bd88-024f1fd8ede6 | | wsrep_cluster_conf_id | 3 | | wsrep_cluster_size | 3 | | wsrep_cluster_state_uuid | 1d3c9c31-8ecb-11e6-8199-2b41ed216b7c | | wsrep_cluster_status | Primary | | wsrep_connected | ON | | wsrep_local_bf_aborts | 0 | | wsrep_local_index | 1 | | wsrep_provider_name | Galera | | wsrep_provider_vendor | Codership Oy <info@codership.com> | | wsrep_provider_version | 25.3.17(r3619) | | wsrep_ready | ON | | wsrep_thread_count | 2 | +------------------------------+-------------------------------------------------+ |
(2) 一部を抜粋してみてみます。
1 2 3 4 5 6 7 8 9 10 |
[root@sql1 ~]# mysql -u root -p -e "show status where Variable_name = 'wsrep_local_state_comment' or Variable_name = 'wsrep_incoming_addresses' or Variable_name = 'wsrep_cluster_size';" Enter password: +---------------------------+-------------------------------------------------+ | Variable_name | Value | +---------------------------+-------------------------------------------------+ | wsrep_local_state_comment | Synced | | wsrep_incoming_addresses | 172.31.1.3:3306,172.31.1.1:3306,172.31.1.2:3306 | | wsrep_cluster_size | 3 | +---------------------------+-------------------------------------------------+ |
問題なく動作してるようです。
動作試験としては、どこかのノードでDBやテーブルを追加して同期されているか確認する感じでしょうか 🙂