为什么师父认为它是重启时的奴隶?



在一个简单的MySQL复制主从配置中,我有一个问题,主试图在重新启动时将自己连接为从。

所以当我在Master上重新启动MySQL时,我看到与同一服务器试图复制到自己相关的错误,我必须每次重新启动MySQL时手动运行mysql -e "STOP SLAVE;"

如何在主服务器上禁用从服务器?

以下是my.cnf的相关部分:

## Logging
binlog_format                   = mixed
log_bin                         = /var/log/mysql/mysql-bin.log
sync_binlog                     = 1
pid_file                        = /var/run/mysqld/mysqld.pid
log_error                       = /var/log/mysql/error.log
#general_log                     = 0
#general_log_file                = /var/log/mysql/general.log
slow_query_log                  = 1
slow_query_log_file             = /var/log/mysql/slow.log
long_query_time                 = 3
expire_logs_days                = 14
sql_mode                        = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# sql_mode                        = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
## Replication
server_id                       = 200
## Master Configuration
binlog-do-db                    = my_db_1
binlog-do-db                    = my_db_2
binlog-do-db                    = my_db_3
binlog-do-db                    = my_db_4
binlog-do-db                    = my_db_5
binlog-do-db                    = my_db_6

另外,当我运行SELECT * FROM mysql.user;时,我没有看到repl用户,据称是Master上的"从"。

BUT,我确实看到localhost有复制授权:

mysql> select Host, User, grant_priv, Repl_slave_priv, Repl_client_priv from mysql.user;
+-----------------+---------------+------------+-----------------+------------------+
| Host            | User          | grant_priv | Repl_slave_priv | Repl_client_priv |
+-----------------+---------------+------------+-----------------+------------------+
| localhost       | root          | Y          | Y               | Y                |
| localhost       | mysql.sys     | N          | N               | N                |

下面是我在重启时看到的错误示例(在Master上运行STOP SLAVE;之前):

2016-09-01T15:22:23.845505Z 384 [Note] Access denied for user 'repl'@'192.168.100.200' (using password: YES)
2016-09-01T15:22:23.845761Z 1 [ERROR] Slave I/O for channel '': error connecting to master 'repl@192.168.100.200:3306' - retry-time: 30  retries: 8, Error_code: 1045
2016-09-01T15:22:50.191636Z 0 [Note] InnoDB: page_cleaner: 1000ms intended loop took 6843ms. The settings might not be optimal. (flushed=15210 and evicted=0, during the time.)

除此之外,复制运行良好。写入主服务器的操作在真正的只读从服务器上显示无误。


完整my.cnf:

[mysql]
default_character_set           = utf8
[mysqld]
datadir                         = /var/lib/mysql
socket                          = /var/lib/mysql/mysql.sock
symbolic-links                  = 0
## Custom Configuration
skip_external_locking           = 1
skip_name_resolve
open_files_limit                = 20000
## Cache
thread_cache_size               = 16
query_cache_type                = 1
query_cache_size                = 256M
query_cache_limit               = 4M
## Per-thread Buffers
sort_buffer_size                = 32M
read_buffer_size                = 4M
read_rnd_buffer_size            = 8M
join_buffer_size                = 2M
## Temp Tables
tmp_table_size                  = 1024M
max_heap_table_size             = 1024M
## Networking
back_log                        = 250
max_connections                 = 512
max_connect_errors              = 100000
max_allowed_packet              = 128M
interactive_timeout             = 1800
wait_timeout                    = 1800
character_set_client_handshake  = FALSE
character_set_server            = utf8mb4
collation_server                = utf8mb4_unicode_ci
### Storage Engines
default_storage_engine          = InnoDB
innodb                          = FORCE
## MyISAM
key_buffer_size                 = 128M
myisam_sort_buffer_size         = 16M
## InnoDB
innodb_buffer_pool_size         = 46G
innodb_buffer_pool_instances    = 64
innodb_log_files_in_group       = 2
innodb_log_buffer_size          = 32M
innodb_log_file_size            = 64M
innodb_file_per_table           = 1
innodb_thread_concurrency       = 0
innodb_flush_log_at_trx_commit  = 1
## Logging
binlog_format                   = mixed
log_bin                         = /var/log/mysql/mysql-bin.log
sync_binlog                     = 1
pid_file                        = /var/run/mysqld/mysqld.pid
log_error                       = /var/log/mysql/error.log
#general_log                     = 0
#general_log_file                = /var/log/mysql/general.log
slow_query_log                  = 1
slow_query_log_file             = /var/log/mysql/slow.log
long_query_time                 = 3
expire_logs_days                = 14
sql_mode                        = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
# sql_mode                        = ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
## Replication
# Master Server ID:
server_id                       = 200
# Slave Server ID:
# server_id                       = 300
## Master Configuration
# Comment out on Slave
binlog-do-db                    = db_1
binlog-do-db                    = db_2
binlog-do-db                    = db_3
binlog-do-db                    = db_4
binlog-do-db                    = db_5
binlog-do-db                    = db_6
## Slave Configuration
# Uncomment the following on Slave
# relay-log                       = /var/log/mysql/mysql-relay-bin.log
# binlog-do-db                    = db_1
# binlog-do-db                    = db_2
# binlog-do-db                    = db_3
# binlog-do-db                    = db_4
# binlog-do-db                    = db_5
# binlog-do-db                    = db_6
# log_slave_updates               = 1
# read_only                       = 1
# slave_skip_errors               = 1062
[mysqld_safe]
datadir                         = /var/lib/mysql
socket                          = /var/lib/mysql/mysql.sock
symbolic-links                  = 0
pid_file                        = /var/run/mysqld/mysqld.pid
log_error                       = /var/log/mysql/error.log

:

mysql> SHOW GLOBAL VARIABLES LIKE '%master_info_repository%';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| master_info_repository | FILE  |
+------------------------+-------+

对于管理这种设置,我建议使用MHA管理器。对于这种特殊情况,您可能想要清除master_info_repository(默认位于master.info中)。此外,您可以在主主机上使用--skip-slave-start来避免故障转移后出现这种情况。

我认为您一定在主服务器上设置了主信息(可能这是从服务器,或者是从服务器刷新的)。运行

SHOW SLAVE STATUS
主机上的

。如果条目不是全部为空,那么这就是原因,并且在重新启动(没有设置skip-slave-start)时,MySQL将尝试启动从服务器。

要解决这个问题,请在主服务器上停止从服务器,如果你还没有停止从服务器,然后运行

RESET SLAVE ALL

清除主设置-假设您使用的是5.5.16或更高版本,否则请保留ALL

这可以通过另一个SHOW SLAVE STATUS来确认,它应该将所有条目显示为空。

当你现在重新启动时,从服务器将不会尝试启动。

如果您出于某种原因更喜欢保留主设置,请将skip-slave-start添加到[mysqld]下的my.cnf,然后设置将在启动时被忽略。

相关内容

  • 没有找到相关文章

最新更新