avatar

十六小站

欢迎来到我的个人主页! 期待与您分享我的经验与故事,一起探索技术的无穷可能!

  • 首页
  • NAS专题
  • 关于
Home ACME证书自动续期
文章

ACME证书自动续期

Posted 2024-07-2 Updated 2025-01- 13
By 十六
9~12 min read

下载shell脚本

官方提供了三种下载方式,有不信的还其他方式尝试

# 1.curl
curl https://get.acme.sh | sh -s email=my@example.com

#2. wget
wget -O - https://get.acme.sh | sh -s email=my@example.com

#3.git
git clone --depth 1 https://github.com/acmesh-official/acme.sh.git
cd acme.sh
./acme.sh --install -m my@example.com

创建别名

如果没有自动创建别名(执行acme.sh,提示command not found),可以使用以下命令自行创建:

# /root/.acme.sh/acme.sh为sh的下载目录
alias acme.sh='/root/.acme.sh/acme.sh'

申请验证证书

配置云平台API

在自己的云平台申请,创建成功后记录,并配置到系统中。配置成功后acme会根据调用api自动校验dns

file

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

需要根据不同平台配置不同的环境变量,如果不知道自己平台需要如何配置。 访问:https://github.com/acmesh-official/acme.sh/blob/master/dnsapi 找到对应的shell文件,即可找到。 file

申请证书

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

手动验证DNS

运行如下命令,请求签发证书,会提示你做一条txt记录,按提示做好txt解析记录:

acme.sh --issue -d example.com -d *.example.com --dns \
--yes-I-know-dns-manual-mode-enough-go-ahead-please

做好txt解析记录生效后,运行如下命令,即可验证DNS解析,即系成功后,即可签发证书了(注意:第一次是--issue,第二次是--renew):

acme.sh --renew -d example.com -d *.example.com \
--yes-I-know-dns-manual-mode-enough-go-ahead-please

发布证书

apache使用

acme.sh --install-cert -d example.com \
--cert-file /path/to/certfile/in/apache/cert.pem \
--key-file /path/to/keyfile/in/apache/key.pem \
--fullchain-file /path/to/fullchain/certfile/apache/fullchain.pem \
--reloadcmd "service apache2 reload"

nginx使用

acme.sh --install-cert -d *.example.com \
--key-file /path/to/certfile/in/nginx/cert.key  \
--fullchain-file /path/to/certfile/in/nginx/cert.pem \
--reloadcmd     "nginx -s reload"

执行该命令后,命令中的参数将自动保存在~/.acme.sh/example.com目录下的example.com.conf文件里,定时器更新证书的时候实现自动部署。

上述命令把下发的证书复制到你指定的位置,这样避免你直接从“~/.acme.sh/”读取证书,然后重新加载nginx或apache以刷新证书。域名为必需参数,其它参数为可选。

但要注意的是,reloadcmd参数非常重要(reloadcmd后面的参数为重新加载nginx或Apache的命令,可以根据系统的不同作相应修改),即使更新了证书,但是nginx或apache没有重新加载,证书是不是会刷新到服务中去的。

acme常用命令

#1、查看acme.sh已签发证书的域名:
acme.sh --list

#2、从acme.sh中移除不需要再次签发证书的域名:
acme.sh --remove -d example.com

#3、删除acme.sh:
acme.sh --uninstall

官方文档

acmesh-official项目地址:https://github.com/acmesh-official/acme.sh/tree/master

How to install/如何安装:https://github.com/acmesh-official/acme.sh/wiki/How-to-install

DNS manual mode/DNS手动签发:https://github.com/acmesh-official/acme.sh/wiki/DNS-manual-mode

How to issue a cert/如何签发证书:https://github.com/acmesh-official/acme.sh/wiki/How-to-issue-a-cert

How to use DNS API/如何使用DNS API:https://github.com/acmesh-official/acme.sh/wiki/dnsapi

License:  CC BY 4.0
Share

Further Reading

OLDER

HTML中的HTTP升级HTTPS请求

NEWER

Docker搭建Redis集群

Recently Updated

  • Onlyoffice编译
  • K6+Playwright实现并发测试
  • 简单规则引擎
  • 在WEB中子线程可以访问Request上下文
  • onlyoffice配置

Trending Tags

Java Docker 前端 中间件 数据库 群晖 unraid

Contents

©2025 十六小站. 陕ICP备2023009742号-2