Reference: http://blog.csdn.net/mr__fang/article/details/8692480http://www.2cto.com/database/201201/116756.htmlhttp:// blog.csdn.net/gzq_qiang/article/details/6988975http://blog.csdn.net/shiqidide/article/details/7254035 Software:
Mysql-server-5.6.29-1.el6.x86_64.rpmmysql-client-5.6.29-1.el6.x86_64.rpmwget http://mirror.centos.org/ centos/6/os/x86_64/packages/libaio-0.3.107-10.el6.x86_64.rpm
Operating system: centos6.5_x64Server: 192.168.1.20 (Master1)
192.168.1.21(Master1)
Installation configuration:don't introduce how to install, see02-02-linux to build a variety of software development environment notestest only synchronizes the test library, master version must be >=slave versionmysql>SELECT VERSION (); configuration files and explanations:
#######################配置master-master1#######################
user=mysql
log-bin=mysql-bin
#指定自己编号,一个集群中id唯一
server-id=1
#要同步的数据库,通过二进制日志同步,所以这里提示"要记录二进制日志的数据库"
binlog-do-db=test
#和binlog-do-db=test对应;如果要同步多个库,这两项参数多个几个就行了.
replicate-do-db=test
#指定哪些库不同步,mysql库肯定不能同步,毕竟每个库上面的用户信息和参数不同
binlog-ignore-db=mysql
#同上面忽略记录日志的库一一对应;是不要记录日志的数据库名,多个数据库中间用逗号(,)隔开
replicate-ignore-db=mysql
#表示如果一个MASTER挂掉的话,另外一个马上接管
log-slave-updates
#跳过同步过程中sql错误
slave-skip-errors=all
#开启同步
sync_binlog=1
#自增主键,每次+2
auto_increment_increment=2
#自增主键,从1开始,每次+2
auto_increment_offset=1
#######################EOF######################################
#######################配置master-master2#######################
user=mysql
log-bin=mysql-bin
#指定自己编号,一个集群中id唯一
server-id=2
#要同步的数据库,通过二进制日志同步,所以这里提示"要记录二进制日志的数据库"
binlog-do-db=test
#和binlog-do-db=test对应;如果要同步多个库,这两项参数多个几个就行了.
replicate-do-db=test
#指定哪些库不同步,mysql库肯定不能同步,毕竟每个库上面的用户信息和参数不同
binlog-ignore-db=mysql
#同上面忽略记录日志的库一一对应;是不要记录日志的数据库名,多个数据库中间用逗号(,)隔开
replicate-ignore-db=mysql
#表示如果一个MASTER挂掉的话,另外一个马上接管
log-slave-updates
#跳过同步过程中sql错误
slave-skip-errors=all
#开启同步
sync_binlog=1
#自增主键,每次+2
auto_increment_increment=2
#自增主键,从1开始,每次+2
auto_increment_offset=2
#表示从mysql服务器启动时不启动同步线程,这就要在启动从服务器之后,手工启动同步线程,在mysql> 提示符下面运行“start slave”就可以
skip-slave-start
#######################EOF######################################
Restart 2 mysql servers. #master1 $ mysql-uroot-pmysql> Grant replication Slave on * * to ' replication ' @ '% ' identified by ' replica tion ';#在master1上创建一个用户用于同步mysql>flush Privileges;mysql>show master status;mysql>show Processlist; #查看同步线程 #master2$ mysql-uroot-p#Master_log_file andMaster_log_posis the previous step on master,mysql>Change master to master_host= ' 192.168.1.20 ', master_user= ' replication ', master_password= ' replication ', Master_ Log_file= ' mysql-bin.000001 ', master_log_pos=406;mysql>start slave;mysql>show slave status;mysql>FLUSH TABLES with READ LOCK;mysql>Grant Replication Slave on * * to ' replication ' @ '% ' identified by ' replication ';mysql>Flush privileges;mysql>Show Master status;mysql> show Processlist; #测试同步数据# # #master1mysql > Use test;mysql>CREATE TABLE IF not EXISTS users (ID integer UNSIGNED auto_increment NOT null PRIMARY key,name varchar (+) NOT NULL U NIQUE,PASSWD varchar (+));mysql> Show tables; #此时再master2也可以看到该表mysql> INSERT into users values (1, ' 1 ', ' 1 ');mysql> SELECT * from users; # # #master2mysql> show tables;mysql> SELECT * from users;mysql>INSERT into users values (2, ' 2 ', ' 2 ');mysql> SELECT * from users;
From for notes (Wiz)
23.mysql Cluster (Master-master)