由于项目需要做冗余备份,同时了解mariadb10自带了galera集群功能于是测试,环境Centos7+mariadb10.1
一、安装mariadb
1、yum安装很简单 yum install -y mariadb-server,如何直接安装将会默认安装mariadb 5.5,如果需要安装mariadb10需要另外配置MariaDB.repo:
# MariaDB 10.1 CentOS repository list - created 2016-12-01 03:36 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
这是官方yum源,非常之慢,若要节省时间最好配置国内yum源。
[mariadb]
name = MariaDB
baseurl = https://mirrors.ustc.edu.cn/mariadb/yum/10.1/centos7-amd64
gpgkey=https://mirrors.ustc.edu.cn/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck=1
2、启动systemctl start mariadb 若可正常启动则说明安装无问题。
二、配置集群
1、修改配置文件/etc/my.cnf
其中关于galera的配置如下:
[galera]
# Mandatory settings
wsrep_on=ON
wsrep_provider=/usr/lib64/galera/libgalera_smm.so
wsrep_cluster_address="gcomm://192.168.3.100,192.168.3.201"
wsrep_sst_auth=tt:tt123
binlog_format=row
wsrep_node_address=192.168.3.201
default_storage_engine=InnoDB
innodb_autoinc_lock_mode=2
innodb_flush_log_at_trx_commit=0
innodb_buffer_pool_size=2G
#
# Allow server to accept connections on all interfaces.
#
bind-address=0.0.0.0
2、将配置复制到其他节点.
3、初始化有数据的节点:
/usr/sbin/mysqld --user=mysql --wsrep-new-cluster > mysql.log 2>&1
4、启动其他节点若能正常启动加入集群则配置成功,后面只需要systemctl start mysqld即可
扫描二维码关注公众号,回复:
3928916 查看本文章
5、查看集群状态:
SHOW STATUS LIKE 'wsrep%';
若显示集群的格式与配置个数一致,则说明所有节点均加入集群。
三、问题总结。
1、多网卡最后配置:wsrep_node_address=192.168.3.100,不然加入不成功
2、第一个主节点出现:[EEROR] WSREP: Failed to flush and lock tables,从字面意思看可以猜到是由于数据库一直有操作,不能锁表进行同步,关闭所有操作程序后同步正常。