Amazon EC2 の t1.microインスタンスでMySQLがよく落ちる
EC2 の t1.microインスタンスにてWordPressを複数たててると、まーよくMySQLが落ちます。
しまいには起動もしなくなるので、MySQLのログを見てみます。
130629 5:46:48 InnoDB: Initializing buffer pool, size = 128.0M InnoDB: mmap(137363456 bytes) failed; errno 12 130629 5:46:48 InnoDB: Completed initialization of buffer pool 130629 5:46:48 InnoDB: Fatal error: cannot allocate memory for the buffer pool 130629 5:46:48 [ERROR] Plugin 'InnoDB' init function returned error. 130629 5:46:48 [ERROR] Plugin 'InnoDB' registration as a STORAGE ENGINE failed. 130629 5:46:48 [ERROR] Unknown/unsupported storage engine: InnoDB 130629 5:46:48 [ERROR] Aborting
という感じでバッファが足りないと起こられてました。
問題のメモリをfreeで確認してみます。
$ free total used free shared buffers cached Mem: 608476 565044 43432 0 1284 53996 -/+ buffers/cache: 509764 98712 Swap: 0 0 0
えっ(;゚д゚) Swapゼロ。
t1.microインスタンスには613MBのメモリしか無い上にSwap領域も無いみたいなのでSwap領域を作ってあげると良いみたいですね。
$ sudo dd if=/dev/zero of=/swapfile bs=1M count=1024 1024+0 records in 1024+0 records out 1073741824 bytes (1.1 GB) copied, 32.7992 s, 32.7 MB/s $ sudo 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=219ec0fb-4c67-449b-a7bb-c082971b68d2 $ sudo swapon /swapfile $ free total used free shared buffers cached Mem: 608476 601432 7044 0 824 88752 -/+ buffers/cache: 511856 96620 Swap: 1048572 0 1048572
うむ、これで安心ですね!