MySQL Replication陷入困境

问题描述 投票:0回答:1

我将MySQL Replication从Master设置为Slave。 “SHOW SLAVE STATUS \ G”显示不断增加的Seconds_Behind_Master。这是从最旧(最高)到最新(最低)的三个连续结果。谁知道什么是错的?............................................. .................................................. .................................................. .................................................. .................................................. .......

1

    mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: <excluding>
                  Master_User: <excluding>
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.002723
          Read_Master_Log_Pos: 893947806
               Relay_Log_File: design-hotels-database-relay-bin.000002
                Relay_Log_Pos: 7692403
        Relay_Master_Log_File: mysql-bin.002723
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: starwood_sop,starwood_blp
           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: 192464416
              Relay_Log_Space: 709176017
              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: 76613
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: 3
                  Master_UUID:
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Reading event from the relay log
           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:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.04 sec)

2

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: <excluding>
                  Master_User: <excluding>
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.002723
          Read_Master_Log_Pos: 908310158
               Relay_Log_File: design-hotels-database-relay-bin.000002
                Relay_Log_Pos: 7906291
        Relay_Master_Log_File: mysql-bin.002723
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: starwood_sop,starwood_blp
           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: 192678304
              Relay_Log_Space: 723538369
              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: 76698
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: 3
                  Master_UUID:
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Reading event from the relay log
           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:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.06 sec)

3

mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
               Slave_IO_State: Queueing master event to the relay log
                  Master_Host: <excluding>
                  Master_User: <excluding>
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.002723
          Read_Master_Log_Pos: 945765663
               Relay_Log_File: design-hotels-database-relay-bin.000002
                Relay_Log_Pos: 8389913
        Relay_Master_Log_File: mysql-bin.002723
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB:
          Replicate_Ignore_DB: starwood_sop,starwood_blp
           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: 193161926
              Relay_Log_Space: 760993874
              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: 76870
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: 3
                  Master_UUID:
             Master_Info_File: /var/lib/mysql/master.info
                    SQL_Delay: 0
          SQL_Remaining_Delay: NULL
      Slave_SQL_Running_State: Reading event from the relay log
           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:
                Auto_Position: 0
         Replicate_Rewrite_DB:
                 Channel_Name:
           Master_TLS_Version:
1 row in set (0.04 sec)
mysql replication database-replication master-slave
1个回答
1
投票

好吧,Exec_Master_Log_Pos也在增加,这表明SQL线程实际上正在工作并应用更改。只是不够快,无法跟上传入的日志,由Read_Master_Log_Pos的增长率表示

    Exec-pos              Read-pos
1:  192464416             893947806
2:  192678304 (+213,888)  908310158 (+14,362,352
3:  193161926 (+483,622)  945765663 (+37,455,505) 

因此,传入日志(Read-pos)的速率比复制能够执行从属实例上的更改的速率高很多倍。

复制滞后是一个复杂的问题,其原因很多。您可以使用许多配置设置来帮助提高从站的吞吐量。您没有描述有关当前配置或数据库更改的性质或正在更改的表的任何内容,因此我无法提供真正明智的建议。但以下是我通常做出的一些典型变化:

innodb_buffer_pool_size = <high> # depends on server RAM and other factors 
innodb_log_file_size = 1G # or more
innodb_flush_log_at_trx_commit = 2
master_info_repository = TABLE
relay_log_info_repository = TABLE
relay_log_recovery = ON
sync_master_info = 0
binlog_format = ROW # make sure all tables have PRIMARY KEY constraints

有关这些选项的详细信息,请参阅MySQL文档。

即使使用了所有这些调整技巧,最终您也可能达到极限,即从属设备在单个线程中重放在主服务器上的许多线程中创建的更改的能力。

您可能可以使用多线程从属设备,但这并不像听起来那么简单,所以在尝试之前需要阅读更多相关内容。

即使使用调优和多线程从站,也可能达到了硬件的极限。它根本无法足够快地处理变化。您可以将硬件升级到更快的CPU和更快的存储。

另一种选择是降低主数据库的更改速率。要么对主站进行节流更改,要么使用各自的从站部署多个主站,并平衡多个主站的更改。

© www.soinside.com 2019 - 2024. All rights reserved.