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

mysql的主主(M-M)复制配置

2011-03-15 18:36 309 查看
mysqlde 主主复制架构

一、环境描述

服务器master1: 192.168.0.124

服务器master2: 192.168.0.129

二、主主配置过程

1、创建同步用户:

服务器master1:

grant replication slave,file on *.* to 'master'@'192.168.0.129' identified by '123456';

flush privileges;

服务器master2:

grant replication slave,file on *.* to 'master'@'192.168.0.124' identified by '123456';

flush privileges;

2、修改mysql配置文件

master1: vim /etc/my.cnf

log-bin=mysql-bin
server-id = 10
replicate-do-db=mysql
replicate-ignore-db=test
auto_increment_increment=2
auto_increment_offset=1
service mysqld restart

master2:
log-bin=mysql-bin
server-id = 20
replicate-do-db= mysql
replicate-ignore-db=test
auto_increment_increment=2
auto_increment_offset=2

service mysqld restart

3、重启mysql服务后,进入mysql命令行

master1:

mysql> flush tables with read lock;

mysql> show master status;记录二进制文件位置和pos
------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000005 | 106 | | |
+------------------+----------+--------------+------------------+

mysql> unlock tables;

mysql> change master to
> master_host='192.168.0.129',master_user='master',master_password='123456',master_log_file='mysql-bin.000004', > master_log_pos=106;

mysql> start slave;

master2:

mysql> flush tables with read lock;

mysql> show master status;
------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000004 | 106 | | |
+------------------+----------+--------------+------------------+

mysql> unlock tables;
mysql> change master to
> master_host='192.168.0.124',master_user='master',master_password='123456',
> master_log_file='mysql-bin.000005', master_log_pos=106;

mysql> start slave;

4、查看master1和master2的服务器的状态:

mysql> show slave status\G;

查看:Slave_IO_Running: Yes

Slave_SQL_Running: Yes

都显示yes为状态正常,直接进行数据测试即可
本文出自 “静穆纱的博客” 博客,请务必保留此出处http://jingmu.blog.51cto.com/1812003/516105
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: