ずっと放置していたvultrサーバーでまたmysqlが動かなくなっていた件
ブログ同様、しばらくサーバー管理を放置しておりました。。。
let's encryptの証明書の更新が切れていたり、
無料ドメイン(freenom)も更新が切れていたり、、、
久しぶりにSSHでログインして再設定を進めておりました。
いろいろつまづいたことがあったので、誰かのお役に立てれば・・・書き残しておきます。
続きを読むinnodb_buffer_pool_sizeが原因でmysqlが落ちる
前回の続きでswap領域は設定したのでmysql側の設定
mysqlの設定
mysqlの設定ファイル my.cnf
を編集、バッファプールサイズを512MBにしてみた
$ sudo vim /etc/mysql/my.cnf --- # バッファプールサイズの指定 innodb_buffer_pool_size=512M
mysql を再起動
下記コマンドでmysqlを再起動、何も出力されなければOK
何か出たら上記のmy.cnfに追加したもののタイポ、または他に原因がある
$ sudo service mysql restart
swap領域を使っているのかの確認
オプションt で合計も出せる
$ free -h -t total used free shared buff/cache available Mem: 481M 205M 81M 40M 194M 223M Swap: 1.0G 298M 725M Total: 1.5G 503M 806M
まとめ
swapの設定をしてからmysqlが突然停止することはなくなったようだ。
原因がわからずmysqlを入れ直したり、botアクセスを抑制したり試行錯誤したがやっぱりmysqlが落ちるということを繰り返していたここ1週間。syslog見れば一発だったのかなーと思いつつ解決したので良しとする。
いろいろ試すうちにmysqlデータが壊れてしまったことが一番痛い。。。
結論、開発環境用(重要ではないサーバー)でもDBのバックアップは取りましょう(T-T)
(めんどくさいですけどね)
海外格安サーバー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の設定をしたので解決できる。。。はず!
Let's encryptのワイルドカード証明書更新
取得済み証明書の情報を確認する
certbot-auto certificates
コマンドを使用する
$ sudo certbot-auto certificates Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Found the following certs: Certificate Name: exapmle-apple.jp Domains: *.exapmle-apple.jp Expiry Date: 2019-08-07 07:57:20+00:00 (VALID: 89 days) Certificate Path: /etc/letsencrypt/live/exapmle-apple.jp/fullchain.pem Private Key Path: /etc/letsencrypt/live/exapmle-apple.jp/privkey.pem Certificate Name: exapmle-orange.jp Domains: exapmle-orange.jp Expiry Date: 2019-06-23 11:37:42+00:00 (VALID: 45 days) Certificate Path: /etc/letsencrypt/live/exapmle-orange.jp/fullchain.pem Private Key Path: /etc/letsencrypt/live/exapmle-orange.jp/privkey.pem Certificate Name: p2.exapmle-peach.jp Domains: p2.exapmle-peach.jp Expiry Date: 2019-06-29 11:45:17+00:00 (VALID: 51 days) Certificate Path: /etc/letsencrypt/live/p2.exapmle-peach.jp/fullchain.pem Private Key Path: /etc/letsencrypt/live/p2.exapmle-peach.jp/privkey.pem Certificate Name: exapmle-peach.jp Domains: *.exapmle-peach.jp Expiry Date: 2019-08-07 08:00:53+00:00 (VALID: 89 days) Certificate Path: /etc/letsencrypt/live/exapmle-peach.jp/fullchain.pem Private Key Path: /etc/letsencrypt/live/exapmle-peach.jp/privkey.pem
取得済みのドメインと有効期限、各ファイルの場所を出力してくれます
ワイルドカード証明書の更新
- 手動でないと更新されないようです。
$ sudo certbot-auto certonly --server https://acme-v02.api.letsencrypt.org/directory --manual --preferred-challenges dns --domain *.exapmle-peach.jp --agree-tos -m <メールアドレス> Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator manual, Installer None Cert is due for renewal, auto-renewing... Renewing an existing certificate Performing the following challenges: dns-01 challenge for exapmle-peach.jp - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - NOTE: The IP of this machine will be publicly logged as having requested this certificate. If you're running certbot in manual mode on a machine that is not your server, please ensure you're okay with that. Are you OK with your IP being logged? - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - (Y)es/(N)o: Y - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Please deploy a DNS TXT record under the name _acme-challenge.exapmle-peach.jp with the following value: weOTD24vGNTrKabWGwh7orHwN4xiepacrRl2603s Before continuing, verify the record is deployed. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Press Enter to Continue Waiting for verification... Cleaning up challenges IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/exapmle-peach.jp/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/exapmle-peach.jp/privkey.pem Your cert will expire on 2019-08-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
TXT レコードに weOTD24vGNTrKabWGwh7orHwN4xiepacrRl2603s
を設定することで対象サーバーであることを確認できます。