一次MySQL主主同步异常的经历

一次MySQL主主同步异常的经历。

MySQL主主同步的时候有一台MySQLSlave_IO_Running: Connecting始终处于连接中。

mysql> show slave status\G;

*************************** 1. row***************************

               Slave_IO_State: Connecting tomaster

                  Master_Host: 192.168.58.3

                  Master_User: root

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000003

         Read_Master_Log_Pos: 908

               Relay_Log_File:mysql-relay-bin.000001

                Relay_Log_Pos: 4

       Relay_Master_Log_File: mysql-bin.000003

            Slave_IO_Running: Connecting

           Slave_SQL_Running: Yes

              Replicate_Do_DB:

         Replicate_Ignore_DB:

          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: 908

              Relay_Log_Space: 154

              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: 2003

               Last_IO_Error: error connecting to master '[email protected]:3306' - retry-time: 60  retries: 34

               Last_SQL_Errno: 0

               Last_SQL_Error:

 Replicate_Ignore_Server_Ids:

            Master_Server_Id: 0

                  Master_UUID:

            Master_Info_File: /var/lib/mysql/master.info

                    SQL_Delay: 0

         SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: Slave has read allrelay log; waiting for more updates

          Master_Retry_Count: 86400

                  Master_Bind:

     Last_IO_Error_Timestamp: 180604 09:10:24

    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.00 sec)

 

其中192.168.58.3MySQL可以连接到192.168.58.2MySQL192.168.58.2MySQL去连接192.168.58.3MySQL报错。

远程连接一下MySQL做一下尝试。

[root@test1 ~]# mysql -h 192.168.58.3 -p

Enter password:

ERROR 2003 (HY000): Can't connect to MySQLserver on '192.168.58.3' (113)

远程失败,查询一下代码报什么错

[root@test2 ~]# perror 113

OS error code 113:  No route to host

使用telnet去测试3306端口,发现不通。

telnet 192.168.58.3 3306

Connecting to 192.168.58.3:3306...

Canceled.

查看是否开启iptables

[root@test2 ~]# service iptables status;

表格:filter

Chain INPUT (policy ACCEPT)

num target     prot opt source               destination        

1   ACCEPT     all  -- 0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED

2   ACCEPT     icmp --  0.0.0.0/0            0.0.0.0/0          

3   ACCEPT     all  -- 0.0.0.0/0            0.0.0.0/0          

4   ACCEPT     tcp  -- 0.0.0.0/0           0.0.0.0/0           state NEW tcpdpt:22

5   REJECT     all  -- 0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT)

num target     prot opt source               destination        

1   REJECT     all  -- 0.0.0.0/0            0.0.0.0/0           reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT)

num target     prot opt source               destination        

测试发现防火墙有开启,但并未加上3306端口允许。

在192.168.58.3的防火墙上加上3306端口

[root@test2 ~]# iptables -I INPUT -s 0/0-p tcp --dport 3306 -j ACCEPT

这条规则的意思是,想要在输入数据INPUT中,protocol为tcp/IP的方式,访问端口3306,都会被允许的

[root@test2 ~]# # iptables -L -n|grep 3306

ACCEPT    tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:3306

或者使用iptables-save命令检查。

[root@test2 ~]# iptables-save|grep 3306

-A INPUT -p tcp -m tcp --dport 3306 -jACCEPT

如果不需要使用iptables服务的话,直接停止iptables服务即可。

service iptablesstop

现在telnet端口成功了

[root@test1 ~]# telnet 192.168.58.2 3306

Connecting to 192.168.58.2:3306...

Connection established.

To escape to local shell, press 'Ctrl+Alt+]'.

N

 5.7.18-logEd'7(ispa|)Y3z

                         \

                          Wmysql_native_password

!#08S01Got packets out of order

Connection closed by foreign host.

再次尝试远程连接,成功。

[root@test1 ~]# mysql -h 192.168.58.3-uroot -p

Enter password:

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 16

Server version: 5.7.18-log MySQL CommunityServer (GPL)

 

Copyright (c) 2000, 2017, Oracle and/or itsaffiliates. All rights reserved.

 

Oracle is a registered trademark of OracleCorporation and/or its

affiliates. Other names may be trademarksof their respective

owners.

 

Type 'help;' or '\h' for help. Type '\c' toclear the current input statement.

 

查看一下连接用户

mysql> select user();

+-------------------+

| user()            |

+-------------------+

| [email protected] |

+-------------------+

1 row in set (0.01 sec)

 

再次查看192.168.58.2的同步状态

mysql> show slave status\G;

*************************** 1. row***************************

               Slave_IO_State: Waiting formaster to send event

                  Master_Host: 192.168.58.3

                  Master_User: root

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000003

         Read_Master_Log_Pos: 908

              Relay_Log_File:mysql-relay-bin.000001

                Relay_Log_Pos: 4

       Relay_Master_Log_File: mysql-bin.000003

            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: 1032

                  Last_Error: Could not execute Delete_rows event on table mysql.user;Can't find record in 'user', Error_code: 1032; handler errorHA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000006, end_log_pos 1727

                 Skip_Counter: 0

         Exec_Master_Log_Pos: 1073

              Relay_Log_Space: 5024

              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: 0

                Last_IO_Error:

              Last_SQL_Errno: 1032

              Last_SQL_Error: Could not execute Delete_rows event on table mysql.user;Can't find record in 'user', Error_code: 1032; handler errorHA_ERR_KEY_NOT_FOUND; the event's master log mysql-bin.000006, end_log_pos 1727

 Replicate_Ignore_Server_Ids:

            Master_Server_Id: 2

                  Master_UUID:4faab039-654b-11e8-9e6a-000c29554567

            Master_Info_File: /var/lib/mysql/master.info

                    SQL_Delay: 0

         SQL_Remaining_Delay: NULL

     Slave_SQL_Running_State:

          Master_Retry_Count: 86400

                  Master_Bind:

     Last_IO_Error_Timestamp:

    Last_SQL_Error_Timestamp: 180604 10:09:27

               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.00 sec)

发现Slave_SQL_Running: No

停止slave

mysql> stop slave;

查看192.168.58.3master是否有变化

mysql> show master status;

+------------------+----------+--------------+------------------+-------------------+

| File             | Position | Binlog_Do_DB |Binlog_Ignore_DB | Executed_Gtid_Set |

+------------------+----------+--------------+------------------+-------------------+

| mysql-bin.000006 |     4391 |              |                  |                   |

+------------------+----------+--------------+------------------+-------------------+

1 row in set (0.00 sec)

查询发现的确有变化,那么需要重新配置从服务器Slave

mysql> change master tomaster_host='192.168.58.3',master_user='root',master_password='123456',master_log_file='mysql-bin.000006',master_log_pos=4391;

重新启动slave

mysql> start slave;

Query OK, 0 rowsaffected (0.00 sec)

查看主从状态正常

mysql> show slave status\G;

***************************1. row ***************************

               Slave_IO_State: Waiting formaster to send event

                  Master_Host: 192.168.58.3

                  Master_User: root

                  Master_Port: 3306

                Connect_Retry: 60

              Master_Log_File: mysql-bin.000006

          Read_Master_Log_Pos: 4391

               Relay_Log_File:mysql-relay-bin.000002

                Relay_Log_Pos: 320

        Relay_Master_Log_File: mysql-bin.000006

             Slave_IO_Running: Yes

            Slave_SQL_Running: Yes

              Replicate_Do_DB:

          Replicate_Ignore_DB:

           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: 4391

              Relay_Log_Space: 527

              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: 2

                  Master_UUID:4faab039-654b-11e8-9e6a-000c29554567

             Master_Info_File:/var/lib/mysql/master.info

                    SQL_Delay: 0

          SQL_Remaining_Delay: NULL

      Slave_SQL_Running_State: Slave has readall 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:

                Auto_Position: 0

         Replicate_Rewrite_DB:

                 Channel_Name:

           Master_TLS_Version:

1 row in set (0.00sec)

你可能感兴趣的:(MySQL)