注:以下环境需要mysql初始环境相同,至少数据库及表结构一样,否则会出现后续无法同步数据的现象,但是依据下面部署完成后再建库和导表均可同步至另一台服务器。
环境描述:
OS:CentOS7.5_X64
MySQL-VIP:172.24.46.23(虚拟ip)
MySQL-master1:172.24.46.19
MySQL-master2:172.24.46.17
1、配置两台Mysql主主同步
[root@master ~]# yum install mysql-server mysql -y
[root@master ~]# service mysqld start
[root@master ~]# mysqladmin -u root password 123.com
[root@master ~]# vi /etc/my.cnf #开启二进制日志,设置id
[mysqld]
#backup这台设置2
server-id = 1
log-bin = mysql-bin
#忽略写入binlog日志的库
binlog-ignore-db = mysql,information_schema
#字段变化增量值
auto-increment-increment = 2
#初始字段ID为1
auto-increment-offset = 1
#忽略所有复制产生的错误
slave-skip-errors = all
[root@master ~]# service mysqld restart
如果是Centos7,则卸载mariadb,安装mysql,参考文章:https://blog.51cto.com/sf1314/2073389
安装mysql,参考文章:
mysql5.6.37 https://blog.51cto.com/sf1314/2058754
#mysql -uroot -p’密码’
先查看下log bin日志和pos值位置
show master status;
172.24.46.19上:

CREATE USER ‘replication’@‘172.24.46.17’ IDENTIFIED BY ‘Abc.123456’;
mysql> CREATE USER 'replication'@'172.24.46.17' IDENTIFIED WITH mysql_native_password BY 'Abc.123456';
mysql> grant ALL PRIVILEGES on *.* to 'replication'@'172.24.46.17' with grant option;
mysql> grant system_user on *.* to 'root';
mysql> flush privileges;
mysql> change master to master_host='172.24.46.17',master_user