Tuesday, September 12, 2023

怎样使用certbot-dns-cloudflare

 【介绍】 

源码:https://github.com/cloudflare/certbot-dns-cloudflare certbot-dns-cloudflare 1.30.0 

源码:https://pypi.org/project/certbot-dns-cloudflare/ 

作者:https://github.com/certbot/certbot 

参考:https://www.cnblogs.com/senro/p/Blog01_L_S.html 

参考:https://www.cnblogs.com/senro/p/Blog01_L_S.html 

参考:https://community.letsencrypt.org/t/certbot-dns-cloudflare-automatic-renewal-issue/97627 

安装】 

参考:https://bobcares.com/blog/install-certbot-dns-cloudflare/ 

1. 安装 snap : 

参考:https://amon.org/snap 

设置 snapd 为开机启动:

 2. 安装 certbot-dns-cloudflare :

 sudo snap install certbot-dns-cloudflare

 输出: 1 2 2022-09-18T19:46:35Z INFO Waiting for automatic snapd restart... certbot-dns-cloudflare 1.30.0 from Certbot Project (certbot-eff✓) installed 

3. 安装 python3-certbot-dns-cloudflare :

 Ubuntu 系统:

 sudo apt-get install python3-certbot-dns-cloudflare 

CentOS 系统: 

sudo yum install python3-certbot-dns-cloudflare 

【配置】 

注意:如果同一台设备切换 CloudFlare 账号,务必清空 /etc/letsencrypt/ 下所有证书相关文件,然后从填写邮箱重新开始。 

先在 CloudFlare 获得 API Token : 

1. 登录Cloudflare后,点击右上角用户头像,在下拉列表中点击My Profile。 

2. 在新页面便可看到API Token的标签。点击Create Token。

 3. 显示有很多模板可供使用,使用第一个 Edit zone DNS。 

4. 一切保持默认就好;在 Zone Resources,选择 All zones 。

 5. 创建Token后,页面会显示一个很长的字符串,这就是Token,点击后面的Copy保存下来。 

参考:https://laowangblog.com/python-cloudflare-api-update-dns.html 

参考:https://juejin.cn/post/7069995574266691614 

在需要运行Certbot的主机上创建一个文件:/etc/letsencrypt/certbot-dns-cloudflare.ini 1 dns_cloudflare_api_token = _yourToken_ 修改这个文件的所有者和权限,提高域名安全性。

建议root:root和600。 

【使用】 签发证书: 

certbot certonly --dns-cloudflare --dns-cloudflare-credentials /etc/letsencrypt/certbot-dns-cloudflare.ini -d domain.name -d *.domain.name 

Certbot的所有信息的路径:/etc/letsencrypt。 

archive目录:包含所有已经申请的证书及私钥,包括已经过期的证书。

 live目录:只包含最新的证书及私钥,通过符号链接指向archive目录对应的文件。 

fullchain.pem是大多数软件需要的证书文件,实际上它是cert.pem和chain.pem的拼接。 privkey.pem如其名,是私钥文件。 

更新证书: 

 certbot renew 查看证书: 

 certbot certificates 删除证书:

 certbot delete 自动更新证书: 

Certbot的设计就是用来自动化的,根据获得软件包的方式,你的Certbot可能已经带有自动化的脚本。 自动化有两套方案,Crontab或Systemd Timer。 

这里说Systemd Timer。 

创建文件:/etc/systemd/system/certbot.service 

[Unit]

Description=Let's Encrypt renewal

[Service]

Type=oneshot ExecStart=/usr/bin/certbot renew --quiet --agree-tos 

创建文件:/etc/systemd/system/certbot.timer

[Unit]

Description=Automatic renewal of Let's Encrypt's certificates

[Timer]

OnCalendar=03:00:00

RandomizedDelaySec=1h

Persistent=true

[Install]

WantedBy=timers.target

启用自动更新:

sudo systemctl enable --now certbot.timer


标题: 怎样使用certbot-dns-cloudflare » 阿蒙的礼物
链接: https://amon.org/certbot-cloudflare
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

No comments:

Post a Comment