记一次由内存不足引起的MYSQL停止故障

记一次由内存不足引起的MYSQL停止故障

我的一台服务器刚进行了迁移,从独立服务器迁移到了腾讯云,奇怪的是,每隔一周左右,会发生一次MYSQL莫名其妙停止服务的情况,重启服务器之后正常。

根据监控日志,找到服务停止时间附近的错误日志,发现如下:

171112 7:59:05 [Note] Plugin ‘FEDERATED’ is disabled.
171112 7:59:05 InnoDB: The InnoDB memory heap is disabled
171112 7:59:05 InnoDB: Mutexes and rw_locks use GCC atomic builtins
171112 7:59:05 InnoDB: Compressed tables use zlib 1.2.3
171112 7:59:05 InnoDB: Using Linux native AIO
171112 7:59:05 InnoDB: Initializing buffer pool, size = 256.0M
171112 7:59:05 InnoDB: Completed initialization of buffer pool
171112 7:59:05 InnoDB: highest supported file format is Barracuda.
171112 7:59:05 InnoDB: Waiting for the background threads to start
171112 7:59:06 InnoDB: 5.5.57 started; log sequence number 1595675
171112 7:59:06 [Note] Recovering after a crash using mysql-bin
171112 7:59:06 [Note] Starting crash recovery…
171112 7:59:06 [Note] Crash recovery finished.
171112 7:59:06 [Note] Server hostname (bind-address): ‘0.0.0.0’; port: 3306
171112 7:59:06 [Note] – ‘0.0.0.0’ resolves to ‘0.0.0.0’;
171112 7:59:06 [Note] Server socket created on IP: ‘0.0.0.0’.
171112 7:59:07 [Note] Event Scheduler: Loaded 0 events
171112 7:59:07 [Note] /www/server/mysql/bin/mysqld: ready for connections.
Version: ‘5.5.57-log’ socket: ‘/tmp/mysql.sock’ port: 3306 Source distribution
171112 8:13:05 [Note] Plugin ‘FEDERATED’ is disabled.
171112 8:13:06 InnoDB: The InnoDB memory heap is disabled
171112 8:13:06 InnoDB: Mutexes and rw_locks use GCC atomic builtins
171112 8:13:06 InnoDB: Compressed tables use zlib 1.2.3
171112 8:13:06 InnoDB: Using Linux native AIO
171112 8:13:06 InnoDB: Initializing buffer pool, size = 256.0M
InnoDB: mmap(274726912 bytes) failed; errno 12
171112 8:13:06 InnoDB: Completed initialization of buffer pool
171112 8:13:06 InnoDB: Fatal error: cannot allocate memory for the buffer pool
171112 8:13:06 [ERROR] Plugin ‘InnoDB’ init function returned error.
171112 8:13:06 [ERROR] Plugin ‘InnoDB’ registration as a STORAGE ENGINE failed.
171112 8:13:06 [ERROR] Unknown/unsupported storage engine: InnoDB
171112 8:13:06 [ERROR] Aborting

171112 8:13:06 [Note] /www/server/mysql/bin/mysqld: Shutdown complete

一开始便沿着Plugin ‘FEDERATED’ is disabled.这个信息去查,找到很多资料说是因为没有设置tmpdir的原因,但想了想,应该跟这个没有关系,于是继续找。

后来看到这里,才发现问题mmap(274726912 bytes) failed; errno 12

后面紧接着几句cannot allocate memeory for the buffer pool无法分配内存给buffer pool,内存不足了?

由于我已经重启服务器了,所以没法看到当时的内存占用情况。然后就想,服务器的变化,之前是4G的独立服务器,现在是4G内存的云服务器,按理说应该不会有问题,腾讯云的云主机内存也不会超售。

然后在腾讯云的公告里乱翻,发现一则“关于新购买Linux服务器不再提供SWAP盘的通知”,然后赶紧执行一下free -m看了一下,发现果然swap分区为0

然后按照

https://cloud.tencent.com/document/product/362/3597

这个说明分配了swap分区,恢复正常了。(文中xxx替换到你想分配到的目录,我替换到了/mnt/swap下,LABEL=xxx这里不用管,直接写/mnt/swap即可)

 

发表评论

电子邮件地址不会被公开。 必填项已用*标注