一、下载
$ git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au $ cd certbot-letencrypt-wildcardcertificates-alydns-au $ chmod 0777 au.sh
二、使用方法
2.1 申请证书
2.1.1 测试是否有错误
certbot certonly -d *.abc.com -d abc.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-auth-hook "/path/certbot-alydns/au.sh python aly add" --manual-cleanup-hook "/path/certbot-alydns/au.sh python aly clean" --dry-run
Debug: 操作 DNS API 可能会遇到一系列问题,比如 API token 权限不足,遇到相关问题,可以查看 /var/log/certd.log。
重要解释: –manual-auth-hook 和 –manual-cleanup-hook 有三个参数:
- 第一个代表你要选择那种语言(php/python)
- 第二个参数代表你的DNS厂商(aly/txy)
- 第三个参数是固定的(–manual-auth-hook中用add,–manual-clean-hook中用clean)
比如你要选择Python环境,可以将 –manual-auth-hook 输入修改为 “/path/certbot-alydns/au.sh python aly add”,–manual-cleanup-hook 输入修改为 “/path/certbot-alydns/au.sh python aly clean”
2.1.2 实际申请
确认无误后,实际运行(去除 –dry-run 参数):
certbot certonly -d *.abc.com -d abc.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-auth-hook "/path/certbot-alydns/au.sh python aly add" --manual-cleanup-hook "/path/certbot-alydns/au.sh python aly clean"
参数解释(可以不用关心):
- certonly:表示采用验证模式,只会获取证书,不会为web服务器配置证书
- –manual:表示插件
- –preferred-challenges dns:表示采用DNS验证申请者合法性(是不是域名的管理者)
- –dry-run:在实际申请/更新证书前进行测试,强烈推荐
- -d:表示需要为那个域名申请证书,可以有多个。
- –manual-auth-hook:在执行命令的时候调用一个 hook 文件
- –manual-cleanup-hook:清除 DNS 添加的记录
2.1.3 多个域名申请
如果你想为多个域名申请通配符证书(合并在一张证书中,也叫做 SAN 通配符证书),直接输入多个 -d 参数即可,比如:
certbot certonly -d *.abc.com -d *.abc.org --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory --manual-auth-hook "/path/certbot-alydns/au.sh python aly add" --manual-cleanup-hook "/path/certbot-alydns/au.sh python aly clean"
2.2 续期证书
证书有效期<30天才会renew,所以crontab可以配置为1天或1周
certbot renew --post-hook "systemctl reload nginx " --post-hook "systemctl reload apache2"
2.3 加入 crontab
编辑文件 /etc/crontab :
1 1 */1 * * root certbot renew --post-hook "systemctl reload nginx " --post-hook "systemctl reload apache2"