mariadb双主模式

创建配置文件

服务器 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:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值