Certbot 设置 Let’s Encrypt 日志

背景

ssl 证书到期,需要更新,按常规方式 certbot renew ./certbot-auto renew失败。
出现过问题:Python 环境问题,certbot 版本问题,plugin 版本问题等等。

贴几个还找得到的错误日志

1
python virtualenv 问题
1
2
3
An unexpected error occurred:
pkg_resources.VersionConflict: (certbot 0.31.0 (/usr/lib/python3/dist-packages), Requirement.parse(‘certbot>=0.34.0’))
Please see the logfile ‘/tmp/tmpbyuigqhc’ for more details.
1
2
3
Saving debug log to /var/log/letsencrypt/letsencrypt.log
Could not choose appropriate plugin: The requested nginx plugin does not appear to be installed
The requested nginx plugin does not appear to be installed

排查过程

  1. 重新部署Python 环境,安装缺失插件(无效)
  2. 查看 which certbot 安装位置,发现是用 pip3 安装的,然后 pip3 更新软件包(无效)
  3. certbot 源码编译安装,替换 certbot 文件(无效,出现 acme 版本问题,plugin 问题)
  4. 删除 pip3 安装的 certbot 以及关联文件,重新安装(无效)
  5. 再次删除 pip3 安装的 certbot 文件,重新 which certbot 发现 apt 也安装过一份
  6. 删除 apt 安装的 certbot,重新 which certbot 发现 snap 也安装过(😓)
  7. 删除 snap 安装的 certbot,重新 which certbot 无结果,清除完成
  8. 官方方式 snap 安装,certbot 执行成功,然后使用 certbot-dns-cloudflare 插件(提示未安装)
  9. apt 安装 certbot-dns-cloudflare,之后 certbot 执行再次出问题,日志显示 certbot 版本回退到 0.4 版本,certbot 执行位置再次恢复至 Python
  10. 再次 pip3 ,apt , snap 全部清除 certbot 及其关联文件。
  11. 再次 snap 安装 certbot,测试成功之后,使用 pip3 安装 certbot-dns-cloudflare 插件,成功!

注意: 有些教程中使用 apt 安装插件,有如下命令,实际过程中会出现
E: The repository 'http://ppa.launchpad.net/certbot/certbot/ubuntu focal Release' does not have a Release file. 类似错误,查阅资料有网友说这种方式已经不再推荐。故使用 snap 安装 certbot 及 pip 安装相关插件。

1
2
3
4
5
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository universe
sudo add-apt-repository ppa:certbot/certbot
sudo apt-get update

相关执行命令

  • pip3 清除软件包
    pip3 uninstall certbot

  • apt 清除软件包
    sudo apt-get remove certbot

  • snap 清除软件包
    sudo snap remove certbot

  • certbot安装
    sudo snap install --classic certbot

  • certbot-dns-cloudflare 插件安装
    pip3 install certbot-dns-cloudflare

总结

  1. 清除所有 certbot 安装包,包括 pip apt snap
  2. 使用 snap 安装 sudo snap install --classic certbot
  3. 使用 pip3 install certbot-dns-cloudflare 安装插件

附:证书申请命令

1.certbot

1
certbot certonly --preferred-challenges dns --manual  -d example.com -d *.example.com --server https://acme-v02.api.letsencrypt.org/directory

2.certbot-auto

1
./certbot-auto certonly --email [email protected] -d example.com -d *.example.com  --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory  

3.自动化

1
2
3
4
5
6
7
sudo certbot certonly -d example.com -d *.example.com  \
--agree-tos \
--email [email protected] \
--server https://acme-v02.api.letsencrypt.org/directory \
--dns-cloudflare \
--dns-cloudflare-credentials ~/.secrets/certbot/cloudflare.ini \
--dns-cloudflare-propagation-seconds 30