简单介绍一下背景,几周前我在墨尔本买了一台新的 CentOS 专用服务器,然而除了我遇到的攻击者数量之外,MySQL 数据库或正在使用的软件似乎也存在问题,因为它不断崩溃和干涸。
我查看了日志,没有发现它崩溃的任何原因,但我想知道是否有人可以帮助我解决这个问题。
日志文件的最后一部分:
150512 06:15:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150512 06:20:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150512 6:20:02 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150512 6:20:02 [Note] Plugin 'FEDERATED' is disabled.
150512 6:20:02 InnoDB: The InnoDB memory heap is disabled
150512 6:20:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150512 6:20:02 InnoDB: Compressed tables use zlib 1.2.3
150512 6:20:02 InnoDB: Using Linux native AIO
150512 6:20:02 InnoDB: Initializing buffer pool, size = 128.0M
150512 6:20:02 InnoDB: Completed initialization of buffer pool
150512 6:20:02 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
150512 6:20:02 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
150512 06:20:02 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150512 06:25:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150512 6:25:02 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150512 6:25:02 [Note] Plugin 'FEDERATED' is disabled.
150512 6:25:02 InnoDB: The InnoDB memory heap is disabled
150512 6:25:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150512 6:25:02 InnoDB: Compressed tables use zlib 1.2.3
150512 6:25:02 InnoDB: Using Linux native AIO
150512 6:25:02 InnoDB: Initializing buffer pool, size = 128.0M
150512 6:25:02 InnoDB: Completed initialization of buffer pool
150512 6:25:02 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
150512 6:25:02 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
150512 06:25:03 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150512 06:30:01 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150512 6:30:01 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150512 6:30:01 [Note] Plugin 'FEDERATED' is disabled.
150512 6:30:01 InnoDB: The InnoDB memory heap is disabled
150512 6:30:01 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150512 6:30:01 InnoDB: Compressed tables use zlib 1.2.3
150512 6:30:01 InnoDB: Using Linux native AIO
150512 6:30:01 InnoDB: Initializing buffer pool, size = 128.0M
150512 6:30:01 InnoDB: Completed initialization of buffer pool
150512 6:30:01 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
150512 6:30:01 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
150512 6:30:01 InnoDB: Waiting for the background threads to start
150512 6:30:02 InnoDB: 5.5.41 started; log sequence number 68534366
150512 6:30:02 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
150512 6:30:02 [Note] - '0.0.0.0' resolves to '0.0.0.0';
150512 6:30:02 [Note] Server socket created on IP: '0.0.0.0'.
150512 6:30:02 [Note] Event Scheduler: Loaded 0 events
150512 6:30:02 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.41' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL Community Server (GPL) by Remi
150512 06:42:37 mysqld_safe Number of processes running now: 0
150512 06:42:37 mysqld_safe mysqld restarted
150512 6:42:37 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150512 6:42:37 [Note] Plugin 'FEDERATED' is disabled.
150512 6:42:37 InnoDB: The InnoDB memory heap is disabled
150512 6:42:37 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150512 6:42:37 InnoDB: Compressed tables use zlib 1.2.3
150512 6:42:37 InnoDB: Using Linux native AIO
150512 6:42:37 InnoDB: Initializing buffer pool, size = 128.0M
150512 6:42:37 InnoDB: Completed initialization of buffer pool
150512 6:42:37 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
150512 6:42:37 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
150512 6:42:37 InnoDB: Waiting for the background threads to start
150512 06:42:37 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
150512 06:45:02 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
150512 6:45:02 [Warning] Using unique option prefix key_buffer instead of key_buffer_size is deprecated and will be removed in a future release. Please use the full name instead.
150512 6:45:02 [Note] Plugin 'FEDERATED' is disabled.
150512 6:45:02 InnoDB: The InnoDB memory heap is disabled
150512 6:45:02 InnoDB: Mutexes and rw_locks use GCC atomic builtins
150512 6:45:02 InnoDB: Compressed tables use zlib 1.2.3
150512 6:45:02 InnoDB: Using Linux native AIO
150512 6:45:02 InnoDB: Initializing buffer pool, size = 128.0M
150512 6:45:02 InnoDB: Completed initialization of buffer pool
150512 6:45:02 InnoDB: highest supported file format is Barracuda.
InnoDB: The log sequence number in ibdata files does not match
InnoDB: the log sequence number in the ib_logfiles!
150512 6:45:02 InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery.
InnoDB: Reading tablespace information from the .ibd files...
InnoDB: Restoring possible half-written data pages from the doublewrite
InnoDB: buffer...
150512 6:45:02 InnoDB: Waiting for the background threads to start
150512 6:45:03 InnoDB: 5.5.41 started; log sequence number 68578838
150512 6:45:03 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
150512 6:45:03 [Note] - '0.0.0.0' resolves to '0.0.0.0';
150512 6:45:03 [Note] Server socket created on IP: '0.0.0.0'.
150512 6:45:03 [Note] Event Scheduler: Loaded 0 events
150512 6:45:03 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.41' socket: '/var/lib/mysql/mysql.sock' port: 3306 MySQL \
服务器正在运行以下内容:
CentOS 6 vestaCP MYSQL 5.5.4 邮件服务器
答案1
InnoDB: Database was not shut down normally!
InnoDB: Starting crash recovery
每当数据库崩溃时,我们都会遇到这种情况。Innodb 机制会尝试自发恢复。使用innodb_force_recovery强制启动 InnoDB 存储引擎
如果这种情况经常发生,请同时检查是否有任何
cron
或任何logrotation
(/etc/logrotate.d/mysql)被触发。检查内存是否不足。如果 Apache 或其他进程也在同一台服务器上运行,则可能需要更多内存。检查交换的情况
cat /proc/swaps
考虑添加交换在这种情况下
如果您重新启动 MySQL,
innodb_force_recovery
则转储损坏的数据库。mysqldump -u root -p –all-databases > all_dbs.sql
转储后,关闭 MySQL,并从 /var/lib/mysql/ 目录中移出 ib* 文件。
mkdir /var/lib/ib_files/ mv /var/lib/mysql/ib* /var/lib/ib_files/
然后从 /etc/my.cnf 中删除“innodb_force_recovery”并启动 MySQL。检查 mysqld.log 是否有任何错误。一旦 MySQL 干净启动,就可以从转储中恢复数据库
mysql -u root -p < all_dbs.sql
恢复完成后,运行数据库修复以确保一切完好无损:
mysqlcheck –all-databases –repair
修复完成后,再次重启mysql
service mysql restart
答案2
您的日志似乎已损坏。请尝试通过移开现有 ib_logfile 并重新启动 MySQL 来重新创建 InnoDB 日志文件。如果此方法无效,则可能是数据损坏。
答案3
这是一个老问题,但答案对其他人可能有用......
MySQL/MariaDB“突然”崩溃的一个常见原因是内核 OOM 杀手- 基本上,如果机器的 RAM 不足,内核就会终止最耗费 RAM 的进程。
内核 OOM 终止程序是部分可配置的,因此应该能够“保护”重要进程。然而,真正的解决方案是了解为什么机器面临内存不足的情况;最常见的原因是:
- 没有配置交换空间或者配置的交换空间不足;
- 某些应用程序出现内存泄漏;
- 配置错误的数据库(例如:InnoDB 缓冲区太大);
- 对于实际工作负载来说内存太少。