1、接着之前配置的主主复制的基础,在每个主库下面分别配置一个从库
master1:
master2:
2、复制环境
3、逻辑备份数据库test
4、在两个从库上创建用户
5、在从库上导入数据,并更改参数
6、查看master1主库的POS,并在slave上配置POS
7、在slave上重复3-6的步骤。
master1:
- mysql> select * from t1;
- +----+----------+
- | id | name |
- +----+----------+
- | 1 | aaaaa |
- | 2 | aaaaa |
- | 3 | bbbbbbbb |
- | 5 | bbbbbbbb |
- +----+----------+
- 4 rows in set (0.00 sec)
- mysql> select * from t1;
- +----+----------+
- | id | name |
- +----+----------+
- | 1 | aaaaa |
- | 2 | aaaaa |
- | 3 | bbbbbbbb |
- | 5 | bbbbbbbb |
- +----+----------+
- 4 rows in set (0.00 sec)
- master1(10.10.10.20)—>slave1(10.10.10.21)
- master2(10.10.10.30)—>slave2(10.10.10.22)
- mysql> flush table with read lock;
- Query OK, 0 rows affected (0.00 sec)
-
- root@master1:/root# mysqldump -u root -p -c test > /tmp/test1.sql
- Enter password:
- root@master1:/root# scp /tmp/test1.sql 10.10.10.21:/tmp/
- root@10.10.10.21 test1.sql 100% 1953 1.9KB/s 00:00
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
- mysql> create user rep_user;
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> grant replication slave on *.* to rep_user identified by 'rep_user';
- Query OK, 0 rows affected (0.01 sec)
-
- mysql> grant super on *.* to rep_user identified by 'rep_user';
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> grant replication client on *.* to rep_user identified by 'rep_user';
- Query OK, 0 rows affected (0.00 sec)
-
- mysql> show grants for rep_user;
- +------------------------------------------------------------------------------------------------------------------------------------------------+
- | Grants for rep_user@% |
- +------------------------------------------------------------------------------------------------------------------------------------------------+
- | GRANT SUPER, REPLICATION SLAVE, REPLICATION CLIENT ON *.* TO 'rep_user'@'%' IDENTIFIED BY PASSWORD '*66275EE2A4400687CE14AD3B2CEE003B1B753575' |
- +------------------------------------------------------------------------------------------------------------------------------------------------+
- 1 row in set (0.00 sec)
- root@slave1:/root# mysql -u root -p -D test < /tmp/test1.sql
- Enter password:
-
- vi /etc/my.cnf
- server-id = 21
- binlog-do-db = test
-
- relay-log = slave-relay-bin
- relay-log-index = slave-relay-bin.index
- mysql> CHANGE MASTER TO
- -> MASTER_HOST = '10.10.10.20',
- -> MASTER_PORT = 3306,
- -> MASTER_USER = 'rep_user',
- -> MASTER_PASSWORD = 'rep_user',
- -> MASTER_LOG_FILE = 'master1-bin.000002',
- -> MASTER_LOG_POS = 387;
- Query OK, 0 rows affected, 2 warnings (0.05 sec)
-
- mysql> start slave;
- Query OK, 0 rows affected (0.00 sec)
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12219480/viewspace-1768487/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12219480/viewspace-1768487/