Press "Enter" to skip to content

使用Let’s Encrypt和dnspod来自动获取ssl证书

背景

一直使用let’s encrypt的免费通配符域名,很爽。

最近发现域名要到期了,准备续订域名,然后收到个提示

Skipping bootstrap because certbot-auto is deprecated on this system.

啥情况?

查了下资料发现,好像是说,官方已经不建议使用certbot-auto来续订证书了。

https://stackoverflow.com/questions/66088845/skipping-bootstrap-because-certbot-auto-is-deprecated-on-this-system-when-using

https://blog.csdn.net/Dancen/article/details/112571444

国外人真是能折腾,反正他们不维护这个cerbot-auto了,然后又搞出了一套方案,使用snap来分发包。然后搞吧。

开撸

根据 https://certbot.eff.org/lets-encrypt/centosrhel7-nginx的说明,你需要根据你的系统安装一个snap的包管理工具,然后用这个包管理工具来下载certbot

我用的是centos7,大概执行下面的步骤来安装。

yum install epel-release
yum install snapd
systemctl enable --now snapd.socket
ln -s /var/lib/snapd/snap /snap

snap install core
snap refresh core
snap install --classic certbot
ln -s /snap/bin/certbot /usr/bin/certbot
snap set certbot trust-plugin-with-root=ok

到此,你的snap和certbot应该安装好了。

根据官方文档:https://certbot.eff.org/docs/using.html#pre-and-post-validation-hooks ,你可以传递个validation-hooks来直接用certbot来获取证书。大概这样用:

certbot certonly --manual --preferred-challenges=dns --manual-auth-hook /path/to/dns/authenticator.sh --manual-cleanup-hook /path/to/dns/cleanup.sh -d secure.example.com

然后我用的是dnspod的dns服务器,正当我准备自己手撸个dnspod的hook的时候,我想到开发人员手册第一条,永远不要重复造轮子。

我google搜了下,果然有大神写了这个脚本了。

https://github.com/al-one/certbot-auth-dnspod

(如果你用的是cloudflare,参考这个脚本,

这样就简单了,把自己的dnspod的token搞到,然后存到

/etc/dnspod_token

这个文件。

然后直接执行脚本:

certbot certonly --manual --preferred-challenges dns-01 --email mail@domain.com -d laravel.run -d *.laravel.run --server https://acme-v02.api.letsencrypt.org/directory --manual-auth-hook /path/to/certbot-auth-dnspod.sh --manual-cleanup-hook "/path/to/certbot-auth-dnspod.sh clean"

来获取你的证书,试了一把,问题不大,证书获取到了。

然后配置个定时任务,自动获取证书。

0 2 1 * * sh -c 'date "+\%Y-\%m-\%d \%H:\%M:\%S" && /usr/bin/certbot renew --manual-auth-hook /path/to/certbot-auth-dnspod.sh --manual-cleanup-hook "/path/to/certbot-auth-dnspod.sh clean"' >> /var/log/certbot-renew.log 2>&1

搞定。

对了,别忘了定时任务同时重启下你的NGINX。

参考资料:

https://certbot.eff.org/lets-encrypt/centosrhel7-nginx

https://certbot.eff.org/docs/using.html

https://github.com/al-one/certbot-auth-dnspod

https://github.com/7sDream/certbot-dns-challenge-cloudflare-hooks

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注