【环境】
Ubuntu 14.04
MariaDB 10.1 stable
【机器】
host-1: 10.0.5.11
host-2: 10.0.5.12
host-3: 10.0.5.13
<以下操作为host-1 2 3都有>
MariaDB官方安装向导:
https://downloads.mariadb.org/mariadb/repositories/#mirror=yamagata-university
安装MariaDB 10.1
- 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 [arch=amd64,i386,ppc64el] http://ftp.yz.yamagata-u.ac.jp/pub/dbms/mariadb/repo/10.1/ubuntu trusty main'
- sudo apt-get update
- sudo apt-get install rsync mariadb-server
注意:
1.安装过程会提示输入MariaDB的root密码
2.MariaDB 10.1及之后的版本默认自带galera cluster,不需要另行安装。
配置MariaDB集群用户:
- GRANT USAGE ON *.* to tt@'%' IDENTIFIED BY 'tt123';
- GRANT ALL PRIVILEGES on *.* to tt@'%';
- GRANT USAGE ON *.* to tt@'localhost' IDENTIFIED BY 'tt123';
- GRANT ALL PRIVILEGES on *.* to tt@'localhost';
- flush privileges;
修改/etc/MysqL/my.cnf文件中的[galera]部分如下:
- [galera]
- # Mandatory settings
- wsrep_on=ON
- wsrep_provider=/usr/lib/galera/libgalera_smm.so
- wsrep_cluster_address="gcomm://10.0.5.11,10.0.5.12,10.0.5.13"
- wsrep_sst_auth=tt:tt123
- binlog_format=row
- default_storage_engine=InnoDB
- innodb_autoinc_lock_mode=2
- #
- # Allow server to accept connections on all interfaces.
- #
- bind-address=0.0.0.0
- #
- # Optional setting
- #wsrep_slave_threads=1
- #innodb_flush_log_at_trx_commit=0
注意:以上操作在host-1 2 3中均要执行
启动测试:
确保所有节点MysqL服务为stop状态
host-1执行:service MysqL start --wsrep-new-cluster
host-2执行:service MysqL start
host-3执行: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"' -p<password>
如显示:
- +--------------+
- | cluster size | +--------------+
- | 3 | +--------------+
如果数字为3则表示集群成功,如为1则表示失败。