我刚创build了两个EC2实例,并为每个实例获得了一个弹性IP。 我似乎无法得到它连接。 这是我的configuration大部分:
auto_increment_offset=2 log-bin=master2-bin binlog-ignore-db=mysql server-id = 2 master-host = 10.122.191.151 master-user = slaverep master-password = ********* master-port = 3306
其他服务器的configuration是非常相似的(但在几件事情中不同的IP)。
当我运行:
mysql> show slave status\G;
我看到以下内容:
*************************** 1. row *************************** Slave_IO_State: Connecting to master Master_Host: 107.20.178.31 Master_User: replication Master_Port: 3306 Connect_Retry: 60 Master_Log_File: mysqld-bin.000002 Read_Master_Log_Pos: 1145380 Relay_Log_File: mysqld-relay-bin.000005 Relay_Log_Pos: 618 Relay_Master_Log_File: mysqld-bin.000002 Slave_IO_Running: No Slave_SQL_Running: No Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 1062 Last_Error: Error 'Duplicate entry '2124' for key 'PRIMARY'' on query. Default database: 'phpmyfaq'. Query: 'INSERT INTO faqsessions (sid, user_id, ip, time) VALUES (2124, -1, '10.223.61.111', 1314625795)' Skip_Counter: 0 Exec_Master_Log_Pos: 472 Relay_Log_Space: 1148388 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: NULL Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 1130 Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60 retries: 86400 Last_SQL_Errno: 1062 Last_SQL_Error: Error 'Duplicate entry '2124' for key 'PRIMARY'' on query. Default database: 'phpmyfaq'. Query: 'INSERT INTO faqsessions (sid, user_id, ip, time) VALUES (2124, -1, '10.223.61.111', 1314625795)' 1 row in set (0.00 sec) ERROR: No query specified
我不知道该怎么做
编辑:
我已经修复了我的设置,以匹配以下内容:MASTER1:
auto_increment_increment = 1 auto_increment_offset = 2
MASTER2:
auto_increment_increment = 2 auto_increment_offset = 2
两台服务器都尝试使用相同的自动增量ID集,从而在复制发生时导致冲突。
要解决这个问题,你需要调整auto_increment_offset (在第一个服务器上是1,在第二个上是2)和auto_increment_increment (到2)。 如果你最终添加第三个服务器,它的auto_increment_offset将需要为3,所有三个服务器将需要3的auto_increment_increment 。
这将导致服务器1使用1,3,5,7,9 …的自动增量ID,服务器2将使用2,4,6,8,10,防止冲突。