系统 Ubuntu 14.04.5 LTS (GNU/Linux 4.4.0-31-generic x86_64)
1.安装需要的源
sudo apt-get install software-properties-common
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv BC19DDBA
2.更新源加入
sudo vim /etc/apt/sources.list.d/galera.list
deb http://releases.galeracluster.com/ubuntu trusty main
deb http://releases.galeracluster.com/mysql-wsrep-5.6/ubuntu trusty main
deb http://releases.galeracluster.com/galera-3/ubuntu trusty main
3.更新源
sudo apt-get update
4.安装
sudo apt-get install galera-3 galera-arbitrator-3 mysql-wsrep-5.6
5.安装完后测试mysql是否正常启动
sudo service mysql start
5.1 .如果不能正常启动,注意是否有/var/run/mysqld/目录,及权限
sudo mkdir /var/run/mysqld/
sudo chmod 777 /var/run/mysqld/
6.创建远程联接用户
grant all on *.* to MyCluster@'%' identified by '********' with grant option;
flush privileges;
7.测试远程访问数据库
mysql -h 192.168.0.145 -uMyCluster -p
mysql -h 192.168.0.144 -uMyCluster -p
mysql -h 192.168.0.146 -uMyCluster -p
8.主节点配置
vim /etc/mysql/my.cnf
[mysqld]
bind-address = 0.0.0.0
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_cluster_name="galeracluster"
wsrep_cluster_address="gcomm://"
wsrep_sst_method=rsync
wsrep_sst_auth=MyCluster:********
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
9.从节点1的配置
vim /etc/mysql/my.cnf
[mysqld]
bind-address = 0.0.0.0
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_cluster_name="galeracluster"
wsrep_cluster_address="gcomm://192.168.0.144"
wsrep_sst_method=rsync
wsrep_sst_auth=MyCluster:********
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
10.从节点2的配置
vim /etc/mysql/my.cnf
[mysqld]
bind-address = 0.0.0.0
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=122M
wsrep_provider=/usr/lib/libgalera_smm.so
wsrep_provider_options="gcache.size=300M; gcache.page_size=1G"
wsrep_cluster_name="galeracluster"
wsrep_cluster_address="gcomm://192.168.0.144"
wsrep_sst_method=rsync
wsrep_sst_auth=MyCluster:********
!includedir /etc/mysql/conf.d/
!includedir /etc/mysql/mysql.conf.d/
11.先停止,再启动集群其他节点
sudo service mysql stop
sudo service mysql start --wsrep-new-cluster
mysql -uroot -p
SHOW GLOBAL STATUS WHERE Variable_name IN('wsrep_ready','wsrep_cluster_size','wsrep_cluster_status','wsrep_connected');
11.查看集群启动情况
mysql -uroot -p
SHOW GLOBAL STATUS WHERE Variable_name IN('wsrep_ready','wsrep_cluster_size','wsrep_cluster_status','wsrep_connected');