使用certbot创建证书后,证书的有效期是3个月。
按照官网的描述,在生成证书之后,certbot会定期更新证书,无需开发者手动更新。
在网上查询,其并未在crontab中创建定时任务,而是创建systemd服务以定期更新证书。
查询系统服务,可发现certbot已创建证书定时更新服务。
查看证书更新服务,具体如下所示:
root@VM-16-14-ubuntu:/etc/systemd/system# cat snap.certbot.renew.service
[Unit]
# Auto-generated, DO NOT EDIT
Description=Service for snap application certbot.renew
Requires=snap-certbot-4325.mount
Wants=network.target
After=snap-certbot-4325.mount network.target snapd.apparmor.service
X-Snappy=yes
[Service]
EnvironmentFile=-/etc/environment
ExecStart=/usr/bin/snap run --timer="00:00~24:00/2" certbot.renew
SyslogIdentifier=certbot.renew
Restart=no
WorkingDirectory=/var/snap/certbot/4325
TimeoutStopSec=30
Type=oneshot
查看证书定时器配置,具体如下:
root@VM-16-14-ubuntu:/etc/systemd/system# cat snap.certbot.renew.timer
[Unit]
# Auto-generated, DO NOT EDIT
Description=Timer renew for snap application certbot.renew
Requires=snap-certbot-4325.mount
After=snap-certbot-4325.mount
X-Snappy=yes
[Timer]
Unit=snap.certbot.renew.service
OnCalendar=*-*-* 01:51
OnCalendar=*-*-* 15:08
[Install]
WantedBy=timers.target
可以通过以下命令,查看certbot的更新次数,具体如下所示:
grep -c skipped /var/log/letsencrypt/letsencrypt.log