mysql数据没有复制,但复制似乎很好

时间:2015-10-10 03:20:54

标签: mysql replication mariadb database-replication

我有一台运行mariadb 10.0.21的4机器mysql集群。我有两个主人设置,彼此奴役。然后是两个分别从第一个和第二个db复制的只读从属。

简而言之,其设置方式如下:

db1 replicates -> db2
db1 replicates -> db3
db2 replicates -> db1
db2 replicates -> db4

这是一个非常基本的4分贝设置。

我遇到的问题是我设置了一个nagios用户来监控第一个数据库上的集群。

我检查过,我可以登录前三个数据库,但不能登录到nagios用户的第四个数据库。我可以在不在每个数据库上创建nagios用户的情况下这样做,因为我在前两个数据库机器上复制了我的mysql数据库。

但由于某种原因,nagios用户从来没有像在db2上那样在db2上创建,即使复制似乎在所有节点上都很好。

您可能还记得,我有db 2复制到第4个数据库。

如果我在db 2上执行show master状态,我可以看到我正在复制mysql db:

MariaDB [mysql]> show master status;
+--------------------+----------+------------------------------+------------------+
| File               | Position | Binlog_Do_DB                 | Binlog_Ignore_DB |
+--------------------+----------+------------------------------+------------------+
| mariadb-bin.000078 |      376 | jfwiki,jokefire,bacula,mysql |                  |
+--------------------+----------+------------------------------+------------------+
1 row in set (0.00 sec)

如果我检查第二个数据库上的nagios用户是否存在,那就是。

 MariaDB [mysql]> select User,Host,Password from user where user like 'nagios';
    +--------+-------------+-------------------------------------------+
    | User   | Host        | Password                                  |
    +--------+-------------+-------------------------------------------+
    | nagios | 52.4.204.96 | *somepasswordhash                         |
    +--------+-------------+-------------------------------------------+
    1 row in set (0.00 sec)

此用户未在db2上创建,但由于复制而存在。

如果我检查db4上的slave状态,复制似乎完全正常:

[root@db4:~] #mysql -e "show slave status\G" | egrep "Slave_IO_State|Master_Host|Slave_IO_Running|Slave_SQL_Running|Last_Errno|Seconds_Behind_Master"
               Slave_IO_State: Waiting for master to send event
                  Master_Host: db2.example.com
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
                   Last_Errno: 0
        Seconds_Behind_Master: 0

如果我按照db2上的方式检查db4上nagios用户的存在,那么用户就不会:

MariaDB [mysql]> select User,Host from user where user like 'nagios';
Empty set (0.00 sec)

所以我的问题是,为什么nagios用户没有像从db1那样复制到db4 - > db2和db1 - > DB3?甚至db4上的slave复制似乎还可以吗?我可以使用监控主机中的nagios用户登录所有主机。

这里是db4上slave slave命令的完整输出,以防我错过了我之前的grep:

MariaDB [(none)]> show slave status\G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: db2.example.com
                  Master_User: jf_slave
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mariadb-bin.000078
          Read_Master_Log_Pos: 376
               Relay_Log_File: db4-relay-bin.000044
                Relay_Log_Pos: 537
        Relay_Master_Log_File: mariadb-bin.000078
             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: 376
              Relay_Log_Space: 1121
              Until_Condition: None
               Until_Log_File:
                Until_Log_Pos: 0
           Master_SSL_Allowed: Yes
           Master_SSL_CA_File: /opt/mysql/ca.crt
           Master_SSL_CA_Path:
              Master_SSL_Cert: /opt/mysql/db4.example.com.crt
            Master_SSL_Cipher:
               Master_SSL_Key: /opt/mysql/db4.example.com.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_SSL_Crl: /opt/mysql/ca.crt
           Master_SSL_Crlpath:
                   Using_Gtid: No
                  Gtid_IO_Pos:
1 row in set (0.00 sec)

我在db4上的mariadb日志中看到了一些错误,但是它们与我在nagios用户数据成功复制的前3个数据库上看到的错误没什么不同。

151004 15:34:36 [Note] Error reading relay log event: slave SQL thread was killed
151004 15:34:36 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
151004 15:34:36 [Note] Slave I/O thread killed while reading event
151004 15:34:36 [Note] Slave I/O thread exiting, read up to log 'mariadb-bin.000078', position 376
151004 15:36:47 [Note] Slave SQL thread initialized, starting replication in log 'mariadb-bin.000078' at position 376, relay log './db4-relay-bin.000042' position: 537
151004 15:36:47 [Note] Slave I/O thread: connected to master 'jf_slave@db2.example.com:3306',replication started in log 'mariadb-bin.000078' at position 376
151007  4:24:12 [Note] Error reading relay log event: slave SQL thread was killed
151007  4:24:12 [ERROR] Error reading packet from server: Lost connection to MySQL server during query ( server_errno=2013)
151007  4:24:12 [Note] Slave I/O thread killed while reading event
151007  4:24:12 [Note] Slave I/O thread exiting, read up to log 'mariadb-bin.000078', position 376
151007  4:28:20 [Note] Slave SQL thread initialized, starting replication in log 'mariadb-bin.000078' at position 376, relay log './db4-relay-bin.000043' position: 537
151007  4:28:20 [Note] Slave I/O thread: connected to master 'jf_slave@db2.example.com:3306',replication started in log 'mariadb-bin.000078' at position 376

那么,当所有复制指标看起来都没问题时,为什么会出现这种数据库不一致的情况呢?为什么nagios用户不能像在前3个db上那样登录db4?

由于

1 个答案:

答案 0 :(得分:0)

因为您需要在每台服务器上的CNF文件中设置Log_slave_updates。