我们在 CentOS 7 上运行 LAMP 堆栈。我们启用了 SCL,但只有 PHP 和 Apache 在使用它。我们无法在测试机器上成功切换 MariaDB,因此我们从未尝试在生产中进行切换。
最近,我们遇到了更严重的数据库崩溃。崩溃和损坏是一个长期存在的问题,但这次它使我们的 wiki 离线。我们修复了 wiki 表和 MariaDB 数据库,并认为我们解决了这个问题(直到下一次)。然而,我在重新启动后注意到日志文件中有以下内容:
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
InnoDB: Database was not shut down normally!
The log sequence number in ibdata files does not match
是一个相当常见的问题,并且已经讨论过令人厌烦。但我们不应该在干净关机/重启时遇到它。(请更正)。
我做了一个实验,然后执行sudo su -
了shutdown -r now
。日志显示:
# tail /var/log/mariadb/mariadb.log
180901 23:01:26 Percona XtraDB (http://www.percona.com) 5.5.59-MariaDB-38.11 started; log sequence number 1478830786
180901 23:01:26 [Note] Plugin 'FEEDBACK' is disabled.
180901 23:01:26 [Note] Server socket created on IP: '0.0.0.0'.
180901 23:01:26 [Note] Event Scheduler: Loaded 0 events
180901 23:01:26 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.60-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server
180901 23:01:30 [ERROR] mysqld: Table './my_wiki/wikicryptopp_objectcache' is marked as crashed and should be repaired
180901 23:01:30 [Warning] Checking table: './my_wiki/wikicryptopp_objectcache'
180901 23:05:01 [ERROR] mysqld: Table './my_wiki/wikicryptopp_module_deps' is marked as crashed and should be repaired
180901 23:05:01 [Warning] Checking table: './my_wiki/wikicryptopp_module_deps'
看来 systemd 没有正确关闭数据库。(请更正)。
我搜索了 CentOS 和 Systemd 错误跟踪器,但没有找到相关问题。我希望其他人也遇到过这些问题,并能提供解决它的步骤。
如何解决 MariaDB 关闭问题?
这是我在弄清楚关机期间发生了什么时得到的结果。我不知道这是否正确(可能不正确),因为我不是 systemd 专家。
[root@ftpit ~]# find /etc -name mariadb.service
/etc/systemd/system/multi-user.target.wants/mariadb.service
[root@ftpit ~]# find /etc -name mysql.service
[root@ftpit ~]# find /opt/rh -name mariadb.service
[root@ftpit ~]# find /opt/rh -name mysql.service
进而:
# cat /etc/systemd/system/multi-user.target.wants/mariadb.service
# It's not recommended to modify this file in-place, because it will be
# overwritten during package upgrades. If you want to customize, the
# best way is to create a file "/etc/systemd/system/mariadb.service",
# containing
# .include /lib/systemd/system/mariadb.service
# ...make your changes here...
# or create a file "/etc/systemd/system/mariadb.service.d/foo.conf",
# which doesn't need to include ".include" call and which will be parsed
# after the file mariadb.service itself is parsed.
#
# For more info about custom unit files, see systemd.unit(5) or
# http://fedoraproject.org/wiki/Systemd#How_do_I_customize_a_unit_file.2F_add_a_custom_unit_file.3F
# For example, if you want to increase mariadb's open-files-limit to 10000,
# you need to increase systemd's LimitNOFILE setting, so create a file named
# "/etc/systemd/system/mariadb.service.d/limits.conf" containing:
# [Service]
# LimitNOFILE=10000
# Note: /usr/lib/... is recommended in the .include line though /lib/...
# still works.
# Don't forget to reload systemd daemon after you change unit configuration:
# root> systemctl --system daemon-reload
[Unit]
Description=MariaDB database server
After=syslog.target
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n
# Note: we set --basedir to prevent probes that might trigger SELinux alarms,
# per bug #547485
ExecStart=/usr/bin/mysqld_safe --basedir=/usr
ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID
# Give a reasonable amount of time for the server to start up/shut down
TimeoutSec=300
# Place temp files in a secure directory, not /tmp
PrivateTmp=true
[Install]
WantedBy=multi-user.target
答案1
“ibdata 文件中的日志序列号不匹配”不应该经常发生。这不太可能是 systemd 问题。我会进行完整的 mysqldump 并将其还原到一个干净的实例中,然后让它清除 innodb 差异。
注意:systemctl show mariadb.service
是显示 systemd 配置的更好方法。