![Mysql 用不同的參數隨機重啟?](https://rvso.com/image/756238/Mysql%20%E7%94%A8%E4%B8%8D%E5%90%8C%E7%9A%84%E5%8F%83%E6%95%B8%E9%9A%A8%E6%A9%9F%E9%87%8D%E5%95%9F%EF%BC%9F.png)
我面臨著一個相當奇怪的問題,我不知道該如何理解它。看起來 mysqld 程序在 mysql systemd 服務已經運行後,是由 systemd 以外的其他東西以不同的參數啟動的。這會導致 mysql 伺服器宕機並且新進程變得無回應。
當透過 systemd 啟動時:
/usr/sbin/mysqld
什麼時候開始的?
mysqld --user=mysql --init-file=/var/lib/mysql-files/tmp.Ld6xyAe3qb --socket=/tmp/tmp.obBArlPCj2/mysqld.sock --pid-file=/tmp/tmp.obBArlPCj2/mysqld.pid
目前尚不清楚 mysql 為何被重啟、由誰重啟以及新參數從何而來。
/var/lib/mysql-files/tmp.Ld6xyAe3qb
(這是上面提供的初始化文件)包含以下文字:
USE mysql;
ALTER USER 'root'@'localhost' IDENTIFIED WITH 'auth_socket';
SHUTDOWN;
我在日誌中唯一能看到的是:
2020-08-08T06:57:31.123013Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.0.21-0ubuntu0.20.04.4).
... [group replication, InnoDB, normal logs] ...
2020-08-08T06:57:49.954754Z 8 [System] [MY-013172] [Server] Received SHUTDOWN from user boot. Shutting down mysqld (Version: 8.0.21-0ubuntu0.20.04.4).
第一條日誌隨機發生;在它之前沒有任何東西表明內存或任何其他類型的錯誤(我可以看到)。第二次關閉似乎來自 init 檔案。然而,更令人困惑的方面是boot
系統上或mysql中沒有使用者。
唯一使用 mysql 的服務是 OpenStack Keystone,用於 Swift 物件存儲,沒有其他 OpenStack 服務。
據我所知,沒有其他 cron 或 systemd 服務引用 mysql,但我對該測試並不積極。命令是:
systemctl list-units --all --no-legend | awk '{print $1}' | xargs -n1 systemctl cat 2>/dev/null | grep mysql
給:
After=postgresql.service mysql.service keystone.service rabbitmq-server.service ntp.service network-online.target local-fs.target remote-fs.target
# /lib/systemd/system/mysql.service
User=mysql
Group=mysql
PIDFile=/run/mysqld/mysqld.pid
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
ExecStart=/usr/sbin/mysqld
RuntimeDirectory=mysqld
第一行來自/lib/systemd/system/cinder-volume.service
,需要刪除,但我不認為與此問題相關,因為問題發生在從未安裝過 cinder 的伺服器上
此問題發生在為群組複製設定的 4 台伺服器上。
# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04 LTS
Release: 20.04
Codename: focal
# mysql --version
mysql Ver 8.0.21-0ubuntu0.20.04.4 for Linux on x86_64 ((Ubuntu))
# cat /etc/mysql/mysql.conf.d/mysqld.cnf
#
# The MySQL database server configuration file.
#
# One can use all long options that the program supports.
# Run program with --help to get a list of available options and with
# --print-defaults to see which it would actually understand and use.
#
# For explanations see
# http://dev.mysql.com/doc/mysql/en/server-system-variables.html
# Here is entries for some specific programs
# The following values assume you have at least 32M ram
[mysqld]
log-error-verbosity = 5
#
# * Basic Settings
#
user = mysql
# pid-file = /var/run/mysqld/mysqld.pid
# socket = /var/run/mysqld/mysqld.sock
# port = 3306
# datadir = /var/lib/mysql
# If MySQL is running as a replication slave, this should be
# changed. Ref https://dev.mysql.com/doc/refman/8.0/en/server-system-variables.html#sysvar_tmpdir
# tmpdir = /tmp
#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address = 0.0.0.0
#
# * Fine Tuning
#
key_buffer_size = 16M
# max_allowed_packet = 64M
# thread_stack = 256K
# thread_cache_size = -1
# This replaces the startup script and checks MyISAM tables if needed
# the first time they are touched
myisam-recover-options = BACKUP
# max_connections = 151
# table_open_cache = 4000
#
# * Logging and Replication
#
# Both location gets rotated by the cronjob.
#
# Log all queries
# Be aware that this log type is a performance killer.
# general_log_file = /var/log/mysql/query.log
# general_log = 1
#
# Error log - should be very few entries.
#
log_error = /var/log/mysql/error.log
#
# Here you can see queries with especially long duration
# slow_query_log = 1
# slow_query_log_file = /var/log/mysql/mysql-slow.log
# long_query_time = 2
# log-queries-not-using-indexes
#
# The following can be used as easy to replay backup logs or for replication.
# note: if you are setting up a replication slave, see README.Debian about
# other settings you may need to change.
# server-id = 1
# log_bin = /var/log/mysql/mysql-bin.log
# binlog_expire_logs_seconds = 2592000
max_binlog_size = 100M
# binlog_do_db = include_database_name
# binlog_ignore_db = include_database_name
# disable non innodb storage engines for group replication
# https://dev.mysql.com/doc/refman/8.0/en/group-replication-configuring-instances.html
disabled_storage_engines="MyISAM,BLACKHOLE,FEDERATED,ARCHIVE,MEMORY"
# use native password auth
default_authentication_plugin=mysql_native_password
# replication framework settings
server_id = 1
gtid_mode = ON
enforce_gtid_consistency = ON
log_bin = binlog
log_slave_updates = ON
binlog_format = ROW
master_info_repository = TABLE
relay_log_info_repository = TABLE
binlog_checksum = NONE
# group replication settings
plugin_load_add = 'group_replication.so'
plugin-load-add = 'mysql_clone.so'
group_replication_group_name = "xxx"
group_replication_start_on_boot = on
group_replication_local_address = "xxx:33061"
group_replication_ip_whitelist="xxx"
group_replication_group_seeds = "xxx:33061"
group_replication_bootstrap_group = off
group_replication_enforce_update_everywhere_checks = off
group_replication_single_primary_mode = off
## tls
# required encrypted remote connections
# require_secure_transport = ON
tls_version=TLSv1.3
ssl_ca = "/etc/mysql/certs/eons.dev.pem"
ssl_cert = "/etc/mysql/certs/skyrim-mysql.pem"
ssl_key = "/etc/mysql/certs/skyrim-mysql.key"
ssl_cipher = "DHE-RSA-AES256-SHA"
##ssl_crl = "crl-server-revoked.crl"
##ssl_crlpath = "/.../crl_directory"
mysqlx_ssl_ca = "/etc/mysql/certs/eons.dev.pem"
mysqlx_ssl_cert = "/etc/mysql/certs/skyrim-mysql.pem"
mysqlx_ssl_key = "/etc/mysql/certs/skyrim-mysql.key"
mysqlx_ssl_cipher = "DHE-RSA-AES256-SHA"
# group replication tls
group_replication_ssl_mode = REQUIRED
group_replication_recovery_use_ssl = on
group_replication_recovery_ssl_ca = "/etc/mysql/certs/eons.dev.pem"
group_replication_recovery_ssl_cert = "/etc/mysql/certs/skyrim-mysql.pem"
group_replication_recovery_ssl_key = "/etc/mysql/certs/skyrim-mysql.key"
group_replication_recovery_ssl_cipher = "DHE-RSA-AES256-SHA"