https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university
【测试环境】
Ubuntu 14.04.1 LTS
mariaDB5.5+galera
host-1:172.31.18.11
host-2:172.31.18.22
以下操作为host-1和host-2都有:
【安装mariaDB+galera】
配置mariaDB源
以下可选:
USA源
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://nyc2.mirrors.digitalocean.com/mariadb/repo/5.5/ubuntu trusty
main‘
Japan源
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/5.5/ubuntu trusty
main‘
China源
sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp://keyserver.ubuntu.com:80 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://mirrors.hustunique.com/mariadb/repo/5.5/ubuntu trusty
main‘
安装mariaDB
sudo apt-get update
sudo apt-get install -y mariadb-server
注:安装过程中会提示输入mariaDB的root密码。
配置garale源
sudo apt-get install python-software-properties
sudo apt-key adv –recv-keys –keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
sudo add-apt-repository ‘deb http://mirror3.layerjet.com/mariadb/repo/5.5/ubuntu precise
main‘
安装galera包
sudo apt-get update
sudo apt-get install -y rsync galera mariadb-galera-server-5.5
【新建mariaDB集群用户】
mysql -uroot -pxxxxx
>GRANT USAGE ON *.* to [email protected]‘%‘ IDENTIFIED BY ‘tt123‘;
>GRANT ALL PRIVILEGES on *.* to [email protected]‘%‘;
>GRANT USAGE ON *.* to [email protected]‘localhost‘ IDENTIFIED BY ‘tt123‘;
>GRANT ALL PRIVILEGES on *.* to [email protected]‘localhost‘;
>flush privileges;
【配置galera cluster】
sudo cp /usr/share/mysql/wsrep.cnf /etc/mysql/conf.d/
修改wsrep.cnf文件中的下列内容:
wsrep_cluster_address="gcomm://172.31.18.11,172.31.18.22"
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_sst_auth=tt:tt123
注:wsrep_cluster_address还有一种写法为,
host-1:
wsrep_cluster_address="gcomm://172.31.18.11:4567"
host-2: wsrep_cluster_address="gcomm://172.31.18.11:4567"
后面所有的节点只要添加主节点IP及端口即可,不过我暂时没有测试这种写法如果主节点宕机会不会影响其他节点,后
面单点故障的时候再进行测试。
【启动测试】
确保所有节点mysql为stop状态
host-1:
sudo service mysql start --wsrep-new-cluster
host-2:
sudo service mysql start
host-1:
mysql -u root -e ‘SELECT VARIABLE_VALUE as "cluster size" FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE
VARIABLE_NAME="wsrep_cluster_size"‘ -pqwer1234
如返回如下结果则配置成功:
+--------------+
| cluster size |
+--------------+
| 2 |
+--------------+
注意事项:
galera节点必须有一个主节点,即执行如下语句的节点:
sudo service mysql start --wsrep-new-cluster
【关于脑裂】
对于只有2个节点的Galera Cluster和其他集群软件一样,需要面对极端情况下的"脑裂"状态。
为了避免这种问题,Galera引入了"arbitrator(仲裁人)"。
"仲裁人"是要找一台新机器,节点上没有数据,它在集群中的作用就是在集群发生分裂时进行仲裁,集群中可以有多个"仲裁人"节点。
"仲裁人"节点加入集群的方法如下:
On both the mysql nodes install mariadb-galera-server and galera. On the the machine thats going to be
arbiter only galera is neccesary.
garbd -a gcomm://172.31.18.11:4567 -g my_wsrep_cluster -d