我们是一个免费/开源项目。我们无法确定为什么 CentOS 7 上的 MariaDB 5.5.58 没有启动。在我们启用 CentOS Software Collections (SCL)并执行 MediaWiki 升级后,出现了启动问题。
缺乏有用的错误信息使我们难以解决问题。我发现 CentOS 的问题 9519,/usr/libexec/mariadb-prepare-db-dir 失败(并且Mariadb 不会启动 - 在执行生成步骤时失败),但权限/
似乎没问题(见下文)。我们还有 Red Hat 的Issue 1082018 中讨论的 PID 文件,systemctl start mariadb.service 不会启动。
/usr/libexec/mariadb-prepare-db-dir
以 root 身份手动运行的结果set -x
如下图所示。我不知道 systemd 是如何运行它的(我还没有找到打印信息的命令)。
我们租用我们的虚拟机,所以没有dmesg
或syslog
检查。它是空的。
如果有人可以提供有关故障原因的更多信息或排除故障的其他步骤,我们将不胜感激。
MariaDB 会议
# grep -v '#' /etc/my.cnf
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
symbolic-links=0
[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid
!includedir /etc/my.cnf.d
接着:
# echo "" > /var/log/mariadb/mariadb.log
其他目录
# ls -al /
total 64
dr-xr-xr-x 20 root root 4096 Dec 23 15:46 .
dr-xr-xr-x 20 root root 4096 Dec 23 15:46 ..
# ls -al /var/run/mariadb/
total 0
drwxr-xr-x 2 mysql mysql 40 Dec 23 15:46 .
drwxr-xr-x 26 root root 680 Dec 23 18:26 ..
数据目录
# ls -al /var/lib/mysql
total 35060
drwxr-xr-x 5 mysql mysql 4096 Dec 23 15:45 .
drwxr-xr-x 30 root root 4096 Dec 23 18:52 ..
-rw-rw---- 1 mysql mysql 16384 Dec 23 15:45 aria_log.00000001
-rw-rw---- 1 mysql mysql 52 Dec 23 15:45 aria_log_control
-rw-rw---- 1 mysql mysql 35651584 Dec 23 15:45 ibdata1
-rw-rw---- 1 mysql mysql 5242880 Dec 23 15:45 ib_logfile0
-rw-rw---- 1 mysql mysql 5242880 Dec 23 15:31 ib_logfile1
drwx------ 2 mysql mysql 4096 Sep 18 2016 mysql
drwx------ 2 mysql mysql 16384 Dec 23 01:14 my_wiki
drwx------ 2 mysql mysql 4096 Sep 18 2016 performance_schema
尝试开始
# ls /usr/libexec/mariadb-prepare-db-dir
/usr/libexec/mariadb-prepare-db-dir
# systemctl start mariadb.service
Job for mariadb.service failed because the control process exited with error code.
See "systemctl status mariadb.service" and "journalctl -xe" for details.
mariadb.log
# cat /var/log/mariadb/mariadb.log
#
系统控制状态
# systemctl -l status mariadb.service
● mariadb.service - MariaDB database server
Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Sat 2017-12-23 18:29:28 EST; 23s ago
Process: 14537 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=1/FAILURE)
Dec 23 18:29:28 ftpit systemd[1]: Starting MariaDB database server...
Dec 23 18:29:28 ftpit systemd[1]: mariadb.service: control process exited, code=exited status=1
Dec 23 18:29:28 ftpit systemd[1]: Failed to start MariaDB database server.
Dec 23 18:29:28 ftpit systemd[1]: Unit mariadb.service entered failed state.
Dec 23 18:29:28 ftpit systemd[1]: mariadb.service failed.
Oct 27 19:05:23 ftpit systemd[1]: Stopping MariaDB database server...
Oct 27 19:05:28 ftpit systemd[1]: Stopped MariaDB database server.
Nov 16 12:48:44 ftpit systemd[1]: Stopping MariaDB database server...
Nov 16 12:48:54 ftpit systemd[1]: Stopped MariaDB database server.
journalctl -xe
# journalctl -xe
-- Subject: Unit sysinit.target has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sysinit.target has finished shutting down.
Nov 16 12:48:57 ftpit systemd[1]: Stopping System Initialization.
-- Subject: Unit sysinit.target has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit sysinit.target has begun shutting down.
Nov 16 12:48:57 ftpit systemd[1]: Stopped target Swap.
-- Subject: Unit swap.target has finished shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit swap.target has finished shutting down.
Nov 16 12:48:57 ftpit systemd[1]: Stopping Swap.
-- Subject: Unit swap.target has begun shutting down
-- Defined-By: systemd
-- Support: http://lists.freedesktop.org/mailman/listinfo/systemd-devel
--
-- Unit swap.target has begun shutting down.
这是/usr/libexec/mariadb-prepare-db-dir
手动运行并set -x
添加到脚本的结果。老实说,我不知道这是否是预期的。
# /usr/libexec/mariadb-prepare-db-dir
+ get_mysql_option mysqld datadir /var/lib/mysql
+ '[' 3 -ne 3 ']'
++ tail -n 1
++ sed -n 's/^--datadir=//p'
++ /usr/bin/my_print_defaults mysqld
+ result=/var/lib/mysql
+ '[' -z /var/lib/mysql ']'
+ datadir=/var/lib/mysql
+ get_mysql_option mysqld_safe log-error /var/log/mariadb/mariadb.log
+ '[' 3 -ne 3 ']'
++ sed -n 's/^--log-error=//p'
++ tail -n 1
++ /usr/bin/my_print_defaults mysqld_safe
+ result=/var/log/mariadb/mariadb.log
+ '[' -z /var/log/mariadb/mariadb.log ']'
+ errlogfile=/var/log/mariadb/mariadb.log
+ get_mysql_option mysqld socket /var/lib/mysql/mysql.sock
+ '[' 3 -ne 3 ']'
++ tail -n 1
++ sed -n 's/^--socket=//p'
++ /usr/bin/my_print_defaults mysqld
+ result=/var/lib/mysql/mysql.sock
+ '[' -z /var/lib/mysql/mysql.sock ']'
+ socketfile=/var/lib/mysql/mysql.sock
+ SERVICE_NAME=
+ '[' x = x ']'
+ SERVICE_NAME=mysqld.service
++ sed 's/^User=//'
++ systemctl show -p User mysqld.service
+ myuser=
+ '[' x = x ']'
+ myuser=mysql
++ sed 's/^Group=//'
++ systemctl show -p Group mysqld.service
+ mygroup=
+ '[' x = x ']'
+ mygroup=mysql
++ dirname /var/log/mariadb/mariadb.log
+ '[' '!' -e /var/log/mariadb/mariadb.log -a '!' -h /var/log/mariadb/mariadb.log -a x/var/log/mariadb = x/var/log ']'
++ dirname /var/log/mariadb/mariadb.log
+ errlogdir=/var/log/mariadb
+ '[' -d /var/log/mariadb ']'
+ '[' -e /var/log/mariadb/mariadb.log -a '!' -w /var/log/mariadb/mariadb.log ']'
+ fuser /var/lib/mysql/mysql.sock
+ export LC_ALL=C
+ LC_ALL=C
+ should_initialize /var/lib/mysql
++ list_datadir /var/lib/mysql
++ grep -v -e '^lost+found$' -e '\.err$' -e '^.bash_history$'
++ ls -1A /var/lib/mysql
+ test -z 'aria_log.00000001
aria_log_control
ib_logfile0
ib_logfile1
ibdata1
my_wiki
mysql
performance_schema'
+ '[' -d /var/lib/mysql/mysql/ ']'
+ echo 'Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.'
Database MariaDB is probably initialized in /var/lib/mysql already, nothing is done.
++ basename /usr/libexec/mariadb-prepare-db-dir
+ echo 'If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.'
If this is not the case, make sure the /var/lib/mysql is empty before running mariadb-prepare-db-dir.
+ exit 0
我们找到了问题的原因。当虚拟机内存不足时,Linux OOM 杀手似乎正在杀死该服务。
加重情节包括 GoDaddy 提供的虚拟机。这台机器有 1 GB 的 RAM,没有虚拟内存。我们无法升级 RAM,也无法配置交换文件。
我们尝试为 Apache 和 PHP 调整 VM 性能,包括 Web 服务器参数和缓存。不幸的是,我们都不是该领域的专家,因此我们不确定这些更改的效果如何。事实上,鉴于问题再次出现,我们的尝试似乎失败了。
我们将提供一个 cron 作业,它 (1) 如果服务未运行,则重新启动它;(2) 在重新启动时修复数据库。(2) 很重要,因为我们有时会在杀死后看到损坏的表。
对于那些处于类似情况的人,这里是 CentOS7 和 MySQL 的命令:
检查服务状态
systemctl status mariadb.service
修复数据库
mysqlcheck --all-databases --auto-repair --user=XXX --password=YYY
这是脚本:
和:
以下是我们确定原因的方法。我们最初错过了它,因为我们的第一步是反弹服务器以恢复服务。后来我们会检查
dmesg
,它会是空的。我们没有在其他日志中找到此信息。这个问题可能已经解决了,但我仍然为此提供了另一种解决方案,以防万一有人来寻找答案。
如果在卸载任何以前安装的版本后完成安装,启动 mariadb 服务器有时会产生问题。
这是您需要清理数据时的特定错误-
在这种情况下,请尝试从“/var/lib/mysql”中删除所有文件
这将清除所有旧数据并启动 mariadb。