Certbot Let's Encrypt 证书自动续期

安装 Certbot

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

certbot certonly //生成证书
certbot renew //续期
certbot certificates //查看证书

域名验证插件

https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

下载

$ git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

$ cd certbot-letencrypt-wildcardcertificates-alydns-au

$ chmod 0777 au.sh

配置

DNS API 密钥:

这个 API 密钥什么意思呢?由于需要通过 API 操作阿里云 DNS, 腾讯云 DNS 的记录,所以需要去域名服务商哪儿获取 API 密钥,然后配置在 au.sh 文件中:

  • ALY_KEY 和 ALY_TOKEN:阿里云 API key 和 Secrec 官方申请文档。
  • TXY_KEY 和 TXY_TOKEN:腾讯云 API 密钥官方申请文档。
  • HWY_KEY 和 HWY_TOKEN: 华为云 API 密钥官方申请文档
  • GODADDY_KEY 和 GODADDY_TOKEN:GoDaddy API 密钥官方申请文档。

生成证书

certbot certonly -d *.example.com -d example.com --manual --preferred-challenges dns --manual-auth-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly add" --manual-cleanup-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly clean"

续期 & nginx reload

certbot renew --manual --preferred-challenges dns --deploy-hook "nginx -s reload" --manual-auth-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly add" --manual-cleanup-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly clean"

定时任务

# 只有成功renew证书,才会重新加载 nginx 配置
0 3 * * 0 root certbot renew --manual --preferred-challenges dns --deploy-hook "nginx -s reload" --manual-auth-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly add" --manual-cleanup-hook "/usr/certbot-letencrypt-aliyun/au.sh python aly clean"

# 查看任务
crontab -l