1、前期准备:
A、安装Linux(CentOS系统),MySQL相关软件,本文使用CentOS自带系统。
B、CentOS-Master1(IP:192.168.227.128),CentOS-Master2(IP:192.168.227.129)两个系统上均关闭防火墙
2、配置MM模式:
A、在Master1上修改MySQL配置文件(/etc/my.cnf)追加内容如下:
server-id=1
master-host=192.168.227.129
master-user=repl
master-password=123456
master-port=3306
master-connect-retry=60
log-bin=mysql-bin
binlog-do-db=test
并进入MySQL的shell做如下操作:
mysql> grant replication slave on *.* to identified by '123456';
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000014 | 782 | test | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:红色字体部分要在Master2上做Chang Master to操作时使用。
mysql> change master to
master_host='192.168.227.129',master_user='repl',master_password='123456',master_log_file='mysql-bin.000009',master_log_pos='1466'
mysql> stop slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.227.129
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000009
Read_Master_Log_Pos: 1466
Relay_Log_File: mysqld-relay-bin.000005
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000009
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 1466
Relay_Log_Space: 235
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
mysql>
B、在Master2上修改MySQL配置文件(/etc/my.cnf)追加内容如下:
server-id=2
master-host=192.168.227.128
master-user=repl
master-password=123456
master-port=3306
master-connect-retry=60
log-bin=mysql-bin
binlog-do-db=test
并进入MySQL的shell进行如下操作:
mysql> show master status;
+------------------+----------+--------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000009 | 1466 | test | |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)
注:红字部分要在Master1上做Chang Master to操作时使用,
在MySQL的shell上做如下操作:
mysql> grant replication slave on *.* to identified by '123456';
mysql> change master to
master_host='192.168.227.128,master_user='repl',master_password='123456',master_log_file='mysql-bin.0000014',master_log_pos='782'
mysql> stop slave;
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.227.128
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000014
Read_Master_Log_Pos: 782
Relay_Log_File: mysqld-relay-bin.000006
Relay_Log_Pos: 235
Relay_Master_Log_File: mysql-bin.000014
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 782
Relay_Log_Space: 235
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
1 row in set (0.00 sec)
mysql>
注:以上操作步骤中的信息是操作后才总结的,信息有不匹配的地方。
配置思想总结:
在Node1修改配置信息,并获取Mysql的master status信息,在Node2上使用Node1上的master status信息进行Chang Master to操作,执行show processlist\G及show slave status\G以确认是否正确启动。
在Node2修改配置信息,并获取Mysql的master status信息,在Node1上使用Node2上的master status信息进行Chang Master to操作,执行show processlist\G及show slave status\G以确认是否正确启动。
常见错误说明:
Slave_IO_State: Waiting for master to send event(表示已经正确连接上了)
为空表示复制没有启动。
为Connecting to master为没连接上master
mysql> show slave status\G
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
此两项线程显示为yes则正常!
注:配置操作期间参考很多网上资料在此表示感谢。
阅读(1250) | 评论(0) | 转发(0) |