はじめてのMariaDB Galera Clusterのインストール〜セットアップ方法
条件
本手順は、以下の条件を想定した構成となっている。
- 安定版を使用する。
- OS:CentOS6.7,アーキテクチャ:64bit,インストール方法:netinstall(iso), 初期パッケージ:minimal。
- OSはインストールしたばかりのクリーンな状態である。(MySQLや他のバージョンのMariaDBは導入されていない)
- selinux,iptablesなどは無効化されている。
- DHCPである。
- ブリッジ接続である。
- 設定ファイルなどは、実施者が必要に応じてバックアップしている。
- MariaDBのユーザは初期状態である
リポジトリ情報取得
- MariaDBの公式サイト(https://mariadb.org/en/)にアクセスする。
- 画面上部"Downloads"をクリックする。
- "Download 10.0.21 Stable Now!"をクリックする。
- 個々のパッケージではなく、リポジトリを登録するために"Repository Configuration Tool."というリンク(リンク一覧下部)をクリックする。
- 導入対象である、OS/ バージョン(OS)/バージョン(MariaDB)を選択。
- 上記選択後、同ページ下部に表示される枠内をコピーする。
- CentOS上の/etc/yum.repos.d配下へ任意のファイル名でファイルを作成し、"6"でコピーした内容を貼り付け、上書き保存する。
インストール
1. yumのキャッシュをクリーンにする。#キャッシュヒットさせないため
# yum clean all
2. パッケージを最新状態にする。#Bug fixの適用
# yum update
3. Galera Clusterに必要なパッケージをインストールする。#その他、必要なパッケージも併せてインストールされる
# yum install MariaDB-Galera-server
仮想マシンの複製
1. Galera Clusterの最小構成が3台であるため、ゲストOSを複製する。
2. 複製したゲストOSのホスト名も変更する。#作業中のホストがわかりづらくなるため
# vi /etc/sysconfig/network
3. 複製したゲストOSのMACアドレスを変更する。
# vi /etc/udev/rules.d/70-persistent-net.rules
[70-persistent-net.rules]
# This file was automatically generated by the /lib/udev/write_net_rules # program, run by the persistent-net-generator.rules rules file. # # You can modify it, as long as you keep each rule on a single # line, and change only the value of the NAME= key. # PCI device 0x1af4:0x1000 (virtio-pci) #SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:f1:91:b9", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" #↑コメントアウトする。 # PCI device 0x1af4:0x1000 (virtio-pci) SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="52:54:00:31:4f:a5", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1" #eth1をeth0へ変更する。
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
[ifcfg-eth0]
DEVICE="eth0" BOOTPROTO="dhcp" HWADDR="52:54:00:F1:91:B9" #ここを70-persistent-net.rulesの"ATTR{address}"の値と同じにする。 NM_CONTROLLED="yes" ONBOOT="yes" TYPE="Ethernet" UUID="4ef161b3-87b1-431a-b609-85e4f42d1124"
4. 設定を反映する
# reboot
5. mysqlモニタのプロンプトの表示を変更する。
MariaDB [none]> prompt galera1
Galera Clusterの設定
1. 設定ファイルを編集する。#赤字は追記 #全台、同じ内容でOK
# vi /etc/my.cnf.d/server.cnf
[/etc/my.cnf.d/server.cnf]
# # These groups are read by MariaDB server. # Use it for options that only the server (but not clients) should see # # See the examples of server my.cnf files in /usr/share/mysql/ # # this is read by the standalone daemon and embedded servers [server] character-set-server = utf8 #日本語対応させるため、文字コードをutf-8に設定する。 # this is only for the mysqld standalone daemon [mysqld] # # * Galera-related settings # [galera] # Mandatory settings wsrep_provider='/usr/lib64/galera/libgalera_smm.so' #Galera Clusterのライブラリを指定。 wsrep_cluster_address=gcomm://192.168.11.11,192.168.11.12,192.168.11.13 #クラスタに参加するサーバのIP or ホスト名を指定 binlog_format=row default_storage_engine=InnoDB innodb_autoinc_lock_mode=2 bind-address=0.0.0.0 #Mandatory settings from https://mariadb.com/ innodb_doublewrite=1 wsrep_on=ON # Optional setting #wsrep_slave_threads=1 #innodb_flush_log_at_trx_commit=0 # this is only for embedded server [embedded] # This group is only read by MariaDB servers, not by MySQL. # If you use the same .cnf file for MySQL and MariaDB, # you can put MariaDB-only options here [mariadb] # This group is only read by MariaDB-10.0 servers. # If you use the same .cnf file for MariaDB of different versions, # use this group for options that older servers don't understand [mariadb-10.0]
Galera Clusterの起動
1. 任意の1台を起動する。#エラーが発生した場合は、/var/lib/mysql/ホスト名.errを参照
# service mysql start --wsrep-new-cluster
2. その他のクラスタメンバであるサーバを起動する。
# service mysql start
動作確認
1. データベース、テーブルを作成し、他のサーバで反映されていることを確認する
[サーバ1]
# mysql -u root MariaDB [none]> create database test1;
[サーバ2]
MariaDB [none]> show databases; #test1が存在すればOK
以上