创建配置文件
服务器 1
在/etc/mysql/my.cnf下增加
[mysqld]
server-id=1
log_bin=master-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
innodb_flush_log_at_trx_commit=1
服务器 2
在/etc/mysql/my.cnf下增加
[mysqld]
server-id=2
log_bin=master-bin
binlog-ignore-db=mysql
binlog-ignore-db=information_schema
binlog-ignore-db=performance_schema
binlog-ignore-db=test
innodb_flush_log_at_trx_commit=1
创建同步账户
// 服务器 1
GRANT REPLICATION SLAVE ON . TO ‘repuser’@‘server-2’ IDENTIFIED BY ‘repuser’;
FLUSH PRIVILEGES;
// 服务器 2
GRANT REPLICATION SLAVE ON . TO ‘repuser’@‘server-1’ IDENTIFIED BY ‘repuser’;
FLUSH PRIVILEGES;
可以顺便在另一台服务器测试能不能登录,如果不能,把 bind-address 那行注释掉即可。
$ mysql -urepuser -prepuser -hserver-1
查看 master 状态
服务器 1 中
MariaDB [mysql]> show master status; ±-------------------±---------±-------------±-----------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |±-------------------±---------±-------------±-----------------+| mariadb-bin.000514 | 639 | xxxxxxxx | mysql |±-------------------±---------±-------------±-----------------+1 row in set (0.00 sec)
服务器 2 中
?
MariaDB [mysql]> show master status; ±-------------------±---------±-------------±-----------------+| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |±-------------------±---------±-------------±-----------------+| mariadb-bin.000006 | 1057 | xxxxxxxx | mysql |±-------------------±---------±-------------±-----------------+1 row in set (0.00 sec)
// 服务器 2
MariaDB [mysql]> CHANGE MASTER TO MASTER_HOST=‘10.12.102.93’,MASTER_PORT=3306,MASTER_USER=‘repuser’,MASTER_PASSWORD=‘repuser’,MASTER_LOG_FILE=‘mariadb-bin.000514’,MASTER_LOG_POS=639;
MariaDB [mysql]> START SLAVE;
// 服务器 1
MariaDB [mysql]> CHANGE MASTER TO MASTER_HOST=‘10.12.102.95’,MASTER_PORT=3306,MASTER_USER=‘repuser’,MASTER_PASSWORD=‘repuser’,MASTER_LOG_FILE=‘mariadb-bin.000006’,MASTER_LOG_POS=1057;
MariaDB [mysql]> START SLAVE;
// 完毕之后,分别执行
MariaDB [mysql]> SHOW SLAVE STATUS\G
如出现以下两项,则说明配置成功!
Slave_IO_Running: