0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Google Compute Engineグループで定期的にインスタンスを再作成する

Posted at

Google Compute Engineグループでインスタンス定期的に再起動して以下のメリットを得る方法です。

  • インスタンスなんらかの状態が溜まっておきる問題を予防できる
    • disk full
    • メモリ full
    • なんらかのインスタンスの状態不整合
    • サーバー落ちてるけどヘルスチェックで検知できていないなど

方法

1. 起動後一定時間後にメンテナンス状態に入らせる

一定時間ごとにサーバーをメンテナンス状態に入らせます。使うフレームワークによって方法が違うと思います。railsでは、turnout gem + cronとかでできました。

2. ヘルスチェックの設定

Google Compute Engineグループの設定でヘルスチェックを設定して、メンテナンス状態に入ったインスタンスを置き換えるようにします。

付帯する問題

なぜか、インスタンスを再作成すると、Cloud SQLへのコネクションが残って、最大接続数に達してしまう問題がありました。

以下のWITH inactive_connections AS (から始まる方法を、Sidekiqで定期的に実行したら解決できました。

0
0
0

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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?