今や当たり前のように使われるようになったSSL証明書について、新規取得や更新の際には結構な手間がかかります。これを認証局によっては自動で更新することが可能であり、その際に使われるツールがACMEクライアントツール(certbot)です。これは証明書管理プロトコルで自動更新を可能とするツールです。
Apacheを前提にインストールから自動更新までの設定を記載します。まずcertbotをインストールします。
# dnf install certbot python3-certbot-apache <省略> Created symlink /etc/systemd/system/timers.target.wants/certbot-renew.timer → /usr/lib/systemd/system/certbot-renew.timer. Certbot auto renewal timer is not started by default. Run 'systemctl start certbot-renew.timer' to enable automatic renewals. <省略> |
証明書更新コマンドがcronではなく、certbot-renewで定期的に動くのですが、上の指定のファイルの中身は下記のようになっており、12時間ごとに動作するというものです。
# more /usr/lib/systemd/system/certbot-renew.timer [Unit] Description=This is the timer to set the schedule for automated renewals [Timer] OnCalendar=*-*-* 00/12:00:00 RandomizedDelaySec=12hours Persistent=true [Install] WantedBy=timers.target |
これを先立って行っておきます。上のcertbot-renewをenable/startする前に動作設定でDEPLOY_HOOKパラメータを設定しstartします。DEPLOY_HOOKは証明書が更新された場合に実行するコマンドでapacheを再起動します。
# vi /etc/sysconfig/certbot <省略> DEPLOY_HOOK="--deploy-hook 'systemctl restart httpd'" <省略> # systemctl enable certbot-renew.timer # systemctl start certbot-renew.timer # systemctl list-timers NEXT LEFT LAST PASSED UNIT ACTIVATES> Fri 2025-11-21 11:29:20 JST 49min left Fri 2025-11-21 10:28:58 JST 10min ago dnf-makecache.timer dnf-makec> Fri 2025-11-21 15:47:59 JST 5h 8min left Thu 2025-11-20 15:47:59 JST 18h ago systemd-tmpfiles-clean.timer systemd-t> Fri 2025-11-21 18:01:26 JST 7h left Fri 2025-11-21 07:31:37 JST 3h 7min ago certbot-renew.timer certbot-r> Sat 2025-11-22 00:00:00 JST 13h left Fri 2025-11-21 00:00:02 JST 10h ago logrotate.timer logrotate> Sat 2025-11-22 00:00:00 JST 13h left Fri 2025-11-21 00:00:02 JST 10h ago mlocate-updatedb.timer mlocate-u> |
次に証明書を新たに発行するために以下コマンドでACME管理サーバに登録を行います。
# certbot register --debug -vvv --server 'https://example.com/xxxx/' --eab-hmac-key xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx --eab-kid xxxxxxxxx --agree-tos -m mail@example.com --no-eff-email |
管理サーバから証明書を取得するのですが、少し前準備が必要です。
※Apacheの設定で以下を追加 # vi /etc/httpd/conf/httpd.conf NameVirtualHost *:80 <VirtualHost *:80> DocumentRoot /var/www/html ServerName inventory.itc.kagawa-u.ac.jp </VirtualHost> ※外部から以下のファイルにアクセスできるようにしておく必要あり。 # mkdir /var/www/html/.well-known/ # mkdir /var/www/html/.well-known/acme-challenge # echo HELLO > /var/www/html/.well-known/acme-challenge/index.txt |
これで以下のコマンドで証明書の取得を行います。
# certbot run -d example.com --key-type rsa --server 'https://example.com/xxxx/' Saving debug log to /var/log/letsencrypt/letsencrypt.log Requesting a certificate for example.com Successfully received certificate. Certificate is saved at: /etc/letsencrypt/live/example.com/fullchain.pem Key is saved at: /etc/letsencrypt/live/example.com/privkey.pem This certificate expires on 2026-02-10. These files will be updated when the certificate renews. Certbot has set up a scheduled task to automatically renew this certificate in the background. Deploying certificate Successfully deployed certificate for example.com to /etc/httpd/conf.d/ssl.conf Congratulations! You have successfully enabled HTTPS on https://example.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 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 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
/etc/letsencrypt/live/配下に証明書や鍵などが保存され、apacheの設定も自動で書き換わりますので、httpdを再起動して完了です。
# systemctl restart httpd |