泛域名自动更新证书

发布 : 2020-01-08 分类 : 杂类 浏览 :

申请泛域名并自动更新
之前的申请Let’s Encrypt永久免费SSL证书 自动化水平不够
申请泛域名时很麻烦需要手动改DNS的TXT并且有时候DNS刷新很慢,还有更崩溃的是本地看到刷新了当回车确认时又刷新出一条新的字符串…很崩溃

安装工具

使用https://github.com/certbot/certbot 工具
不要使用 https://github.com/letsencrypt/letsencrypt 这个运行时python会报错

1
2
3
4
5
6
7
8
git clone https://github.com/certbot/certbot

//DNS验证 创建证书时使用DNS验证需要用到的插件
git clone https://github.com/ywdblog/certbot-letencrypt-wildcardcertificates-alydns-au

cd certbot-letencrypt-wildcardcertificates-alydns-au
chmod 0777 au.sh

certbot-letencrypt-wildcardcertificates-alydns-au
如果使用泛域名就需要DNS验证
需要配置域名的key
工具使用教程

泛域名生成

1
./letsencrypt-auto certonly -d zhouinfo.site -d *.zhouinfo.site --manual --preferred-challenges dns --manual-auth-hook "certbot-letencrypt-wildcardcertificates-alydns-au/au.sh python aly add" --manual-cleanup-hook "certbot-letencrypt-wildcardcertificates-alydns-au/au.sh python aly clean" --server https://acme-v02.api.letsencrypt.org/directory --dry-run
  • certonly:表示采用验证模式,只会获取证书,不会为web服务器配置证书

  • -d 指定生成证书的域名 一般是主域名在前 泛域名在后

  • –manual:表示插件

  • –preferred-challenges dns 表示采用DNS验证申请者合法性

  • –dry-run 测试运行

  • –manual-auth-hook DNS创建修改钩子

  • –manual-cleanup-hook DNS删除钩子

  • au.sh python aly add

  • 第一个代表你要选择那种语言(php/python)

  • 第二个参数代表你的DNS厂商(aly/txy)

  • 第三个参数是固定的(–manual-auth-hook中用add,–manual-clean-hook中用clean)

泛域名更新

1
2
3
4
vim auto-certbot.sh

cd certbot
/zhou/letsencrypt/letsencrypt-auto renew --cert-name zhouinfo.site --manual --deploy-hook "nginx -s reload" --preferred-challenges dns --manual-auth-hook "/zhou/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh python aly add" --manual-cleanup-hook "/zhou/certbot-letencrypt-wildcardcertificates-alydns-au/au.sh python aly clean" --server https://acme-v02.api.letsencrypt.org/directory
  • –cert-name 中的zhouinfo.site需要和生成的证书名称对应 可以使用 ./letsencrypt-auto certificates 查看生成的证书名称
  • –manual –deploy-hook “nginx -s reload” 更新证书后需要重启nginx
    其余的参数和泛域名生成一样

每个月执行一次自动更新

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
sudo vim /etc/crontab 

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root

# For details see man 4 crontabs

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
# 每个月1日2时3分执行一次
3 2 1 * * auto-certbot.sh
本文作者 : zhouinfo
原文链接 : http://blog.zhouinfo.site/2020/01/08/%E6%B3%9B%E5%9F%9F%E5%90%8D%E8%87%AA%E5%8A%A8%E6%9B%B4%E6%96%B0%E8%AF%81%E4%B9%A6/
版权声明 : 本博客所有文章除特别声明外,均采用 CC Apache License 2.0 许可协议。转载请注明出处!
留下足迹