Linux使用certbot通过DNSPod申请Letsencrypt免费泛域名证书并设置自动续期

安装certbot

CentOS

yum install -y certbot

如果提示No package certbot available.的话,先安装EPEL源再安装

yum install -y epel-release
yum install -y certbot

Ubuntu/Debian

sudo apt install -y certbot

安装certbot-dns-dnspod

使用pip安装,需要先安装python跟pip

pip install certbot-dns-dnspod
pip安装certbot-dns-dnspod
pip安装certbot-dns-dnspod

配置DNSPod Token

Token申请地址:https://console.dnspod.cn/account/token/token

配置dnspod token信息

dnspod的token配置格式是 id,token

创建配置文件,保存在/etc/certbot/目录下

假设我的id是123456,token是9d9aee10be45ce79417b22b5c906bd33

mkdir /etc/certbot
echo '
dns_dnspod_email = "web@notevm.com"
dns_dnspod_api_token = "123456,9d9aee10be45ce79417b22b5c906bd33"
'>/etc/certbot/dnspod.ini
创建dnspod配置文件
创建配置文件

查看配置文件

cat /etc/certbot/dnspod.ini
查看dnspod配置文件
查看配置文件

设置配置文件权限

chmod 600 /etc/certbot/dnspod.ini

申请证书

certbot certonly \
-a dns-dnspod \
--dns-dnspod-credentials /etc/certbot/dnspod.ini \
-d notevm.com \
-d *.notevm.com
certbot申请证书
申请证书

第一次申请填写几个参数(邮箱、是否同意条款、是否接收资讯邮件)就行。

证书申请后保存在/etc/letsencrypt/live/域名/目录下。

设置自动续期

使用crontab任务计划来实现自动续期

关于crontab用法可以查看这篇文章:Linux任务计划crontab用法

执行crontab -e

0 3 */8 * * /bin/certbot renew
30 3 */8 * * /bin/nginx -s reload
crontab配置证书自动续期
配置自动续期

保存后重启crond服务

systemctl restart crond

每隔8天凌晨3点整执行证书续签指令

每隔8天凌晨3点30分重启nginx

原创文章,作者:小哆啦,如若转载,请注明出处:https://www.notevm.com/a/5738.html

(0)
小哆啦的头像小哆啦
上一篇 2022年5月25日 14:31
下一篇 2022年5月27日 11:27

相关推荐

发表回复

登录后才能评论

评论列表(2条)