


























warning: 这篇文章距离上次修改已过1868天,其中的内容可能已经有所变动。
今晚发现 hellodk.com 的几个网站的证书过期(比如 https://router.hellodk.com )无法访问,然后续期证书遇到问题,本文记录解决过程。
由于之前是配置了 crontab 脚本定期续期证书的,没有成功续上那就肯定是程序执行出错了。检查 cron 日志发现下面这个报错
PluginError('An authentication script must be provided with
--manual-auth-hook when using the manual plugin non-interactively godaddy
出现这个错误的原因是 certbot 无法直接更新你的域名的DNS记录中的 TXT 记录值导致更新失败
因为推荐的申请泛域名证书/通配符证书的方式是--preferred-challenges dns dns challenge 模式。这是使用 DNS 方式校验域名所有权,域名验证 dns 解析需要增加 TXT 类型的解析配置,子域名为_acme-challenge 默认情况下需要你自己去域名服务商(比如 阿里云 腾讯云 华为云 godaddy等) dns 解析那里去配置。如果想要通过命令行直接更新 txt 值就要利用 certbot 提供的 hook 函数,我们在shell 中调用DNS服务商的相关API接口就可以动态的更新TXT记录了
就是这样一个原理。好在已经有大神写出来了相关的项目了。因为我的域名服务商使用的是 godaddy 所以找了一个支持 godaddy的github项目: https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au
仔细阅读大神项目的 readme 文档
重要的几个点
au.sh 文件有执行权限domain.ini 文件中存在,如果不存在就自行添加一行au.sh 文件中--dry-run 选项进行一次证书申请的测试附上一个小插曲,centOS7 安装 php7 的教程: https://linuxize.com/post/install-php-7-on-centos-7/
简而言之就是下面几条命令
执行 php -v 有版本输出代表本机的php7成功安装
$ php -v
PHP 7.3.27 (cli) (built: Feb 2 2021 10:32:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies
with Zend OPcache v7.3.27, Copyright (c) 1999-2018, by Zend Technologies
在开始之前,建议执行 certbot certificates 查看本机安装的证书,使用certbot delete 删除不需要的证书再开始(删除的时候是交互式的,放心大胆的执行 certbot delete 没事,会让你选择数字然后yes确认,或者直接按c取消操作)
带上 --dry-run 选项
certbot certonly -d "*.hellodk.com" -d hellodk.com \
--manual --preferred-challenges dns --dry-run \
--manual-auth-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add" \
--manual-cleanup-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean"
下面这是测试时候的日志
[root@justhostRU /]# certbot certonly -d "*.hellodk.com" -d hellodk.com --manual --preferred-challenges dns --dry-run --manual-auth-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add" --manual-cleanup-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean"
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator manual, Installer None
Cert is due for renewal, auto-renewing...
Simulating renewal of an existing certificate for *.hellodk.com and hellodk.com
Performing the following challenges:
dns-01 challenge for hellodk.com
dns-01 challenge for hellodk.com
Running manual-auth-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add
Running manual-auth-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add
Waiting for verification...
Cleaning up challenges
Running manual-cleanup-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean
Running manual-cleanup-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean
IMPORTANT NOTES:
- The dry run was successful.
如果有 IMPORTANT NOTES: - The dry run was successful. 的日志输出,那么说明 api key 和 secret 配置的肯定是正确的,说明成功请求到 dns 服务商的 api,然后就可以进行接下来的续期操作了
命令
certbot renew --manual --preferred-challenges dns \
--manual-auth-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add" \
--manual-cleanup-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean"
下面这是实际续期时候的日志
[root@justhostRU /]# certbot renew --manual --preferred-challenges dns --manual-auth-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add" --manual-cleanup-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean"
Saving debug log to /var/log/letsencrypt/letsencrypt.log
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/hellodk.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert is due for renewal, auto-renewing...
Plugins selected: Authenticator manual, Installer None
Renewing an existing certificate for *.hellodk.com and hellodk.com
Performing the following challenges:
dns-01 challenge for hellodk.com
dns-01 challenge for hellodk.com
Running manual-auth-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add
Running manual-auth-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add
Waiting for verification...
Cleaning up challenges
Running manual-cleanup-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean
Running manual-cleanup-hook command: /root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed without reload, fullchain is
/etc/letsencrypt/live/hellodk.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations, all renewals succeeded:
/etc/letsencrypt/live/hellodk.com/fullchain.pem (success)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
成功续期
执行一下 nginx -s reload
网页访问 https://router.hellodk.com

成功续期
# 每当 7月 10月 1月 4月 的 7号 上午9点 执行命令,续期通配符证书
0 9 7 7,10,1,4 * /usr/bin/certbot renew --manual --preferred-challenges dns --manual-auth-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy add" --manual-cleanup-hook "/root/temp/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh php godaddy clean" --renew-hook "/usr/sbin/nginx -s reload"
crontab -e 将上面的命令追加到末尾
# 重载 crond 服务
systemctl reload crond.service
# 重启 crond 服务
systemctl restart crond.service
这样一来,7月、10月、2022年1月、2022年4月(后面不断推进时间……)的7号上午的9点都会自动的续期通配符证书,https服务可以不间断的运行了。本文的分享结束
end.
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。