MariaDB 在重启后无法启动 - 可以手动启动

MariaDB 在重启后无法启动 - 可以手动启动

我有一个运行 Centos7 和 MariaDB 的 VPS。我在尝试让它在启动时启动 MariaDB 时遇到了问题,我将 MariaDB 绑定到我的 VPS 的私有地址,因为我只希望它监听该接口上的连接。它失败了,日志中显示以下内容:

170204 15:34:03 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
170204 15:34:12 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170204 15:34:13 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 784 ...
170204 15:34:13 InnoDB: The InnoDB memory heap is disabled
170204 15:34:13 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170204 15:34:13 InnoDB: Compressed tables use zlib 1.2.7
170204 15:34:13 InnoDB: Using Linux native AIO
170204 15:34:13 InnoDB: Initializing buffer pool, size = 128.0M
170204 15:34:13 InnoDB: Completed initialization of buffer pool
170204 15:34:13 InnoDB: highest supported file format is Barracuda.
170204 15:34:13  InnoDB: Waiting for the background threads to start
170204 15:34:14 Percona XtraDB (http://www.percona.com) 5.5.49-MariaDB-38.0 started; log sequence number 1597945
170204 15:34:14 [Note] Plugin 'FEEDBACK' is disabled.
170204 15:34:14 [Note] Server socket created on IP: '10.99.0.14'.
170204 15:34:14 [ERROR] Can't start server: Bind on TCP/IP port. Got error: 99: Cannot assign requested address
170204 15:34:14 [ERROR] Do you already have another mysqld server running on port: 3306 ?
170204 15:34:14 [ERROR] Aborting

170204 15:34:14  InnoDB: Starting shutdown...
170204 15:34:15  InnoDB: Shutdown completed; log sequence number 1597945
170204 15:34:15 [Note] /usr/libexec/mysqld: Shutdown complete

但是,我可以通过运行sudo systemctl start mariadb以下命令手动启动该服务:

170204 15:34:15 mysqld_safe mysqld from pid file /var/run/mariadb/mariadb.pid ended
170204 15:38:52 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
170204 15:38:52 [Note] /usr/libexec/mysqld (mysqld 5.5.52-MariaDB) starting as process 2609 ...
170204 15:38:52 InnoDB: The InnoDB memory heap is disabled
170204 15:38:52 InnoDB: Mutexes and rw_locks use GCC atomic builtins
170204 15:38:52 InnoDB: Compressed tables use zlib 1.2.7
170204 15:38:52 InnoDB: Using Linux native AIO
170204 15:38:52 InnoDB: Initializing buffer pool, size = 128.0M
170204 15:38:52 InnoDB: Completed initialization of buffer pool
170204 15:38:52 InnoDB: highest supported file format is Barracuda.
170204 15:38:52  InnoDB: Waiting for the background threads to start
170204 15:38:53 Percona XtraDB (http://www.percona.com) 5.5.49-MariaDB-38.0 started; log sequence number 1597945
170204 15:38:53 [Note] Plugin 'FEEDBACK' is disabled.
170204 15:38:53 [Note] Server socket created on IP: '10.99.0.14'.
170204 15:38:53 [Note] Event Scheduler: Loaded 0 events
170204 15:38:53 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.52-MariaDB'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MariaDB Server

我的my.cnf:

[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
# Disabling symbolic-links is recommended to prevent assorted security risks
symbolic-links=0
# Settings user and group are ignored when systemd is used.
# If you need to run mysqld under a different user or group,
# customize your systemd unit file for mariadb according to the
# instructions in http://fedoraproject.org/wiki/Systemd

bind-address    = 10.99.0.14

[mysqld_safe]
log-error=/var/log/mariadb/mariadb.log
pid-file=/var/run/mariadb/mariadb.pid

#
# include all files from the config directory
#
!includedir /etc/my.cnf.d

暂时地禁用 SELinux 以查看是否是此问题,但似乎无法解决问题。当我绑定到 0.0.0.0 时,它工作正常,但我并不特别想这样做。提前致谢。

答案1

我最终通过/usr/lib/systemd/system/mariadb.service在 unit 指令下将 network-online.target 添加到文件中来修复此问题:

[Unit]
Description=MariaDB database server
After=syslog.target
After=network-online.target

最初,它被设置为network.target。基本上,eth1 接口无法足够快地获取 IP 地址,导致 MariaDB 在启动时发出抱怨。

谢谢@nickm

答案2

就我的情况而言,从 5.5.68-MariaDB 升级到 10.5.8 后的情况如下(注意:drupal 在 RHEL7 上与 mariadb 一起运行):

sudo systemctl enable mariadb

我希望这能帮助别人

答案3

发生这种情况是因为您的 MariaDB 配置将设置bind-address为 MariaDB 启动时不在任何接口上的 IP 地址。

bind-address    = 10.99.0.14

bind-address =您可以通过不绑定到任何特定地址来解决这个问题;MariaDB 随后将在任何接口或 IP 地址上应答,即使是启动时不存在的接口或 IP 地址。通过从配置中删除所有实例来实现。

(您也可以通过让 systemd 等待启动 MariaDB,直到 IP 地址可用来解决此问题,如下所示另一个答案

相关内容