如何验证Certbot对免费Let's Encrypt证书的续期是否会成功

如何验证Certbot对免费Let's Encrypt证书的续期是否会成功,可以分解成2个问题,1.验证定时任务是否存在。 2.验证续期操作是否能成功

验证定时任务是否存在

1
2
3
4
5
6
7
8
root@localhost:~# sudo systemctl status certbot.timer
● certbot.timer - Run certbot twice daily
     Loaded: loaded (/lib/systemd/system/certbot.timer; enabled; vendor preset: enabled)
     Active: active (waiting) since Wed 2022-12-07 02:08:51 UTC; 22h ago
    Trigger: Thu 2022-12-08 04:56:59 UTC; 3h 49min left
   Triggers: ● certbot.service

Dec 07 02:08:51 localhost systemd[1]: Started Run certbot twice daily.

如果存在上述定时任务,则定时是成功的。
在较新的版本中定时任务是在安装时自动设置的,无需手工设置。

验证续期操作是否能成功

使用certbot renew命令验证,执行以后会验证所有certbot管理的域名

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
root@localhost:~# sudo certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/abc.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for ijoke.fun and abc.com and www.abc.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/knightli.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for knightli.com and www.knightli.com

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all simulated renewals succeeded: 
  /etc/letsencrypt/live/abc.com/fullchain.pem (success)
  /etc/letsencrypt/live/knightli.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

看到all simulated renewals succeeded说明都能成功

常见的不成功的例子

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
root@localhost:/# sudo certbot renew --dry-run
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/abc.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for abc.com and www.abc.com
Failed to renew certificate abc.com with error: Could not bind TCP port 80 becau
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/knightli.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Simulating renewal of an existing certificate for knightli.com and www.knightli.com
Failed to renew certificate knightli.com with error: Could not bind TCP port 80 because it is already in use by another process on this system (such as a web server). Please stop the program in question and then try again.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
All simulated renewals failed. The following certificates could not be renewed:
  /etc/letsencrypt/live/abc.com/fullchain.pem (failure)
  /etc/letsencrypt/live/knightli.com/fullchain.pem (failure)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
2 renew failure(s), 0 parse failure(s)
Ask for help or search for solutions at https://community.letsencrypt.org. See the logfile /var/log/letsencrypt/letsencrypt.log or re-run Certbot with -v for more details.

以上是不成功的例子,不成功的原因是当时申请证书时使用的是standalone方式,在申请和续期时certbot都会自己搭建一个http服务,如果这是你的服务器运行了其他http服务器,就会导致失败。

这是需要修改certbot的配置文件就可以成功

在目录/etc/letsencrypt/renewal/下找到你的域名对应的配置文件

1
2
3
4
5
root@localhost:~# ll /etc/letsencrypt/renewal
drwxr-xr-x 2 root root 4096 Dec  7 02:59 ./
drwxr-xr-x 9 root root 4096 Dec  8 01:09 ../
-rw-r--r-- 1 root root  530 Dec  7 02:59 abc.com.conf
-rw-r--r-- 1 root root  545 Dec  7 02:59 knightli.com.conf

修改对应的配置文件

1
2
3
4
5
6
原有
authenticator = standalone

修改成(适用于nginx服务器的情形)
authenticator = nginx
installer = nginx
记录并分享
Built with Hugo
主题 StackJimmy 设计