Alan Hou的个人博客

MariaDB内存溢出导致服务自动停止

最近公司一个网站一个月内出现过几次网站无法访问的问题,都是数据库的问题

Error establishing a database connection

这个网站是构建在CentOS 7上的Wordpress,这本身并没有问题。数据库使用的是默认的MariaDB,查看状态处于停止状态,启动服务则可正常访问。查看历史记录并没有对数据库服务被误停止这样的操作。

而通过journalctl -u mariadb发现了问题

May 23 22:35:38 iZ23l4d00udZ mysqld_safe[9510]: /usr/bin/mysqld_safe: line 183:  9827 Killed                  nohup /usr/libexec/mysqld --basedir=/usr --datadi
May 23 22:35:40 iZ23l4d00udZ mysqld_safe[9510]: 160523 22:35:40 mysqld_safe Number of processes running now: 0
May 23 22:35:40 iZ23l4d00udZ mysqld_safe[9510]: 160523 22:35:40 mysqld_safe mysqld restarted
May 23 22:35:50 iZ23l4d00udZ mysqld_safe[9510]: 160523 22:35:50 mysqld_safe mysqld from pid file /var/lib/mysql/iZ23l4d00udZ.pid ended
May 24 10:29:56 iZ23l4d00udZ systemd[1]: Starting MariaDB database server...
May 24 10:29:56 iZ23l4d00udZ mysqld_safe[9150]: 160524 10:29:56 mysqld_safe Logging to '/var/lib/mysql/iZ23l4d00udZ.err'.
May 24 10:29:56 iZ23l4d00udZ mysqld_safe[9150]: 160524 10:29:56 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
May 24 10:29:59 iZ23l4d00udZ systemd[1]: Started MariaDB database server.

很明显错误日志写入了/var/lib/mysql/iZ23l4d00udZ.err文件,进一步查看

160523 22:35:42 [ERROR] Plugin 'InnoDB' init function returned error.
160523 22:35:42 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
160523 22:35:42 [ERROR] mysqld: Out of memory (Needed 128917504 bytes)
160523 22:35:42 [ERROR] mysqld: Out of memory (Needed 96681984 bytes)
160523 22:35:42 [ERROR] mysqld: Out of memory (Needed 72499200 bytes)
160523 22:35:43 [Note] Plugin 'FEEDBACK' is disabled.
160523 22:35:48 [ERROR] Unknown/unsupported storage engine: InnoDB
160523 22:35:49 [ERROR] Aborting

160523 22:35:50 [Note] /usr/libexec/mysqld: Shutdown complete

160523 22:35:50 mysqld_safe mysqld from pid file /var/lib/mysql/iZ23l4d00udZ.pid ended

可以看出服务由于内存溢出(Out of memory,简称OOM)而被关闭,这可能与配置文件中innodb_buffer_pool_size的配置以及内存本身占用都存在着关系。

Alan目前还没有好的解决方案,所以暂时在crontab中添加了一段每分钟对服务状态进行检查,若出现问题则重新启动数据库服务

* * * * * systemctl status mariadb.service || systemctl start mariadb.service
退出移动版