2015年12月23日 星期三

[HA] - Mariadb + Galera

參考 https://goo.gl/uF18Yg

測試環境 : Debian8 64bit   PS ( InnoDB  Only / Myisam 不支援 , 也不建議開啟 )

D1 : 192.168.89.111 ( Node 1  )
D2 : 192.168.89.112 ( Node 2  )

1. 設定 Node1 / Node2 主機名稱
# vim /etc/hosts

192.168.89.211  L1
192.168.89.212  L2
192.168.89.111  D1
192.168.89.112  D2
192.168.89.100  G1


2 MariaDB repo 加進系統
# 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 wheezy main'

3 安裝套件
# sudo apt-get update
# sudo apt-get install mariadb-galera-server-10.0


4. Node 1 & Node2 兩台都先進去 Mariadb 設定帳號
# mysql -uroot -p

MariaDB [(none)]> > GRANT USAGE ON *.* TO cluster@'%' IDENTIFIED BY 'xxxxxx';
MariaDB [(none)]> > GRANT ALL PRIVILEGES ON *.* TO cluster@'%';
MariaDB [(none)]> > GRANT USAGE ON *.* TO cluster@'localhost' IDENTIFIED BY 'xxxxxx';
MariaDB [(none)]> > GRANT ALL PRIVILEGES ON *.* TO cluster@'localhost';
MariaDB [(none)]> > FLUSH PRIVILEGES;

5. 先設定 Node 1  192.168.89.111
# vim /etc/mysql/conf.d/wsrep.cnf

[MYSQLD]
wsrep_provider=/usr/lib/galera/libgalera_smm.so
binlog_format="row"
wsrep_cluster_name="MYCLUSTER"
wsrep_node_address="192.168.89.111"
wsrep_node_name="db1"
wsrep_cluster_address="gcomm://"
wsrep_sst_method=rsync
wsrep_sst_auth=cluster:xxxxxx

6. Restart 192.168.89.111  MariaDB
# sudo service mysql restart

7.  設定 Node2
# vim  /etc/mysql.conf.d/wsrep.cnf

[MYSQLD]
wsrep_provider=/usr/lib/galera/libgalera_smm.so
binlog_format="row"
wsrep_cluster_name="MYCLUSTER"
wsrep_node_address="192.168.89.112"
wsrep_node_name="db2"
wsrep_cluster_address="gcomm://192.168.89.111"
wsrep_sst_method=rsync
wsrep_sst_auth=cluster:xxxxxx

# sudo service mysql restart

8. 驗證服務 
# mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep%';"

9. 災難驗證 , 避免 Single point of failure
# 停掉服務 或 主機 ( D1 or D2 )

沒有留言: