海外格安サーバーvultrでswap領域の拡張
mysqlがすぐに落ちるようになったのでsyslogを確認したところ「Cannot allocate memory for the buffer pool 」というエラーが発生していた。
単純に innodb_buffer_pool_size
の値を上げただけでは起動すらできなかったので、きちんと調べてみた。
まずはswapから。
参考: Setup Swap File on Linux - Vultr.com
参考: https://tech.librastudio.co.jp/index.php/2018/05/22/post-1891/
スワップが存在しないことを確認 - Step 1: Verify that swap does not exist
$ free -h total used free shared buff/cache available Mem: 481M 130M 129M 120M 220M 217M Swap: 0 0 0
Swapセクションに0が表示されている
swapファイルの作成 - Step 2: Create swap file
RAM 512MBなので1G(*)にしてみた。
(*) スワップ領域のサイズの求め方はawsのページに載っていました。
$ sudo mkdir /var/lib/swap $ cd /var/lib/swap/ $ sudo fallocate -l 1G swapfile
swapファイルを有効化 - Step 3: Activate the swap file
確認
$ ls -lh swapfile -rw-r--r-- 1 root root 1.0G Jun 18 21:48 swapfile
権限変更
$ sudo chmod 600 swapfile
スワップファイルを設定する
$ sudo mkswap swapfile Setting up swapspace version 1, size = 1024 MiB (1073737728 bytes) no label, UUID=e119cd0b-dda
スワップON - Step 4: Turn swap on
$ sudo swapon swapfile $ free -h total used free shared buff/cache available Mem: 481M 132M 125M 120M 223M 216M Swap: 1.0G 0B 1.0G
Swapの値が1Gとなっているので、正常にセットアップされています!
次回はmysql側の設定です。 swapの設定をしたので解決できる。。。はず!