let’s encryptの定期更新

Arch Linuxでは、標準ではcronがインストールされていない。
cronieまたはfcronをインストールすればよいが、標準にしたがって、timerで、let’s encryptの定期更新。

# cd /etc/systemd/system
# vi certbot.timer
[Unit]
Description=Run certbot on 2nd day bimonthly
[Timer]
OnCalendar=*-01,03,05,07,09,11-02 03:00:00
RandomizedDelaySec=60min
Persistent=true
[Install]
WantedBy=timers.target

# vi certbot.service
[Unit]
Description=bimonthly certbot
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot renew –quiet –agree-tos –max-log-backups 9

# systemctl start certbot.timer
# systemctl status certbot.timer
# systemctl enable certbot.timer
# systemctl list-timers –all

ログは、logrotateではなく自前で管理しており、 /var/log/letsencrypt/に1000までログができるので、オプションで制限する。
ヘルプ表示は、certbot -h all。
強制実行で確認する。
# systemctl start certbot.service

3か月前には更新できたcertbot renewで以下のエラーが発生する。
Attempting to renew cert (domain.name.com ) from /etc/letsencrypt/renewal/domain.name.com.conf produced an unexpected error: Unable to find a virtual host listening on port 80 which is currently needed for Certbot to prove to the CA that you control your domain. Please add a virtual host for port 80.. Skipping.
All renewal attempts failed. The following certs could not be renewed:
/etc/letsencrypt/live/domain.name.com/fullchain.pem (failure)

解決のために、/etc/httpd/conf/extra/httpd-vhosts.confを編集して、以下を追加。
<VirtualHost:80>
ServerName domain.name.com
</VirtualHost>

/etc/httpd/conf/httpd.confを編集して、rewriteモジュールをコメントアウト。
LoadModule rewrite_module modules/mod_rewrite.so

# httpd -t ; syntax check
# systemctl restart httpd
# certbot renew –dry-run; 動作確認
# stemctl daemon-reload; ファイルを修正した場合

いつの間にか期限前30日だと更新されない設定になったので、2か月ごとの更新だと期限切れになるので、強制更新に変更。
/etc/systemd/system/certbot.serviceを変更。
ExecStart=/usr/bin/certbot renew –force-renewal –quiet –agree-tos –max-log-backups 9

いつのまにか、エラーでApacheが止まっていた。そのため証明書の期限切れになっている。
/etc/httpd/conf/httpd.confに追加したphp拡張が原因であった。7を削れば動くようだ。
LoadModule php7_module modules/libphp7.so
Include conf/extra/php7_module.conf
その後に、certbot renewで証明書を更新。

証明書は/etc/letsencrypt/live/domainにあり、リンク先はarchive/domainにある。
利用するためには、ディレクトリのパーミッションを755に変更して、ファイルも644に変更しなければならないことがあるが、セキュリティ的には問題があるような気がする。

rsaからeccへの変更もできる。
# certbot renew –key-type ecdsa –force-renewal


コメント