分类: Mysql/postgreSQL
2013-04-10 14:37:15
配置mysql双主架构
环境:
Master1:
192.168.212.136
系统:centos5.8
数据库:percona-server mysql5.5.29
Master2:
192.168.212.206
系统:centos5.8
数据库:percona-server mysql5.5.29
1. 数据库的安装在此省略。(建议使用源码安装)。
2. Maser1主机配置
修改配置文件my.cnf,打开bin-log 日志。下面是主要和必须的配置参数 。
[mysqld]
server-id = 1
sync_binlog =1
innodb_flush_log_at_trx_commit = 1
innodb_support_xa =1
log_slave_updates =1
slave-skip-errors =all
auto_increment_increment=2
auto_increment_offset=1
#下面这些数据库可不用同步,减少因为权限更新引起的权限混乱#
replicate-wild-ignore-table =mysql.%
replicate-wild-ignore-table =test.%
replicate-wild-ignore-table =log.%
replicate-wild-ignore-table =information_schema.%
replicate-wild-ignore-table =performance_schema.%
在Master1上创建复制账号:
grant replication slave,replication client on *.* to identified by ;
3. Maser2主机配置
修改配置文件my.cnf,打开bin-log 日志。下面是主要和必须的配置参数 。
[mysqld]
server-id = 2
sync_binlog =1
innodb_flush_log_at_trx_commit = 1
innodb_support_xa =1
log_slave_updates =1
slave-skip-errors =all
auto_increment_increment=2
auto_increment_offset=2
#下面这些数据库可不用同步,减少因为权限更新引起的权限混乱#
replicate-wild-ignore-table =mysql.%
replicate-wild-ignore-table =test.%
replicate-wild-ignore-table =log.%
replicate-wild-ignore-table =information_schema.%
replicate-wild-ignore-table =performance_schema.%
在Master2上创建复制账号:
grant replication slave,replication client on *.* to identified by ;
4. 锁定Master1的库不能写入数据;
flush tables with read lock;
Show master status;查看日志和偏移量
5. 锁定Master2的库不能写入数据;
flush tables with read lock;
Show master status;查看日志和偏移量
6. 在Master1上进行同步
change master to
master_host='192.168.212.206',
master_user='repl',
,
master_log_file='mysql-bin.000007',
master_log_pos=107;
7. 在Master2上进行同步
change master to
master_host='192.168.212.136',
master_user='repl',
,
master_log_file='mysql-bin.000007',
master_log_pos=107;
8.Master1和Master2解锁
unlock tables;
并打开slave :slave start;
9.分别在Master1和Master2上查看Slave状态
Show slave stasue\G