本文介绍了Amazon EC2,mysql 中止启动,因为 InnoDB: mmap (x bytes) failed;错误 12的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个基于 EC2 的 微型 实例服务器 这个

I have a micro instance server on EC2 based this

mysql 服务器频繁出现故障,第三次 mysql 服务器不见了.日志只显示

mysql server fails frequently and for the third time mysql server is gone. The logs only shows

120423 09:13:38 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
120423 09:14:27 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
120423  9:14:27 [Note] Plugin 'FEDERATED' is disabled.
120423  9:14:27 InnoDB: The InnoDB memory heap is disabled
120423  9:14:27 InnoDB: Mutexes and rw_locks use GCC atomic builtins
120423  9:14:27 InnoDB: Compressed tables use zlib 1.2.3
120423  9:14:27 InnoDB: Using Linux native AIO
120423  9:14:27 InnoDB: Initializing buffer pool, size = 512.0M
InnoDB: mmap(549453824 bytes) failed; errno 12
120423  9:14:27 InnoDB: Completed initialization of buffer pool
120423  9:14:27 InnoDB: Fatal error: cannot allocate memory for the buffer pool
120423  9:14:27 [ERROR] Plugin 'InnoDB' init function returned error.
120423  9:14:27 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
120423  9:14:27 [ERROR] Unknown/unsupported storage engine: InnoDB
120423  9:14:27 [ERROR] Aborting

什么是真正的失败了;错误12?我怎么能提供更多的空间/内存或任何需要的东西来解决这个问题.

What is really failed; errno 12? And how could I give more space/memory or whatever needed to make this fixed.

我每次都通过重新启动整个系统并删除所有日志并重新启动 mysql 服务器来解决此问题.但我知道我的配置有问题.

I fix this each time by rebooting the whole system and deleting all logs and restart the mysql server. But I know something is wrong with my configuration.

还有我的my.cnf"如下:

Also my `my.cnf' is like below :

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


innodb_buffer_pool_size         = 512M


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

推荐答案

当我尝试在没有 RDS 的微实例上运行 wordpress 时遇到了同样的问题.

I met the same problem when I tried to run a wordpress on my micro instance without RDS.

添加交换页面为我解决了问题.

Adding a Swap page solved the problem for me.

您可以按照以下步骤设置交换空间.

You can follow steps below to setup the swap space.

如果它仍然不适合您,请考虑使用 RDS 服务.

If it still doesn't work for you, consider using the RDS service.

==============================================

===============================================

我复制了博客的内容以作记录.归功于博客作者 pmoubed:

I copied the content of the blog for the record. Credit goes to the blog author pmoubed:

Amazon EC2 微型实例交换空间 - Linux

Amazon EC2 Micro Instance Swap Space - Linux

我有一个 Amazon EC2 Linux Micro 实例.由于微型实例只有 613MB 的内存,MySQL 时不时崩溃.经过对 MySQL、微实例和内存管理的长时间搜索,我发现微实例没有默认的 SWAP 空间.因此,如果您想避免崩溃,您可能需要为您的微型实例设置交换空间.实际上,启用交换会更好地提高性能.

I have a Amazon EC2 Linux Micro instance. Since Micro instances have only 613MB of memory, MySQL crashed every now and then. After a long search about MySQL, Micro Instance and Memory Managment I found out there is no default SWAP space for Micro instance. So if you want to avoid the crash you may need to setup a swap space for your micro instance. Actually performance wise is better to enable swap.

以下步骤显示了如何为您的 Micro 实例创建交换空间.我假设您有一个运行 Micro 实例的 AWS 账户.

Steps below show how to make a swap space for your Micro instance. I assume you have AWS Account with a Micro instance running.

  1. 运行 dd if=/dev/zero of=/swapfile bs=1M count=1024
  2. 运行 mkswap/swapfile
  3. 运行swapon/swapfile
  4. 将这一行 /swapfile swap swap defaults 0 0 添加到 /etc/fstab

如果您想在每次重启后自动启用交换文件,则需要执行第 4 步.

Step 4 is needed if you would like to automatically enable swap file after each reboot.

一些与 SWAP 空间相关的有用命令:

Some useful command related to SWAP space:

$ swapon -s   
$ free -k

$ swapoff -a
$ swapon  -a

参考文献:

  1. http://www.thegeekstuff.com/2010/08/how-to-add-swap-space/
  2. http://cloudstory.in/2012/02/getting-the-best-out-of-amazon-ec2-micro-instances/
  3. http://cloudstory.in/2012/02/adding-swap-space-to-amazon-ec2-linux-micro-instance-to-increase-the-performance/
  4. http://aws.amazon.com/ec2/instance-types/

这篇关于Amazon EC2,mysql 中止启动,因为 InnoDB: mmap (x bytes) failed;错误 12的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!