NipGeihou's blog NipGeihou's blog
  • 开发规范
  • 进阶笔记
  • 微服务
  • 快速开始
  • 设计模式
  • NoSQL 数据库

    • Redis
  • 数据结构与算法
  • 计算机网络
烹饪
关于
  • 分类
  • 标签
  • 归档

NipGeihou

我见青山多妩媚,料青山见我应如是
  • 开发规范
  • 进阶笔记
  • 微服务
  • 快速开始
  • 设计模式
  • NoSQL 数据库

    • Redis
  • 数据结构与算法
  • 计算机网络
烹饪
关于
  • 分类
  • 标签
  • 归档
  • Linux

  • Docker

  • 云原生

  • Kubernetes

  • KubeSphere

  • K3S

  • 笔记

    • 基于KtConnect实现本地与kubernetes集群互通
    • 基于Wireguard实现本地与kubernetes集群互通
    • Kubesphere问题总结
    • SpringBoot应用存活探针
    • DevOps - IDEA与Docker实现CI
    • 下一代CI工具 - Tekton
    • 基于Clash.Meta实现的流量分离
    • Windows命令-route路由表
    • 基于acme.sh的证书分发
      • acme.sh
        • 安装
        • 生成证书
        • Cloudflare
        • DNSPod
        • 腾讯云
        • 常用命令
        • 参考
    • 基于Nginx的内网域名管理
    • 年轻人的第一台服务器(D1581)
    • 基于WireGuard实现的云组网
    • 基于Tailscale实现的云组网
  • PVE

  • 维修

  • DevOps

  • 云服务

  • 路由器

  • 运维
  • 笔记
NipGeihou
2023-10-08
目录

基于acme.sh的证书分发

在个人项目中常常使用免费证书降低成本,而免费证书通常只有 3 个月。而续签脚本通常会在快过期前一个月就开始续签,进而导致我每次复制到 CDN 的证书通常只有 2 个月有效期,而通常 CDN 服务商会在过期前一个月就会疯狂发短信提醒,也就是每隔一个多月我就要被 CDN 服务商催更新证书,基于上述问题,笔者打算编写一个程序,自动完成证书分发到 CDN、VPS、kubernetes 等的工作。

# acme.sh

证书: fullchain.cer

私钥: example.com.key

# 安装

curl https://get.acme.sh | sh -s email=[email protected]

# 退出终端,重新连接
exit

# 检测
acme.sh -v

# 生成证书

这里只演示使用 DNS 生成泛域名证书

acme.sh --issue --dns dns_cf -d example.com -d *.example.com
  • --dns [dns_hook] :使用 dns 手动方式或 dns api 方式。当参数被省略时,默认为手动模式。
    • See: https://github.com/acmesh-official/acme.sh/wiki/dnsapi (opens new window)
  • -d, --domain <domain.tld> :指定一个域名,用于颁发、更新或撤销等。
  • --cert-file <file> :证书颁发 / 更新后拷贝到的路径。
  • --fullchain-file <file> :证书链签发 / 更新后复制到的路径。(推荐,可代替证书)
  • --key-file <file> :密钥颁发 / 更新后复制到的路径。
  • --reloadcmd <command> :命令,在证书签发 / 更新后执行,可用来重新加载服务器。

默认证书路径: ~/.acme.sh/example.com

# Cloudflare

# 方式1:使用具有特定权限的限制性API令牌,需另行创建
export CF_Token="<token>"
export CF_Account_ID="<id>"
export CF_Zone_ID="<zone>"

# 方式2:全局API令牌,该令牌具有所有权限
export CF_Key="763eac4f1bcebd8b5c95e9fc50d010b4"
export CF_Email="[email protected]"

acme.sh --issue --dns dns_cf -d example.com -d *.example.com
  • CF_Token :https://dash.cloudflare.com/profile/api-tokens,API 令牌,创建证书,编辑区域 DNS,使用模板。
  • CF_Account_ID 、 CF_Zone_ID :Find zone and account IDs · Cloudflare Fundamentals docs (opens new window)

# DNSPod

API 密钥 - DNSPod - 免费智能 DNS 解析服务商 - 电信_网通_教育网,智能 DNS (opens new window)

笔记

这里要使用 DNSPod Token ,不能使用 腾讯云 API 密钥 。

export DP_Id="<id>"
export DP_Key="<key>"

acme.sh --issue --dns dns_dp -d example.com -d *.example.com

# 腾讯云

参考:使用 acme.sh 为在腾讯云(DNSPod)解析的域名自动申请证书(API3.0 / 腾讯云(DNSPod)API 密钥版本) | 归去如风 (opens new window)

export Tencent_SecretId="<Your SecretId>"
export Tencent_SecretKey="<Your SecretKey>"

acme.sh --issue --dns dns_tencent -d example.com -d *.example.com

# 常用命令

# 列表
acme.sh --list

# 重新生成证书(证书在有效期内不会更新,强制更新加 --force)
acme.sh --renew --dns dns_tencent -d example.com -d *.example.com

# 手动更新
acme.sh --upgrade

# 自动更新
acme.sh --upgrade --auto-upgrade

# 关闭自动更新
acme.sh --upgrade --auto-upgrade  0

# 参考

  • acmesh-official/acme.sh: A pure Unix shell script implementing ACME client protocol (opens new window)
  • Run acme.sh in docker · acmesh-official/acme.sh Wiki (opens new window)
上次更新: 2023/12/05, 09:33:37
Windows命令-route路由表
基于Nginx的内网域名管理

← Windows命令-route路由表 基于Nginx的内网域名管理→

最近更新
01
Grafana笔记
12-04
02
Prometheus笔记
12-04
03
Spring Boot 整合Elasticsearch
12-04
更多文章>
Theme by Vdoing | Copyright © 2018-2023 NipGeihou | 友情链接
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式