Amazon EC2, mysql aborts the launch because InnoDB: mmap (x bytes) failed; errno 12

I installed the micro instance server on EC2 based on what I read here

The mysql server often fails, and the third time the mysql server has left. Only displayed in logs

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 

What is failed; errno 12 failed; errno 12 ? And how can I give more space / memory or something else that is needed for this.

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

Also my `my.cnf 'looks like this:

 [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 
+88
mysql amazon-ec2
Apr 23 2018-12-12T00:
source share
8 answers

I ran into the same problem when I tried to run WordPress on a micro instance without RDS.

Adding a Swap page solved the problem for me.

You can follow this to customize the swap page:

http://www.prowebdev.us/2012/05/amazon-ec2-linux-micro-swap-space.html

If it still does not work for you, consider using RDS.

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

A link to a blog sometimes fails. I copied the content below for the record. The loan belongs to the author of the blog Pedram Moubed :

Amazon EC2 Micro Instance Swap Space - Linux

I have an instance of Amazon EC2 Linux Micro. Because Micro instances only have 613 MB of memory, MySQL crashes from time to time. After a long search about MySQL, Micro Instance, and Memory Managment, I found that there is no default SWAP space for the Micro instance. Therefore, if you want to avoid a malfunction, you may need to adjust the swap space for your micro-site. Actually, swap is best used.

The following shows how to create swap space for your Micro instance. I assume you have an AWS account with an instance of Micro.

  • Run dd if=/dev/zero of=/swapfile bs=1M count=1024
  • Run mkswap /swapfile
  • Run swapon /swapfile
  • Add this line /swapfile swap swap defaults 0 0 to /etc/fstab

Step 4 is necessary if you want to automatically include the page file after each reboot.

Some useful command related to the SWAP space:

 $ swapon -s $ free -k $ swapoff -a $ swapon -a 

Literature:

+160
Dec 22 '12 at 3:26
source share

I also had a problem with the Amazon EC2 micro instance. I tried to decrease inno_db memory usage by adding the following to /etc/my.cnf

 innodb_buffer_pool_size = 64M

This did not work, I tried to reset it to 16M, and it still did not work. Then I realized that the instance has basically zero free memory. So I tried restarting apache

 sudo system httpd restart
 sudo system mysqld restart

And it worked fine. Perhaps another solution is to configure apache to prevent that much memory.

+23
Aug 22 '12 at 16:14
source share

It looks like you are requesting 128M of memory for innodb_buffer_pool_size in the my.cfg file that you are showing in the message, but MySQL thinks you are requesting 512 M of memory:

Initialization of the buffer pool, size = 512.0M

A few lines down, the error message says that MySQL is not starting because it cannot reserve enough (512M) memory for the InnoDB buffer pool:

Fatal error: memory allocation for buffer pool cannot be allocated

This raises three questions:

  • How much memory is on your instance? Should there be enough memory to accommodate 512M InnoDB trying to grab the buffer pool, as well as everything else that MySQL allocates, plus your applications, as well as the operating system?
  • Why is InnoDB trying to take more than you think?
  • Why is MySQL rebooting?

You can answer 1.

Regarding 2., there are several different places where MySQL parameter files can be installed. Subsequently, the found files override the parameters specified in the previously found files. Cm.

http://dev.mysql.com/doc/refman/5.5/en/option-files.html

3. Problem 3 may occur due to lack of memory that occurs sometime after startup. You should see this again in the magazines, if so.

Finally, but somewhat unrelated, are you using EBS-supported instances? This is usually recommended for database servers (in fact, for any instance that prohibits special circumstances). See more about this.

stack overflow

+4
Apr 24 '12 at 22:30
source share

For me, this problem was fixed by adding swap volume to my EC2 instance. My services simply swallowed all the memory on the box and collapsed. Not what I'm used to as the administrator of RedHat / CentOS for many years - Anaconda does a lot of the work that is not in a free copy of Ubuntu EC2.

I just created a 2GB volume via the web console, attached it to my instance and made "mkswap / dev / [whatever]", edited / etc / fstab, and the failure stopped.

These instances are NOT installed as the multimedia-based installation OS that most of us are used to: it stripped without packages, there is no proper file system and things like AppArmor that cause all kinds of problems if you are not aware of it and / or do not know how to configure it.

+2
Nov 30 '12 at 1:09
source share

Use any of the following solutions:

  • Increase physical memory. Adding 1 GB of additional RAM will solve the problem.

  • Allocate SWAP space using the configuration changes below:

Config

 dd if=/dev/zero of=/extraswap bs=1024 count=512M mkswap /extraswap swapon /extraswap ## Edit the /etc/fstab, and the following entry. /extraswap none swap sw 0 0 
0
Oct 19 '15 at 5:18
source share

The problem is that the server does not have enough memory to allocate for the MySQL process. There are several solutions to this problem.

(1) Increase physical memory. Adding 1 GB of additional RAM will solve the problem. (2) Allocate SWAP space. The Digital Ocean VPS instance is not configured to use the default swap space. By allocating 512 MB of swap space, we were able to solve this problem. To add swap space to your server, follow these steps:

 ## As a root user, perform the following: # dd if=/dev/zero of=/swap.dat bs=1024 count=512M # mkswap /swap.dat # swapon /swap.dat ## Edit the /etc/fstab, and the following entry. /swap.dat none swap sw 0 0 

Reduce MySQL buffer pool size

 ## Edit /etc/my.cnf, and add the following line under the [mysqld] heading. [mysqld] innodb_buffer_pool_size=64M 

Also check the disk space. Make sure you have enough space.

 df-h 
0
Sep 08 '16 at 8:51
source share

I found the answer to this question and worked for me: https://www.digitalocean.com/community/questions/mysql-server-keeps-stopping-unexpectedly?answer=26016

you need to do both innodb_buffer_pool_size for something reasonable, like 32M on my.conf in /etc/mysql/my.cnf , and you might also need to change /etc/apache2/mods-enabled/mpm_prefork.conf to reduce the number of connections running apache;

 <IfModule mpm_prefork_module> StartServers 3 MinSpareServers 3 MaxSpareServers 5 MaxRequestWorkers 25 MaxConnectionsPerChild 0 </IfModule> 
0
May 15, '19 at 8:35
source share

EASY RESPONSE:

 * * * * * systemctl is-active --quiet mysqld || systemctl restart mysqld 

DETAILED ANSWER:

This is an important issue, especially for people who use a very small VPS, say, 1 GB of RAM or less. If MySQL shuts down, it may be due to the configuration of your server (Apache | nginx) or MySQL. DOS attacks can cause an increased surge in the use of system resources (see. Image). The end result is that the MySQL process is shut down by the kernel. For a long-term solution, take a look at optimizing your Apache or MySQL configurations.

System resources spike causing RAM spike (just before 6pm) and system resources spike causing only a CPU spike Midnight on Tue 18

There are several other discussions related to stack overflow, as well as the MySQL manual and the Percona blog:

MySQL Manual - How MySQL uses memory:

https://dev.mysql.com/doc/refman/8.0/en/memory-use.html

Percona - Recommendations for tuning the optimal use of MySQL memory:

https://www.percona.com/blog/2016/05/03/best-practices-for-configuring-optimal-mysql-memory-usage/

How to optimize MySQL performance using MySQLTuner:

https://www.linode.com/docs/databases/mysql/how-to-optimize-mysql-performance-using-mysqltuner/

Apache memory usage configuration:

https://serverfault.com/questions/254436/apache-memory-usage-optimization

Apache Performance Tuning Guide:

https://httpd.apache.org/docs/2.4/misc/perf-tuning.html

Apache server setup:

https://www.linode.com/docs/web-servers/apache-tips-and-tricks/tuning-your-apache-server/

However, as for your original question, yes, you can write a workaround that checks if the MySQL service is loaded and active, and will restart MySQL if it is not loaded and not active.

You did not mention which operating system you are using. This would help give you a specific command. I will give you an example for CentOS Linux.
Take a look at the following output from the systemctl status mysql command. At the top you can see that the service is loaded and active .

 [root@centos-mysql-demo ~]# systemctl status mysqld ● mysqld.service - MySQL Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Tue 2019-06-18 18:28:18 UTC; 924ms ago Docs: man:mysqld(8) http://dev.mysql.com/doc/refman/en/using-systemd.html Process: 3350 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid $MYSQLD_OPTS (code=exited, status=0/SUCCESS) Process: 3273 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 3353 (mysqld) CGroup: /system.slice/mysqld.service └─3353 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid Jun 18 18:28:11 centos-mysql-demo systemd[1]: Starting MySQL Server... Jun 18 18:28:18 centos-mysql-demo systemd[1]: Started MySQL Server. 

If the service is not loaded, then a command such as:

 systemctl status mysqld || systemctl restart mysqld 

will do the trick of restarting the process. You could cron that:

 * * * * * systemctl status mysqld || systemctl restart mysqld 

However, in case mysql is loaded but the service is not active , your cron will do nothing. So you should use a more detailed command such as:

* * * * * systemctl is-active --quiet mysqld || systemctl restart mysqld

In this case, if the service is loaded but inactive, for example, a state in which a DOS attack can leave the mysql service, the command will also restart mysql. Using the --quiet flag simply tells the command only to return a status code, not to display anything on the screen. If you omit the --quiet flag, you will see the status output either active or inactive .

You can also create some swap space to add more available RAM resources to your server, for example:

 sudo dd if=/dev/zero of=/swapfile count=2096 bs=1MiB chmod 600 /swapfile mkswap /swapfile swapon /swapfile swapon --show swapon --summary free -h 
0
Jun 18 '19 at 19:36
source share



All Articles