acme.sh使用教程

安装

  • acme.shGitHub地址 acme.sh
  • 安装
1
2
curl https://get.acme.sh | sh -s [email protected]
source ~/.bashrc

注:email需要替换成自己的邮箱

  • 检查是否安装成功
1
acme.sh -h

配置dns使用域名解析商提供的api自动添加txt记录完成验证

  • 详细的api使用方法介绍地址 dns api usage
  • 此处使用阿里云为例
1
2
export Ali_Key="<key>"
export Ali_Secret="<secret>"

生成证书

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

安装证书(此处为nginx方式)

1
2
3
4
acme.sh --install-cert -d example.com \
--key-file /path/to/keyfile/in/nginx/key.pem \
--fullchain-file /path/to/fullchain/nginx/cert.pem \
--reloadcmd "service nginx force-reload"

查看已安装证书信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
acme.sh --info -d example.com
# 会输出如下内容:
DOMAIN_CONF=/root/.acme.sh/example.com/example.com.conf
Le_Domain=example.com
Le_Alt=no
Le_Webroot=dns_ali
Le_PreHook=
Le_PostHook=
Le_RenewHook=
Le_API=https://acme-v02.api.letsencrypt.org/directory
Le_Keylength=
Le_OrderFinalize=https://acme-v02.api.letsencrypt.org/acme/finalize/23xxxx150/781xxxx4310
Le_LinkOrder=https://acme-v02.api.letsencrypt.org/acme/order/233xxx150/781xxxx4310
Le_LinkCert=https://acme-v02.api.letsencrypt.org/acme/cert/04cbd28xxxxxx349ecaea8d07
Le_CertCreateTime=1649358725
Le_CertCreateTimeStr=Thu Apr 7 19:12:05 UTC 2022
Le_NextRenewTimeStr=Mon Jun 6 19:12:05 UTC 2022
Le_NextRenewTime=1654456325
Le_RealCertPath=
Le_RealCACertPath=
Le_RealKeyPath=/etc/acme/example.com/privkey.pem
Le_ReloadCmd=service nginx force-reload
Le_RealFullChainPath=/etc/acme/example.com/chain.pem

acme.sh更新证书列表

1
2
acme.sh --list
acme.sh --list -d example.com

移除证书

1
acme.sh --remove -d your_domain.com

更新acme.sh

  • 更新acme.sh
1
acme.sh --upgrade
  • 开启自动升级
1
acme.sh --upgrade --auto-upgrade
  • 关闭自动更新
1
acme.sh --upgrade --auto-upgrade  0

acme.sh 卸载

1
2
acme.sh --uninstall 
# 然后再删除 ~/.acme.sh/ 目录.

docker 部署 acme.sh

  • 克隆仓库
1
git clone https://github.com/acmesh-official/acme.sh.git
  • 创建 docker-compose.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
services:
acme-sh:
build:
context: ./acme.sh
dockerfile: Dockerfile
image: acme.sh
container_name: acme.sh
network_mode: host
restart: always
command: daemon
environment:
- CF_Token="API令牌"
volumes:
- /home/docker/acme.sh:/acme.sh
logging:
driver: "json-file"
options:
max-size: "10m"
max-file: "3"
  • 将默认证书服务器切换为 letsencrypt
1
docker exec acme.sh acme.sh --set-default-ca --server letsencrypt
  • 更改 acme.sh 邮箱,(实测可以不用这一步)
1
docker exec acme.sh --register-account -m [email protected]
  • 申请证书
1
docker exec acme.sh --issue --dns dns_cf -d domin.example.com

注意:其他命令结合前面自行组合 docker exec acme.sh ...

  • 设置 crontab 任务自动续签
1
2
3
4
5
crontab -l  # 查看任务列表
crontab -e # 编辑任务列表

# 添加如下内容
# 0 0 * * * docker exec acme.sh --cron