letsencrypt证书自动续期问题

官方建议一天两次

0 */12 * * * certbot renew --quiet --renew-hook "/etc/init.d/nginx reload"

官方原话
Note:
if you're setting up a cron or systemd job, we recommend running it twice per day (it won't do anything until your certificates are due for renewal or revoked, but running it regularly would give your site a chance of staying online in case a Let's Encrypt-initiated revocation happened for some reason). Please select a random minute within the hour for your renewal tasks.

为什么不是90天或者5天,因为哪天重启服务器,这个crontab就会向后又延长90天导致失效
--renew-hook这个选项在证书续期成功的时候会重新载入nginx配置,如果不加就需要手动载入或者手动重启nginx,不然的话虽然续期成功了nginx没加进来也会提示过期


最新发现设置成5天是可以的,通过查看日志文件/var/log/letsencrypt发现,续期命令检测到续期时间小于30天时,会重新请求生成新证书,部分日志文件如下

2017-02-04 04:30:02,138:DEBUG:certbot.main:Root logging level set at 30
2017-02-04 04:30:02,138:INFO:certbot.main:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2017-02-04 04:30:02,138:DEBUG:certbot.main:certbot version: 0.9.3
2017-02-04 04:30:02,138:DEBUG:certbot.main:Arguments: ['--quiet', '--renew-hook', '/etc/init.d/nginx reload']
2017-02-04 04:30:02,138:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#webroot,PluginEntryPoint#null,PluginEntryPoint#manual,PluginEntryPoint#standalone)
2017-02-04 04:30:02,150:DEBUG:certbot.storage:Should renew, less than 30 days before certificate expiry 2017-03-06 04:03:00 UTC.
2017-02-04 04:30:02,150:INFO:certbot.renewal:Cert is due for renewal, auto-renewing...
2017-02-04 04:30:02,153:DEBUG:certbot.plugins.selection:Requested authenticator webroot and installer None
2017-02-04 04:30:02,154:DEBUG:certbot.plugins.selection:Single candidate plugin: * webroot
Description: Place files in webroot directory
Interfaces: IAuthenticator, IPlugin
Entry point: webroot = certbot.plugins.webroot:Authenticator
Initialized: <certbot.plugins.webroot.Authenticator object at 0x1fe8c50>
Prep: True



很多人会遇到的一个问题,crontab是不是执行的问题
建议搞个1分钟打印时间的放crontab里,这是个人感觉最有效的方法
*/1 * * * * echo "$(date)" >>/var/log/datecron.txt

查看
cat /var/log/datecron.txt


crontab 相关命令
cat /var/log/cron #查看crontab日志
crontab -l #查看crontab列表
crontab -e #编辑crontab列表
systemctl status crond.service #查看crontab服务状态
systemctl restart crond.service #重启crontab

certbot renew --quiet和certbot renew区别
前一个命令不输出内容到控制台和生成日志,后一个会输出内容到控制台和生成日志
日志文件在/var/log/letsencrypt/letsencrypt.log
如果证书没有过期,那么证书不会更新
没有过期执行更新命令控制台内容如下
[root@centos7 ~]# certbot renew
Saving debug log to /var/log/letsencrypt/letsencrypt.log


-------------------------------------------------------------------------------
Processing /etc/letsencrypt/renewal/www.vvvtimes.com.conf
-------------------------------------------------------------------------------
Cert not yet due for renewal


The following certs are not due for renewal yet:
  /etc/letsencrypt/live/www.vvvtimes.com/fullchain.pem (skipped)
No renewals were attempted.

日志内容如下
[root@centos7 ~]# cat /var/log/letsencrypt/letsencrypt.log
2016-12-06 00:18:48,448:DEBUG:certbot.main:Root logging level set at 20
2016-12-06 00:18:48,449:INFO:certbot.main:Saving debug log to /var/log/letsencrypt/letsencrypt.log
2016-12-06 00:18:48,449:DEBUG:certbot.main:certbot version: 0.9.3
2016-12-06 00:18:48,449:DEBUG:certbot.main:Arguments: []
2016-12-06 00:18:48,449:DEBUG:certbot.main:Discovered plugins: PluginsRegistry(PluginEntryPoint#webroot,PluginEntryPoint#null,PluginEntryPoint#manual,PluginEntryPoint#standalone)
2016-12-06 00:18:48,461:INFO:certbot.renewal:Cert not yet due for renewal
2016-12-06 00:18:48,461:DEBUG:certbot.renewal:no renewal failures

这个日志不是追加的,而是每条命令生成一个,上面的时间是UTC时间


为了能更快的看到效果使用吊销命令试一下( 不用试了,没有用


吊销和安装(这两个命令说明文档太少,不确定下面的命令是否能用)
certbot revoke --cert-path cert.pem
certbot install --key-path privkey.pem --cert-path cert.pem

注意:吊销和安装命令是一对,和续期命令renew没有关系,renew只判断pem的有效期范围,超过范围才会去请求新的证书。官方文档中说吊销和过期使用renew命令都会生成证书,但实际上吊销后使用renew命令并不能生成新的证书


certbot renew --renew-hook "/etc/init.d/nginx reload"
发现吊销之后的原来的证书还能用。。。这算什么吊销。。。


/etc/letsencrypt/live/www.vvvtimes.com/这里有4个pem
cert.pem #公钥
privkey.pem #私钥
chain.pem #中间证书链
fullchain.pem #全证书链

/etc/letsencrypt/live/www.vvvtimes.com/ 这里的pem实际指向 /etc/letsencrypt/archive/www.vvvtimes.com/的pem


把4个pem全吊销了,install和renew都不行,pem也不让删,这个吊销实际上是个残次品
好像还有证书请求频率的限制,暂时不折腾了。


附:证书请求频率限制: https://letsencrypt.org/docs/rate-limits/



### Let's Encrypt 证书自动续期配置方法 Let’s Encrypt 提供的 SSL/TLS 证书的有效期限仅为 90 天,这一设计旨在推动用户采用自动化的方式完成证书续期操作[^1]。为了简化此过程并减少手动干预的需求,可以利用 Certbot 工具来实现证书自动续期功能。 #### 安装 Certbot Certbot 是一个由 EFF 开发的强大工具,用于管理 Let’s Encrypt 的证书生命周期,包括申请、部署和续期等功能[^3]。以下是安装 Certbot 的基本步骤: 对于 Ubuntu 或 Debian 系统: ```bash sudo apt update sudo apt install certbot python3-certbot-apache ``` 对于 CentOS/RHEL 系统: ```bash sudo yum install epel-release sudo yum install certbot python3-certbot-nginx ``` 如果使用的是其他操作系统或者 Web 服务器环境,请查阅官方文档获取具体指导。 #### 设置定时任务以执行自动续期 一旦成功安装了 Certbot 并初次获得了有效的 SSL 证书之后,下一步就是安排定期运行 `certbot renew` 命令的任务计划程序。通常推荐通过 cron 来调度这些作业。 编辑用户的 crontab 文件: ```bash crontab -e ``` 添加如下条目以便每天凌晨两点尝试一次证书更新(实际时间可以根据需求调整): ```cron 0 2 * * * /usr/bin/certbot renew --quiet && systemctl reload apache2 ``` 上述命令中的 `/usr/bin/certbot` 路径可能依据不同发行版有所变化;另外注意最后部分重启服务的动作应匹配所使用的Web Server类型,比如这里针对 Apache 使用了 `systemctl reload apache2` ,如果是 Nginx 则改为相应的指令如 `systemctl reload nginx` [^4]. 当 Cronjob 执行时它会静默处理所有即将到期的证书,并且只有那些距离失效日期少于30天的才会真正触发重新签发动作[^2]. #### 测试自动续订流程 可以通过模拟提前过期的方式来验证整个机制是否正常运作: ```bash sudo certbot renew --dry-run ``` 如果没有错误消息返回,则说明设置无误。 --- ### 注意事项 尽管本文主要围绕 Linux 下的操作展开讨论,但类似的原理同样适用于 Windows 和 macOS 上的服务端应用场合。不过具体的实施细节可能会因为平台差异而略有区别。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值