环境信息:
localhost102为主 localhost105为主的备。即是双主并采用keepalived的高可用的结构。
问题:由于误删了localhost105上的所有的binlog日志文件和索引文件。然后停机,再重启了。没有以前的索引文件和binlog文件。
状态:localhost102为主 ,localhost105为主的备 192.168.1.208为VIP
查看localhost102的状态时,报找不到localhost105以前的索引文件和binlog文件。
解决办法是:先让localhost105成为主,然后localhost102重新使用change master to语句,开始新的复制。
[MySQL@localhost102 softwares]# mysql -uroot -p -P3306
mysql> show master status\G
*************************** 1. row ***************************
File: mysql_bin.000009
Position: 154
Binlog_Do_DB:
Binlog_Ignore_DB:
Executed_Gtid_Set:
1 row in set (0.00 sec)
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.0.105
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin.000007
Read_Master_Log_Pos: 3857
Relay_Log_File: localhost102-relay-bin.000016
Relay_Log_Pos: 4023
Relay_Master_Log_File: mysql_bin.000007
Slave_IO_Running: No
Slave_SQL_Running: Yes
Last_IO_Errno: 1236
Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'Could not find first log file name in binary log index file'
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 11
Master_UUID: 1ea5f3d8-7776-11e7-ba21-000c2930cce4
Master_Info_File: /usr/local/mysql/data/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: 170805 09:29:38
解决办法:
停localhost102的keepalived,让localhost105成为主。
[root@localhost102 ~]# ps -ef | grep kee
root 17719 1 0 07:14 ? 00:00:02 /opt/keepalived-1.2.20/bin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf
root 17721 17719 0 07:14 ? 00:00:05 /opt/keepalived-1.2.20/bin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf
root 18202 17719 0 10:11 ? 00:00:00 /opt/keepalived-1.2.20/bin/keepalived -f /usr/local/keepalived/etc/keepalived/keepalived.conf
[root@localhost102 ~]#kill 17719
[root@localhost102 ~]#kill 17721
[root@localhost102 ~]#kill 18202
这是检测localhost105是否是主:即使用VIP 192.168.1.208是否可以连接localhost105的MySQL服务。可以的话,就是主了。也可以看keepalived的日志信息
[mysql@localhost105 ~]$ mysql -uroot -p -h192.168.1.208 -P3306
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1233
Server version: 5.7.18-log MySQL Community Server (GPL)
锁库,然后看状态
mysql> flush tables with read lock;
Query OK, 0 rows affected (0.01 sec)
mysql> show master status;
+------------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+------------------+----------+--------------+------------------+-------------------+
| mysql_bin.000002 | 154 | | | |
+------------------+----------+--------------+------------------+-------------------+
1 row in set (0.00 sec)
mysql> unlock tables;
Query OK, 0 rows affected (0.00 sec)
现在在localhost102上进行change master to操作
[root@localhost102 ~]# mysql -uroot -p -P3306
mysql> change master to master_host='192.168.0.105' master_user='repl',master_password ='123456',
master_log_file ='mysql_bin.000002' master_log_pos=154;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near 'master_user='repl',master_password ='123456',
master_log_file ='mysql_bin.000002' at line 1
报错:由于漏了写二个,号。
解决办法:
停slave之前,一定要看状态是否已经把 relay log文件应用完成了,没有完成的话,不要停slave。
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
mysql> stop slave;
mysql> change master to master_host='192.168.0.105', master_user='repl',master_password ='123456',
master_log_file ='mysql_bin.000002', master_log_pos=154;
Query OK, 0 rows affected, 2 warnings (0.06 sec)
mysql> start slave;
Query OK, 0 rows affected (0.03 sec)
mysql> show slave status \G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.0.105
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql_bin.000002
Read_Master_Log_Pos: 154
Relay_Log_File: localhost102-relay-bin.000002
Relay_Log_Pos: 320
Relay_Master_Log_File: mysql_bin.000002
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 154
Relay_Log_Space: 534
Until_Condition: None
Until_Log_File:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 11
Master_UUID: 1ea5f3d8-7776-11e7-ba21-000c2930cce4
Master_Info_File: /usr/local/mysql/data/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
现在localhost102已经开始读取localhost105的新binlog日志文件和索引文件了。恢复完成!然后可以测试一下双主的功能!