popyone
发布于 2026-02-03 / 6 阅读
0
0

certbot Cloudflare/腾讯云 泛域名证书申请及续订

安装certbot

1. SSH 进入服务器以具有 sudo 权限的用户身份通过 SSH 进入运行 HTTP 网站的服务器。

2. 安装系统依赖项系统依赖项可能包括 Python 3.6+(包括 venv 模块)和 Apache 插件的 Augeas。

如果您在安装加密系统时遇到问题,可能需要安装其他依赖项。 有关更多信息,请参阅加密系统项目网站。

安装系统依赖项的命令可能如下所示,在机器上的命令行上运行。

对于基于 APT 的发行版(例如 Debian、Ubuntu...):

 sudo apt update
 sudo apt install python3 python3-dev python3-venv libaugeas-dev gcc

对于基于 RPM 的发行版(例如 Fedora、CentOS...):

 sudo dnf install python3 python-devel augeas-devel gcc

请注意,旧发行版使用yum而不是dnf,而基于 RHEL 的发行版使用python3.X而不python3(例python3.6)。

3. 删除 certbot-auto 和所有 Certbot OS 软件包

# debian/ubuntu
sudo apt-get remove certbot

# centos8/9
sudo dnf remove certbot

# centos7
sudo yum remove certbot。

4. 设置 Python 虚拟环境

在机器上的命令行上执行以下指令来设置虚拟环境。

 sudo python3 -m venv /opt/certbot/
 source /opt/certbot/bin/activate
 pip3 install --upgrade pip3

5. 安装 Certbot

在机器上的命令行上运行此命令来安装 Certbot。

 pip3 install certbot

6. 准备 Certbot 命令

在机器的命令行上执行如下指令,确certbot命令可以运行。

 sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot

7. 安装插件

安装正确的DNS插件

运行以下命令,将 替换为您的 DNS 提供商的名称。

pip3 install certbot-dns-<PLUGIN>

例如,如果您的 DNS 提供商是 Cloudflare,您将运行以下命令:

pip3 install certbot-dns-cloudflare

如果您的 DNS 提供商是 腾讯云,您将运行以下命令:

pip3 install certbot-dns-tencentcloud

8. 申请证书

1、生成API 密钥存储文件

使用受限 API 令牌的示例凭证文件(推荐)

mkdir ~/.certbot
vim ~/.certbot/key.ini
# Cloudflare API token used by Certbot
dns_cloudflare_api_token = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    
# 腾讯云 API 凭据
dns_tencentcloud_secret_id = AKIDxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
dns_tencentcloud_secret_key = xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

修改key.ini权限

chmod 600 ~/.certbot/key.ini

9. 申请泛域名证书

Cloudflare:

```shell
certbot certonly --dns-cloudflare --dns-cloudflare-credentials ~/.certbot/key.ini --dns-cloudflare-propagation-seconds 60 -d *.popyone.cn -d popyone.cn
```

腾讯云:

```shell
certbot certonly --authenticator dns-tencentcloud --dns-tencentcloud-credentials ~/.certbot/key.ini --dns-tencentcloud-propagation-seconds 60 -d *.popyone.cn -d popyone.cn
```
  • --dns-cloudflare 使用cloudflare插件

  • --dns-cloudflare-credentials 证书文件

  • --dns-cloudflare-propagation-seconds 60 等待60秒, 等DNS解析生效

10. 自动续订证书

续订证书,重新载入nginx

certbot renew --renew-hook "/usr/sbin/nginx -s reload"

评论