​主從複製的一個報錯(Relay log read failure)

  • 2020 年 2 月 17 日
  • 筆記

//

主從複製的一個報錯(Relay log read failure)

//

今天早上來到公司,遇到了一個主從複製的報錯問題,雖然解決的過程比較快,但是我感覺還是有一定的借鑒意義,遇到類似的錯誤code,大家可以參考一下:

錯誤資訊如下:

             Slave_IO_Running: Yes              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: 1594                     Last_Error: Relay log read failure: Could not parse relay log event entry.                     The possible reasons are: the master's binary log is corrupted                     (you can check this by running 'mysqlbinlog' on the binary log),                     the slave's relay log is corrupted                     (you can check this by running 'mysqlbinlog' on the relay log),                     a network problem, or a bug in the master's or slave's MySQL code.                     If you want to check the master's binary log or slave's relay log,                     you will be able to know their names by issuing 'SHOW SLAVE STATUS' on this slave.                   Skip_Counter: 0  

從錯誤的類型上看,應該是從庫找不到對應的relay log的事件了,造成這樣的問題有很多,錯誤資訊中給了4種提示:

1、master的binlog出現問題

2、slace的binlog出現問題

3、網路問題

4、可能是master或者slave中MySQL 源碼的bug(倒是供認不諱啊~~~)

這給了我一點提醒,因為這台機器昨天剛剛做過磁碟擴容,因為是個從庫,所以直接進行了停機擴容,隨後進行了MySQL的實例重啟,可能停機擴容再重啟對實例產生了一定的影響。。。(至於什麼影響?我想最有可能的是配置文件參數的變更吧)

怎麼辦呢???用網管思維先解決一下:

"網管,這台機器有問題,來看看",

"重啟試一下",

"重啟了,不行",

"換個機器吧"

先嘗試重啟複製,如下:

stop slave;start slave;show slave statusG

還是不行,但是報錯資訊改變了:

             Slave_IO_Running: Yes              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:                     Last_Error: Error initializing relay log position: Could not find target log file mentioned                     in relay log info in the index file './relay-bin.index' during relay log initialization                   Skip_Counter:  

這個提示資訊看意思是說沒有找到目標的relay log index文件,index文件是定義在指定目錄裡面的,查看了主從庫的relay-log文件路徑(雖然主庫上沒有relay log),相關參數如下:

主庫  mysql:(none) 09::>>show variables like '%relay%';  +-----------------------+--------------------------------------------+  | Variable_name         | Value                                      |  +-----------------------+--------------------------------------------+  | max_relay_log_size    | 0                                          |  | relay_log             | /data/mysql_3306/log/slave-relay-bin       |  | relay_log_index       | /data/mysql_3306/log/slave-relay-bin.index |  | relay_log_info_file   | relay-log.info                             |  | relay_log_purge       | ON                                         |  | relay_log_recovery    | OFF                                        |  | relay_log_space_limit | 0                                          |  +-----------------------+--------------------------------------------+   rows in set (. sec)    從庫  mysql:(none) 09::>>show variables like '%relay%';  +---------------------------+----------------+  | Variable_name             | Value          |  +---------------------------+----------------+  | max_relay_log_size        | 0              |  | relay_log                 |                |  | relay_log_basename        |                |  | relay_log_index           |                |  | relay_log_info_file       | relay-log.info |  | relay_log_info_repository | FILE           |  | relay_log_purge           | ON             |  | relay_log_recovery        | OFF            |  | relay_log_space_limit     | 0              |  +---------------------------+----------------+   rows in set (. sec)  

可以看到,從庫上沒有配置相關的relay log路徑,於是使用find的linux命令找到了從庫的relay-bin.index文件所在位置,是默認放在了/data文件夾下面,看來上面的報錯和relay log的文件位置有點關係。

鑒於上述原因,我們需要利用IO執行緒重新生成相應的relay log來在從庫應用,於是使用了下面的方法在從庫進行修復:

1、reset slave;

2、記錄相應的偏移量master_log_file和read_master_log_pos

3、重新使用change master語句和上面記錄的偏移量進行複製

4、start slave;重啟複製關係即可