terte 发表于 2018-4-9 10:00:35

MySQL双主(主主)架构

128机器:


1
2
3
# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!





129机器:


1
2
3
# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!





先配主从:
128机器上:
拷贝数据并传输到129机器上

1
2
# mysqldump -uroot -p123456 --all-databases > /tmp/mysqlall.sql
# scp -r /tmp/mysqlall.sql 192.168.65.129:/tmp/






1
2
3
mysql> grant replication slave on *.* to 'repl'@192.168.65.129 identified by '123456';

mysql> flush privileges;




测试机器数据变化基本没有,所以就不锁表了


129机器上:

1
# mysql -uroot -p123456 < /tmp/mysqlall.sql






1
2
3
4
5
6
7
8
9
10
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='192.168.65.128', master_user='repl', master_password='123456', master_log_file='thermos.000001, master_log_pos=420;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

mysql> show slave statusG





主从同步完成

主主同步:
129机器上:
更改/etc/my.cnf,增加log_bin


1
2
3
# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!






1
2
3
4
5
mysql> grant replication slave on *.* to 'repl'@192.168.65.128 identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)





128机器上:

1
2
3
4
5
6
7
8
9
10
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host='192.168.65.129', master_user='repl', master_password='123456', master_log_file='alex.000001', master_log_pos=420;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave statusG






测试主主
128上

129上

(已经多了micheal库)

129上

128上

(多了jackson库)

自己研究的,不知道正确与否,如果有错误,望指正!
页: [1]
查看完整版本: MySQL双主(主主)架构