Mariadb 主主复制

两台server1  192.168.1.189 &&  server2 192.168.1.226

安装mariadb数据库

yum -y install mariadb mariadb-server

修改server1  /etc/my.cnf

vim /etc/my.cnf

[mysqld]     

server_id=1          # ID,全网唯一
log-bin=mysql-bin     # 开启二进制日志 日志文件格式为 mysql-bin.XXXX
relay-log=mysql-relay-bin  # 中继日志文件, 日志文件格式为 mysql-relay-bin.XXXX

auto_increment_increment=2 #步进值auto_imcrement。一般有n台主MySQL就填n       #避免主键重复冲突
auto_increment_offset=1 #起始值。一般填第n台主MySQL。此时为第一台主MySQL

replicate-wild-ignore-table=mysql.%   # replicate-wild-ignore-table 忽略不需要复制的数据库和表
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%

修改server2 /etc/my.cnf

vim /etc/my.cnf
[mysqld]     

server_id=2          # ID,全网唯一
log-bin=mysql-bin     # 开启二进制日志 日志文件格式为 mysql-bin.XXXX
relay-log=mysql-relay-bin  # 中继日志文件, 日志文件格式为 mysql-relay-bin.XXXX

auto_increment_increment=2 #步进值auto_imcrement。一般有n台主MySQL就填n       #避免主键重复冲突
auto_increment_offset=2 #起始值。一般填第n台主MySQL。此时为第一台主MySQL

replicate-wild-ignore-table=mysql.%   # replicate-wild-ignore-table 忽略不需要复制的数据库和表
replicate-wild-ignore-table=test.%
replicate-wild-ignore-table=information_schema.%

server1 

grant replication slave on *.* to 'repl_user'@'192.168.1.226' identified by 'repl_passwd';  #创建一个用于复制的用户

MariaDB [(none)]> show master statusG                             # 查看position 值, 指针 和 File 名
*************************** 1. row ***************************
File: mysql-bin.000003
Position: 591
Binlog_Do_DB:
Binlog_Ignore_DB:
1 row in set (0.00 sec)

server2

change master to master_host='192.168.1.189',master_user='repl_user',master_password='repl_passwd',master_log_file='mysql-bin.000003',master_log_pos=591;
start slave; #开启主重复制
show slave statusG # 查看状态

*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.1.189          # 主mysql IP
Master_User: repl_user              # mysql 登入用户
Master_Port: 3306                   # 端口
Connect_Retry: 60                   # 重连时间
Master_Log_File: mysql-bin.000003   # 主mysql 上的二进制文件 名 
Read_Master_Log_Pos: 591                    # 指针位置
Relay_Log_File: mysql-relay-bin.000002      # 中继日志文件名
Relay_Log_Pos: 875                          # 指针位置 
Relay_Master_Log_File: mysql-bin.000003     #  
Slave_IO_Running: Yes                       # IO 进程, 用于去主mysql 拿数据 
Slave_SQL_Running: Yes                      # mysql 进程, 用于读取拿到的二进制文件 执行mysql语句  当看到Slave_IO_Running: YES、Slave_SQL_Running: YES才表明状态正常
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table: mysql.%,test.%,information_schema.%
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 591
Relay_Log_Space: 1169
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 1



以上是 server1 为master , server2为slave 的配置, 反过来再配置一边 就是主主复制了。

原文地址:https://www.cnblogs.com/blogscc/p/8286989.html