MySQL 会无缘无故地定期停止在 AWS ec2 实例上运行

MySQL 会无缘无故地定期停止在 AWS ec2 实例上运行

我在 AWS 上运行了一个开发服务器,它运行得很好,没有任何问题。最近,mysql 服务器开始定期不工作。然后我输入

service mysqld restart

会产生一条错误消息

MySQL Daemon failed to start.

现在,如果我停止实例然后启动它,然后从命令行重新启动服务器,一切都会正常工作(这很烦人,迫使我重新编辑我的区域文件,因为 IP 地址发生了变化,但我读到重新启动不会删除 IP 地址)。但是有什么线索可以说明为什么这不起作用吗?

以下是 var/log/mysqld.log 中的几行我无法理解的内容。

130613 23:12:21 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
130613 23:12:21 [Note] Plugin 'FEDERATED' is disabled.
130613 23:12:21 InnoDB: The InnoDB memory heap is disabled
130613 23:12:21 InnoDB: Mutexes and rw_locks use GCC atomic builtins
130613 23:12:21 InnoDB: Compressed tables use zlib 1.2.5
130613 23:12:21 InnoDB: Using Linux native AIO
130613 23:12:21 InnoDB: Initializing buffer pool, size = 128.0M
130613 23:12:21 InnoDB: Completed initialization of buffer pool
InnoDB: The first specified data file ./ibdata1 did not exist:
InnoDB: a new database to be created!
130613 23:12:21  InnoDB: Setting file ./ibdata1 size to 10 MB
InnoDB: Database physically writes the file full: wait...
130613 23:12:22  InnoDB: Log file ./ib_logfile0 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile0 size to 5 MB
InnoDB: Database physically writes the file full: wait...
130613 23:12:23  InnoDB: Log file ./ib_logfile1 did not exist: new to be created
InnoDB: Setting log file ./ib_logfile1 size to 5 MB
InnoDB: Database physically writes the file full: wait...
InnoDB: Doublewrite buffer not found: creating new
InnoDB: Doublewrite buffer created
InnoDB: 127 rollback segment(s) active.
InnoDB: Creating foreign key constraint system tables
InnoDB: Foreign key constraint system tables created
130613 23:12:24  InnoDB: Waiting for the background threads to start
130613 23:12:25 InnoDB: 5.5.31 started; log sequence number 0
130613 23:12:25 [Note] Server hostname (bind-address): '0.0.0.0'; port: 3306
130613 23:12:25 [Note]   - '0.0.0.0' resolves to '0.0.0.0';
130613 23:12:25 [Note] Server socket created on IP: '0.0.0.0'.
130613 23:12:25 [Note] Event Scheduler: Loaded 0 events
130613 23:12:25 [Note] /usr/libexec/mysqld: ready for connections.
Version: '5.5.31'  socket: '/var/lib/mysql/mysql.sock'  port: 3306  MySQL Community Server (GPL)
130614  6:08:52 [Note] /usr/libexec/mysqld: Normal shutdown

130614  6:08:53 [Note] Event Scheduler: Purging the queue. 0 events

我在 stackexchange 上的其他帖子中看到,有时这可能是由于磁盘大小限制造成的。df - h 说

Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1            7.9G  1.7G  6.2G  22% /
tmpfs                 298M     0  298M   0% /dev/shm

有人知道我还应该寻找什么吗?

答案1

首先,您必须备份数据库:

cp -r /var/lib/mysql /tmp/mysql_backup

然后,从中删除该文件/var/lib/mysql

rm -rf ibdata1

现在重新启动 mysql 服务器。

/etc/init.d/mysqld start

答案2

如果您使用的是微型或小型实例,运行网站的 mysql 数据库可能会对您的 VM 内存施加相当大的负载,最终导致您的 mysql 服务器不断崩溃。

考虑使用远程数据传送系统这可能会更贵,或者至少是 ec2t2.中等节省资金并且运行良好。

对于 IP,你必须分配你的实例松紧带IP 将一直保留在您的实例中,直到您摆脱它为止,只要您在使用它,就无需为 IP 付费。

答案3

如果您使用的是只有大约 1GB 内存的 t2.micro 实例,mysql 实例将被终止。如果您执行 ps -ef | grep apache,您可以看到正在运行的 apache 实例数量。大量 apache 实例将迫使服务器在内存不足时终止 mysql。

答案4

安装 monit 来监控 Apache。当负载上升时,Monit 会正常重启 Apache,一切继续正常运行。

相关内容