mariadb10.0.16_galera_集群配置
步骤
前提条件:
node1: db1 192.168.2.117
node2: db2 192.168.2.119
具体实现:
- 添加/etc/yum.repos.d/mariadb.repo
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.0.16/centos6-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
- 安装过程
1)yum install
http://dl.fedoraproject.org/pub/epel/6/x86_64/socat-1.7.2.3-1.el6.x86_64.rpm
2)yum install MariaDB-Galera-server MariaDB-client rsync galera
版本信息如下:
galera-25.3.5-1.rhel6.x86_64.rpm
MariaDB-Galera-10.0.16-centos6-x86_64-server
MariaDB-10.0.16-centos6-x86_64-compat.rpm
MariaDB-10.0.16-centos6-x86_64-common.rpm
MariaDB-10.0.16-centos6-x86_64-client.rpm
perl-DBI-1.609-4.el6.x86_64
rsync-3.0.6-9.el6_4.1.x86_64
- 设置mariadb的安全
1)启动service mysql start
2)修改/usr/bin/mysql_secure_installation,选择修改密码,其他的可全选y
- 为mariadb galera集群创建用户
mysql -u root -p
mysql> DELETE FROM mysql.user WHERE user='';
mysql> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY 'dbpass';
mysql> GRANT USAGE ON *.* to sst_user@'%' IDENTIFIED BY
'dbpass';
mysql> GRANT ALL PRIVILEGES on *.* to sst_user@'%';
mysql> FLUSH PRIVILEGES;
mysql> quit
- 在/etc/my.cnf.d/server.cnf后添加如下配置:
db1(先启动):
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.2.117,192.168.2.119"
wsrep_cluster_name='galera_cluster'
wsrep_cluster_address="192.168.2.117"
wsrep_node_name='db1'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
db2(后启动):
binlog_format=ROW
default-storage-engine=innodb
innodb_autoinc_lock_mode=2
innodb_locks_unsafe_for_binlog=1
query_cache_size=0
query_cache_type=0
bind-address=0.0.0.0
datadir=/var/lib/mysql
innodb_log_file_size=100M
innodb_file_per_table
innodb_flush_log_at_trx_commit=2
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.2.117,192.168.2.119"
wsrep_cluster_name='galera_cluster'
wsrep_node_address='192.168.2.119'
wsrep_node_name='db2'
wsrep_sst_method=rsync
wsrep_sst_auth=sst_user:dbpass
- 修改/etc/selinux/config中的SELINUX=disabled,重启机器
SELINUX=permissive
- 启动集群第一个节点 /etc/init.d/mysql start –wsrep-new-cluster
service mysql start
- 查看集群状态 mysql -u root -p
show status like 'wsrep%'
- 测试用例:
1)在db1上创建demo数据库,db2是自动创建demo
2)在关掉db2后,操作db1,再启动db2,db2的数据自动与db1同步