MySQL的双主复制其实就是为主的时候同时也是从,为从是也是主。
实验环境
Master1:192.168.200.12
Master2:192.168.200.13
准备工作
所有机器关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# iptables -F
[root@localhost ~]# setenforce 0
Master1配置
修改配置文件
[root@localhost ~]# vim /etc/my.cnf
[mysqld]
#添加修改一下配置文件
server-id = 1
log-bin=mysql-binlog ##开启二进制日志
log-slave-updates=true ##允许从库更新数据
max_binlog_size=1024M ##二进制日志的大小
auto_increment_offset = 1
auto_increment_increment = 2 #奇数ID
replicate-ignore-db = information_schema ##忽略不同步的主从数据库
replicate-ignore-db = performance_schema
replicate-ignore-db = test
replicate-ignore-db = mysql
max_connections = 3000 ##超时次数
max_connect_errors = 30 ##连接失败次数
skip-character-set-client-handshake ##忽略应用程序想要设置的其他字符集
init-connect='SET NAMES utf8' ##连接时执行的SQL
character-set-server=utf8 ##服务端默认字符集
wait_timeout=1800 ##请求的最大连接时间
interactive_timeout=1800 ##和上一参数同时修改才会生效
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES ##sql模式
relay-log=relay-log-bin ##开启中继日志
relay-log-index=slave-relay-bin.index
[root@localhost ~]# systemctl restart mariadb
创建授权账号
[root@localhost ~]# mysql
MariaDB [(none)]> grant replication slave on *.* to 'repl'@'192.168.200.13' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status;
+---------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+-----