Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

阿里云 DNS 的 certbot 插件,用来解决阿里云 DNS 不能自动为通配符证书续期的问题

License

NotificationsYou must be signed in to change notification settings

justjavac/certbot-dns-aliyun

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

解决阿里云 DNS 不能自动为通配符证书续期的问题

原理

当我们使用 certbot 申请通配符证书时,需要手动添加 TXT 记录。每个 certbot申请的证书有效期为 3 个月,虽然 certbot提供了自动续期命令,但是当我们把自动续期命令配置为定时任务时,我们无法手动添加新的TXT 记录用于 certbot 验证。

好在 certbot 提供了一个 hook,可以编写一个 Shell 脚本。在续期的时候让脚本调用DNS 服务商的 API 接口动态添加 TXT 记录,验证完成后再删除此记录。

安装(CommandLine)

  1. 安装 aliyun cli 工具

    wget https://aliyuncli.alicdn.com/aliyun-cli-linux-latest-amd64.tgztar xzvf aliyun-cli-linux-latest-amd64.tgzsudo cp aliyun /usr/local/binrm aliyun

    安装完成后需要配置凭证信息

  2. 安装 certbot-dns-aliyun 插件

    wget https://cdn.jsdelivr.net/gh/justjavac/certbot-dns-aliyun@main/alidns.shsudo cp alidns.sh /usr/local/binsudo chmod +x /usr/local/bin/alidns.shsudo ln -s /usr/local/bin/alidns.sh /usr/local/bin/alidnsrm alidns.sh
  3. 申请证书

    测试是否能正确申请:

    certbot certonly -d*.example.com --manual --preferred-challenges dns --manual-auth-hook"alidns" --manual-cleanup-hook"alidns clean" --dry-run

    正式申请时去掉--dry-run 参数:

    certbot certonly -d*.example.com --manual --preferred-challenges dns --manual-auth-hook"alidns" --manual-cleanup-hook"alidns clean"
  4. 证书续期

    certbot renew --manual --preferred-challenges dns --manual-auth-hook"alidns" --manual-cleanup-hook"alidns clean" --dry-run

    如果以上命令没有错误,把--dry-run 参数去掉。

  5. 自动续期

    添加定时任务 crontab。

    crontab -e

    输入

    1 1*/1** root certbot renew --manual --preferred-challenges dns --manual-auth-hook "alidns" --manual-cleanup-hook "alidns clean" --deploy-hook "nginx -s reload"

    上面脚本中的--deploy-hook "nginx -s reload" 表示在续期成功后自动重启nginx。

安装(Dockerfile)

下载 Dockerfile 以及 entrypoint.sh, 确保他们在同一文件夹下。目前 Dockerfile中默认下载 amd64 版本,其他架构请修改对应的 Aliyun CLI URL。

  1. 创建 Image

    进入 Dockerfile 同目录:

    docker build -t certbot-aliyun.

    使用代理(可选):

    docker build. \ --build-arg"HTTP_PROXY=http://127.0.0.1:7890" \ --build-arg"HTTPS_PROXY=http://127.0.0.1:7890" \ -t certbot-aliyun
  2. 运行容器

    docker run \-e REGION=YOUR_REGEION \-e ACCESS_KEY_ID=YOUR_ACCESS_KEY \-e ACCESS_KEY_SECRET=YOUR_ACCESS_SECRET \-e DOMAIN=YOUR_DOMAIN \-e EMAIL=YOUR_NOTIFICATION_EMAIL\  // 证书刷新通知邮箱-e CRON_SCHEDULE="0 0 * * *"\  // 自定义证书刷新间隔-v /path/letsencrypt:/etc/letsencrypt\// 将容器内的证书路径完整映射到宿主机-d certbot-aliyun

About

阿里云 DNS 的 certbot 插件,用来解决阿里云 DNS 不能自动为通配符证书续期的问题

Topics

Resources

License

Stars

Watchers

Forks

Contributors7


[8]ページ先頭

©2009-2025 Movatter.jp