侧边栏壁纸
博主头像
王小木人

这是很长,很好的一生

  • 累计撰写 141 篇文章
  • 累计创建 43 个标签
  • 累计收到 7 条评论

目 录CONTENT

文章目录

使用certbot申请Let's encrypt 泛域名证书并自动续期

王小木人
2021-08-26 / 0 评论 / 2 点赞 / 2,672 阅读 / 2,598 字

我的服务器环境是centos8,之前写过certbot生成泛域名证书,但是证书有效期只有三个月,到期后需要手动续期,且需要手动在dns解析中修改txt配置。

申请单域名证书时可以直接使用

certbot renew --deploy-hook 'nginx -s reload'

完成续期,但是泛域名多了一个在阿里云那里修改dns解析txt配置的操作,certbot无法自动完成,所以会报

Failed to renew certificate wxmblog.com with error: The manual plugin is not working; there may be problems with your existing configuration.
The error was: PluginError('An authentication script must be provided with --manual-auth-hook when using the manual plugin non-interactively.',)

错误。

20210826_1520.png

大概是说:当使用手动插件时,必须提供一个身份验证脚本

解决办法 安装certbot阿里云dns插件

阿里云dns插件可以自动帮我们修改我们阿里云账号上的dns解析记录,当然需要授权后得到access_key和secret码。

pip install certbot-dns-aliyun

安装过程可能因环境不同会报-bash: pip: 未找到命令 错误,这是没有安装pip包,需要先安装后再操作。

创建aliyun.ini,并写入授权信息(授权账号需要有AliyunDNSFullAccess)
授权信息如下
certbot_dns_aliyun:dns_aliyun_access_key = 登陆阿里云控制台获取
certbot_dns_aliyun:dns_aliyun_access_key_secret = 登陆阿里云控制台获取
AccessKey ID 和 AccessKey Secret 登陆阿里云》控制台》RAM控制》创建用户》添加权限(授权需要有AliyunDNSFullAccess)
创建aliyun.ini

touch aliyun.ini

写入授权信息

vim aliyun.ini

20210826_1733.png

保存后退出
修改权限

chmod 600 aliyun.ini

申请证书

certbot certonly -a certbot-dns-aliyun:dns-aliyun --certbot-dns-aliyun:dns-aliyun-credentials aliyun.ini -d wxmblog.com -d *.wxmblog.com --server https://acme-v02.api.letsencrypt.org/directory

成功后会返回证书地址,在nginx中配置好就好了,主要是下面这两个。
/etc/letsencrypt/live/wxmblog.com/fullchain.pem
etc/letsencrypt/live/wxmblog.com/privkey.pem

20210826_1804.png

重新加载nginx

nginx -s reload

查看证书日期已经被更新了。

自动续期

使用liunx自带的定时任务 crontab每天自动检查。

0 1 * * * certbot renew --force-renewal --deploy-hook 'nginx -s reload'

到此结束。

常见报错

安装过程中系统环境不一样可能遇到安装失败问题,如pip 不存在之类,先安装相应的组件即可。

-bash: pip: 未找到命令

安装 pip

sudo easy_install pip

查看安装结果

pip -V

如果依然找不到,试试 pip3 -V,centos版本不一样安装也不一样,高版本安装pip3,安装阿里云插件时,不能使用pip,而是pip3

pip3 install certbot-dns-aliyun

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-5tf4frgo/cryptography/

pip3 install --upgrade pip

再安装阿里云插件

pip3 install certbot-dns-aliyun
2

评论区