Let's Encrypt:証明書の更新(certbot-auto)

関連投稿

以前の投稿からツールが新しくなり、自動更新方法がちょっとかわったのでメモしておく。

証明書の自動更新するツールを以下からダウンロードする。中身はシェルスクリプトになっており、初回実行時に必要な(Python?)のツール類がインストールされる。インストール完了後、このツールを所定の場所にでも移動しておく。

> wget https://dl.eff.org/certbot-auto
> chmod a+x certbot-auto
> sudo ./certbot-auto
> sudo mv certbot-auto /usr/local/bin

更新方法

筆者の場合、プロキシサーバーを立てているので、このままだと更新が失敗するので、いったんプロキシサーバーを停止し、80番ポートで動作するダミーWebサーバーを起動しておく。

起動後、以下のコマンドで証明書を更新する。
ちなみに更新回数が制限があるので、--dry-runオプションで、更新前にいけそうか確認しておく。

> sudo certbot-auto renew --dry-run
:
> sudo certbot-auto renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log

-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/hoge.com.conf
-------------------------------------------------------------------------------
Cert is due for renewal, auto-renewing...
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for hoge.com
http-01 challenge for xx.hoge.com
http-01 challenge for yy.hoge.com
http-01 challenge for zz.hoge.com
Waiting for verification...
Cleaning up challenges

-------------------------------------------------------------------------------
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/hoge.com/fullchain.pem
-------------------------------------------------------------------------------

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/hoge.com/fullchain.pem (success)

成功したら、ダミーWebサーバーを停止し、他のHTTPサーバーを全て再起動する。(証明書の再読み込みが必要なので)

更新とサブドメイン追加について

更新ついでまたはその逆で運用中にサブドメインを追加したくなった場合、上記の方法だけでは、既存のサブドメインの更新しかできない。

やりかたはあるかもしれないが、結局のところ再度作成コマンドを実行することで成功している。

下記の例では、a.hoge.com,b.hoge.comの運用中にc.hoge.comを追加したケース。また、実行時にcertbotが外部からほんとにサイトが存在するかチェックするので、一時的に80番ポートのダミーサーバーを起動して(本稼動サイトは一旦停止)以下のコマンドを実行する。

> sudo certbot-auto certonly --force-renewal --webroot -w /home/web/dummysrv/public -d a.hoge.com -d b.hoge.com -d c.hoge.com  -m hoge@hoge.com
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator webroot, Installer None
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for a.hoge.com
http-01 challenge for b.hoge.com
http-01 challenge for c.hoge.com
Using the webroot path /home/web/dummysrv/public for all unmatched domains.
Waiting for verification...
Cleaning up challenges

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
:

その後、ダミーサーバーを停止して、本稼動するサイトを起動すればめでたく更新となる。注意点としては、止めなくても良いサーバーがあっても再起動しないと証明書が最ロードされないので注意する。

-->