以前玩過 Percona XtraDB Cluster過了,這次用 MariaDB Galera Cluster build 自己的測試環境就順便記錄一下吧
- IP address:192.168.1.201、192.168.1.202
安裝 mariadb-galera-server-10.0
-
先把 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'
-
用 apt-get 安裝
sudo apt-get update sudo apt-get install mariadb-galera-server-10.0
-
兩台都先進去 mysql 設定帳號
mysql -uroot -p mysql> GRANT USAGE ON *.* TO cluster@'%' IDENTIFIED BY 'abcdefg'; mysql> GRANT ALL PRIVILEGES ON *.* TO cluster@'%'; mysql> GRANT USAGE ON *.* TO cluster@'localhost' IDENTIFIED BY 'abcdefg'; mysql> GRANT ALL PRIVILEGES ON *.* TO cluster@'localhost'; mysql> FLUSH ALL PRIVILEGES;
-
然後先設定 192.168.1.202
-
編輯 /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.1.202" wsrep_node_name="db2" wsrep_cluster_address="gcomm://" wsrep_sst_method=rsync wsrep_sst_auth=cluster:abcdefg
-
重跑 192.168.1.202 的MariaDB
sudo service mysql restart
-
-
然後設定 192.168.1.201
-
編輯 /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.1.201" wsrep_node_name="db1" wsrep_cluster_address="gcomm://192.168.1.202" wsrep_sst_method=rsync wsrep_sst_auth=cluster:1234
-
重跑 192.168.1.201 的MariaDB
-
-
如果兩台的 MariaDB 都有成功跑起來的話,這時候可以下:
mysql -uroot -p -e "SHOW STATUS LIKE 'wsrep%';"
如果看到
就是 OK 了