您的位置:首页 > 数据库 > SQL

mysql主主互备+原来mysql主从架构

2016-04-02 02:41 393 查看
接http://wsw26.blog.51cto.com/1442148/1749125我这个A已做了BC的主架构上增加一台D的虚拟机(同一个环境),我的目的是D和A主主互备,BC继续做A的从,既是D<-->A-->BC这样架构(类似级联的)




准备工作:
(1)D的IP是192.168.0.190,A的IP是192.168.0.8,B的IP是192.168.0.140,C的IP是192.168.0.141
(2)将A的mysql备份的sql通过scp传去D那里再从D那里新建对应的数据库名字后导入刚刚scp传过来的sql库,BC两个从库基本不用动它的了

一、首先在D和A的my.cnf做如下配置(红色圈住的代表是要配置正确)







read-only = 0/1 0: 允许从属服务器独立地执行SQL命令(默认设置); 1: 从属服务器只能执行来自主控服务器的SQL命令。

配置auto-increment-increment&auto-increment-offset的值

关于sync_binlog的数值: http://blog.csdn.net/wulantian/article/details/9965905,http://my.oschina.net/erichd/blog/499606?p=1
二、在D和A的mysql里先将各自同步的库锁表:flush tables with read lock;后,根据show master status\G;查到master的信息,再执行change master to master命令来做主从,只是D和A都先要执行:








如果show slave status\G;提示有错误的,各自就要先stop slave;reset slave;,再执行以下:
D:mysql> grant replication slave on *.* to 'repl'@'192.168.0.8' identified by '123456';
A: mysql> grant replication slave on *.* to 'repl'@'192.168.0.190' identified by '123456';
D:mysql> flush tables with read lock;
A:mysql> flush tables with read lock;
D: mysql> change master to master_host='192.168.0.8',master_user='repl',master_password='123456',master_log_file='mysql-bin.000010',master_log_pos=357;
A: mysql> change master to master_host='192.168.0.190',master_user='repl',master_password='123456',master_log_file='mysql-bin.000013',master_log_pos=440;
各自flush privileges;start slave;unlock tables;show slave status\G;








三、即可测试,D和A分别对db2的库各自操作,use db2(我的mysql库备份出来的库文件名)来删除库里面的其中一个表可否同步删除成功(能各自同步数据了,mysql_binlog会产生变化)














这样就可以基本大功告成了,数据同步,主主(DA)互备+mysql一主二从(A,BC)的架构
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息