You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Certbot在CentOS 7定时任务中频繁因主机名不匹配失败,手动执行需两次才成功

Certbot在CentOS 7定时任务中频繁因主机名不匹配失败,手动执行需两次才成功

最近遇到个头疼的问题:我在CentOS 7上用Certbot自动续期SSL证书好几年了,一直靠每日定时任务跑,结果最近每次域名到续期时间,定时任务就报错:

Failed to renew certificate renewthisdomain.com with error: hostname 'acme-v02.api.letsencrypt.org' doesn't match 'renewthisdomain.com'

所有续期都失败,对应的证书路径是/etc/letsencrypt/live/renewthisdomain.com/fullchain.pem。更奇怪的是,我SSH到服务器手动执行certbot renew,第一次肯定会报同样的错,第二次执行却总能成功。

从错误信息看明显是DNS解析出问题了,但我自己在同一台机器上部署了主从DNS服务器,其他业务的DNS解析都正常,实在摸不着头脑。后来翻/var/log/letsencrypt/letsencrypt.log,发现了相关的OCSP查询错误:

2023-04-08 11:32:34,314:DEBUG:certbot.ocsp:Error while running openssl ocsp -no_nonce -issuer /etc/letsencrypt/archive/domain.com-0001/chain20.pem -cert /etc/letsencrypt/archive/domain.com-0001/cert20.pem -CAfile /etc/letsencrypt/archive/domain.com-0001/chain20.pem -verify_other /etc/letsencrypt/archive/domain.com-0001/chain20.pem -trust_other -timeout 10 -header Host r3.o.lencr.org -url http://r3.o.lencr.org.
Error querying OCSP responder
2023-04-08 11:32:34,314:INFO:certbot.ocsp:OCSP check failed for /etc/letsencrypt/archive/domain.com-0001/cert20.pem (are we offline?)
2023-04-08 11:32:34,316:INFO:certbot._internal.renewal:Cert not yet due for renewal

折腾了一阵后终于找到根源:

  • 2023-04-20 初步排查结果:CentOS 7的NetworkManager是罪魁祸首!它会偷偷覆盖/etc/resolv.conf文件。我当时手动停止并禁用了NetworkManager服务,之后resolv.conf里的DNS条目就一直保持我在/etc/sysconfig/network-scripts/配置文件里设置的内容,再也没收到续期失败的通知。当时打算观察一段时间再回来确认。
  • 2023-05-06 最终确认:没错,自从禁用NetworkManager后,这个问题彻底解决了,再也没出现过。

如果你也遇到同样的问题,直接执行这两条命令停止并禁用NetworkManager就行:

systemctl stop NetworkManager
systemctl disable NetworkManager

备注:内容来源于stack exchange,提问作者Shovas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.22 14:35:34