从从属数据库服务器

时间:2017-12-10 03:25:17

标签: mysql

我有一个带有bin日志文件bin.000008的主MySQL服务器A.还有一个从服务器B及其bin日志文件bin.000012。

从A到B的复制效果很好。

每次我将数据更改为服务器A时,服务器B都会正确复制它。

有一个新的MySQL服务器C.我将它作为服务器B的从属服务器。

问题是:

当我修改服务器A上的数据时,服务器B正确复制它。但是服务器C不会被更改。这意味着从服务器B到服务器C的复制无效。

我尝试重新启动服务器C上的从服务器。当从二进制日志中读取数据时,它显示 从主服务器获得致命错误1236:'服务器正在使用CHANGE MASTER连接到MASTER_AUTO_POSITION = 1 ,但主人已清除包含奴隶所需的GTID的二进制日志。'

以下是每个服务器的主从状态:

服务器C(服务器B的从属服务器):

db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 1579
                Connect_Retry: 60
              Master_Log_File: bin.000012
          Read_Master_Log_Pos: 194
               Relay_Log_File: cf3613332a61-relay-bin.000004
                Relay_Log_Pos: 355
        Relay_Master_Log_File: bin.000012
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
           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: 194
              Relay_Log_Space: 569
              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
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 65535
                  Master_UUID: dd7aa123-ca18-11e7-9411-0242ac110005
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-79,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)
]|

服务器B(服务器A的从属服务器,服务器C的主服务器):

db> show variables like '%slave%';
+------------------------------+-----------------------+
| Variable_name                | Value                 |
+------------------------------+-----------------------+
| init_slave                   |                       |
| log_slave_updates            | ON                    |
| log_slow_slave_statements    | OFF                   |
| pseudo_slave_mode            | OFF                   |
| rpl_stop_slave_timeout       | 31536000              |
| slave_allow_batching         | OFF                   |
| slave_checkpoint_group       | 512                   |
| slave_checkpoint_period      | 300                   |
| slave_compressed_protocol    | OFF                   |
| slave_exec_mode              | STRICT                |
| slave_load_tmpdir            | /tmp                  |
| slave_max_allowed_packet     | 1073741824            |
| slave_net_timeout            | 60                    |
| slave_parallel_type          | DATABASE              |
| slave_parallel_workers       | 0                     |
| slave_pending_jobs_size_max  | 16777216              |
| slave_preserve_commit_order  | OFF                   |
| slave_rows_search_algorithms | TABLE_SCAN,INDEX_SCAN |
| slave_skip_errors            | OFF                   |
| slave_sql_verify_checksum    | ON                    |
| slave_transaction_retries    | 10                    |
| slave_type_conversions       |                       |
| sql_slave_skip_counter       | 0                     |
+------------------------------+-----------------------+


db> show master status\G;
|[
*************************** 1. row ***************************
File: bin.000012
Position: 194
Binlog_Do_DB:
Binlog_Ignore_DB: mysql,sys,information_schema,performance_schema
Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
1 row in set (0.00 sec)
]|

db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 5961
                Connect_Retry: 60
              Master_Log_File: bin.000008
          Read_Master_Log_Pos: 27885
               Relay_Log_File: 217fcc5843c2-relay-bin.000005
                Relay_Log_Pos: 27684
        Relay_Master_Log_File: bin.000008
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,sys,information_schema,performance_schema
           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: 27885
              Relay_Log_Space: 27938
              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
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 0
                Last_IO_Error:
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 1
                  Master_UUID: c389aee6-ca16-11e7-81e3-0242ac110004
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp:
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:48-81
            Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81,
dd7aa123-ca18-11e7-9411-0242ac110005:1-13
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.00 sec)
]|

服务器A(服务器B的主服务器):

db> show master status\G;
|[
*************************** 1. row ***************************
File: bin.000008
Position: 27885
Binlog_Do_DB:
Binlog_Ignore_DB: mysql,sys,information_schema,performance_schema
Executed_Gtid_Set: c389aee6-ca16-11e7-81e3-0242ac110004:1-81
1 row in set (0.00 sec)
]|

在服务器C上重启奴隶:

db> stop slave;
db> start slave;
db> show slave status\G;
|[
*************************** 1. row ***************************
               Slave_IO_State:
                  Master_Host: luexu.com
                  Master_User: Aario
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File:
          Read_Master_Log_Pos: 4
               Relay_Log_File: cf3613332a61-relay-bin.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File:
             Slave_IO_Running: No
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: mysql,information_schema,performance_schema,sys
           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: 0
              Relay_Log_Space: 308
              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
Master_SSL_Verify_Server_Cert: No
                Last_IO_Errno: 1236
                Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'
               Last_SQL_Errno: 0
               Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
             Master_Server_Id: 65535
                  Master_UUID: dd7aa123-ca18-11e7-9411-0242ac110005
             Master_Info_File: /master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
           Master_Retry_Count: 86400
                  Master_Bind:
      Last_IO_Error_Timestamp: 171210 04:01:51
     Last_SQL_Error_Timestamp:
               Master_SSL_Crl:
           Master_SSL_Crlpath:
           Retrieved_Gtid_Set:
            Executed_Gtid_Set: 074c1f93-dd08-11e7-b173-0242ac110004:1-3
                Auto_Position: 1
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
]|

1 个答案:

答案 0 :(得分:0)

我不确定你的问题因此只是一些想法 - 也许你会在其中找到一些灵感:

设置链复制A-> B-> C?如果不能避免这种复杂性,只需制作A的C副本(你可以通过简单克隆已经工作的B副本来实现它 - 见这里:http://mysql.freeideas.cz/subdom/mysql/2017/08/14/create-new-replica-by-copying-data-and-log-files-on-os-level/

如果你真的必须链接你的复制,那么它通常工作正常,我们用它来进行更大的架构更改,而不需要长时间停机,甚至可以在不同的MySQL版本之间工作。

当我们需要从一个云提供商转移到另一个云提供商时,我们第一次使用它 - 我们在旧云上使用了(A)旧主人 - > (B)新云上新的预期主人 - > (C)应用程序的新云副本。目前我们将其设置为使用新版MySQL的新应用程序开发 - (A)旧5.5 Master - > (B)5.7 replica / master - > (C)应用程序的5.7个副本。

你只需要设置" log_slave_updates = ON" on" master replica"并且从B创建B副本的方式与从A创建B的方式相同 - 请参阅此处的一般注释:http://mysql.freeideas.cz/subdom/mysql/2016/11/10/how-to-manually-set-mysql-replication/

含义 - 您必须在B上为C进行转储,并且复制已停止并且表针对更改锁定并记录B的主状态并使用它来设置C.当然 - 您必须确保B上的bin日志将存在& #34;足够长" - 设置" expire_logs_days"在B到几天(当然你必须有足够的磁盘空间)。设置中的所有这些更改都需要重新启动。