LoginSignup
86
59

More than 5 years have passed since last update.

AmazonAWSで、MySQL がよく落ちる? そんな時はSWAP領域をチェック!

Last updated at Posted at 2016-03-11

Amazon AWSにてt1microサービスを利用していますが、MySQLがよく落ちるんです。

それで、ログを確認したところ。。。

[Note] InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12
[ERROR] InnoDB: Cannot allocate memory for the buffer pool
[ERROR] Plugin 'InnoDB' init function returned error.
[ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed.
[ERROR] Unknown/unsupported storage engine: InnoDB
[ERROR] Aborting

メモリを確認すると、Swapが0でした。。。

[root@ip-xxx ~]# free
             total       used       free     shared    buffers     cached
Mem:       1018504     949092      69412      31980      28740     695944
-/+ buffers/cache:     224408     794096
Swap:            0          0          0

要するに、AWSのt1microサービスだと、Swap領域が無かった訳です。
やることは、Swap領域を作成してあげれば、問題解決ですね。

まずは、ddコマンドで指定サイズの空のファイルを作成します。
とりあえず、サイズは1024MBで。

[root@ip-xxx ~]# dd if=/dev/zero of=/swapfile bs=1M count=1024

1024+0 records in
1024+0 records out
1073741824 bytes (1.1 GB) copied, 14.8488 s, 72.3 MB/s

mkswapで、スワップ領域を作成します。

[root@ip-xxx ~]# mkswap /swapfile
mkswap: /swapfile: warning: don't erase bootbits sectors
        on whole disk. Use -f to force.
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx

swaponコマンドで、スワップ領域を有効にします。

[root@ip-xxx ~]# swapon /swapfile

freeコマンドで、確認すると、Swap領域が作成されました。

[root@ip-xxx ~]# free
             total       used       free     shared    buffers     cached
Mem:       1018504     950208      68296      31980      28772     697060
-/+ buffers/cache:     224376     794128
Swap:      1048572          0    1048572

あとは、MySQLを再起動するだけです。

[root@ip-xxx ~]# service mysqld restart
mysqld を停止中:                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]

上記設定のままだと、再起動した時にマウントされないので、 /etc/fstab に以下の1行を追加。

/swapfile    swap       swap    defaults        0   0

お疲れ様でした。

86
59
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
86
59