MariaDB Galera Cluster 10.1 Setting

先前已經寫過 10.0 的設定方式,MariaDB 升級成 10.1galera 就已經內建在其中了,也不用額外安裝它的套件。

Environment

Debian Jessie

# MariaDB
sudo apt-get install python-software-properties
sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository 'deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.0/debian jessie main'

# Percona XtraBackup
wget https://repo.percona.com/apt/percona-release_0.1-3.jessie_all.deb
sudo dpkg -i percona-release_0.1-3.jessie_all.deb
sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 8507EFA5

Install MariaDB & XtraBackup

這邊額外安裝 XtraBackup 是讓 wsrep_sst_method 參數可以使用 xtrabackup-v2 來同步 (一般是使用 rsync),好處是不會鎖表

sudo apt-get update
sudo apt-get install -y mariadb-server percona-xtrabackup

Upgrade MariaDB form 10.0 to 10.1 (Optional)

如果你的 MariaDB 還是 10.0 版,你可以升級它,除了安裝套件之外還要使用 mysql_upgrade 將原有的資料庫升級

sudo apt-get update
sudo apt-get remove -y mariadb-galera-server
sduo apt-get install mariadb-server

# Upgrade old table
sudo mysql_upgrade -u root -p

Setting Cluster

Add Cluster User

以下參數請自行帶入

  • CLUSTER_USER
  • CLUSTER_PASS
GRANT USAGE ON *.* to CLUSTER_USER@'%' IDENTIFIED BY 'CLUSTER_PASS';
GRANT ALL PRIVILEGES on *.* to CLUSTER_USER@'%';

Modify /etc/mysql/conf.d/galera.cnf

以下參數請自行帶入

  • CLUSTER_NAME
  • OTHER_NODE_IP
  • NODE_IP
  • NODE_NAME
  • CLUSTER_USER
  • CLUSTER_PASS
[galera]
# Mandatory settings
wsrep_on                    = ON
wsrep_provider              = /usr/lib/galera/libgalera_smm.so
wsrep_provider_options      = "gcache.size=2G"
wsrep_cluster_name          = "CLUSTER_NAME"
wsrep_cluster_address       = "gcomm://OTHER_NODE_IP:4567?pc.wait_prim=no"
wsrep_node_address          = "NODE_IP"
wsrep_node_name             = NODE_NAME
wsrep_sst_auth              = CLUSTER_USER:CLUSTER_PASS
wsrep_sst_method            = xtrabackup-v2

bind-address                = 0.0.0.0
binlog_format               = ROW
query_cache_size            = 0
query_cache_type            = 0
default_storage_engine      = InnoDB

innodb_autoinc_lock_mode    = 2
innodb_log_file_size        = 48M
innodb_data_file_path       = ibdata1:12M:autoextend
innodb_buffer_pool_size     = 400M

Firewall allow ports

  • 3306: MariaDB
  • 4444: SST (RSync, XtraBackup)
  • 4567: Galera Cluster
  • 4568: IST

Start Cluster Node

Master Node

sudo service mysql bootstrap

Slave Node

sudo service msyql start

Troubleshooting

About
ScarWu

刀疤

記錄學習過程、生活以及一些想說的話。