Acme.sh 证书
1. 工具定位
Section titled “1. 工具定位”Acme.sh 是一个完全用纯 Shell 脚本编写的 ACME 协议客户端。无需安装额外的 Python 环境或庞大的 certbot,即可自动从 Let’s Encrypt、ZeroSSL 等证书颁发机构签发、安装并自动续期 HTTPS (SSL/TLS) 证书。
2. 基础部署与高级安装
Section titled “2. 基础部署与高级安装”2.1. 方案 A:一键基础安装
Section titled “2.1. 方案 A:一键基础安装”curl https://get.acme.sh | sh -s email=my@example.com2.2. 方案 B:高度定制化安装 (推荐)
Section titled “2.2. 方案 B:高度定制化安装 (推荐)”自定义所有证书缓存与配置的落盘目录,方便集中隔离管理:
git clone --depth 1 https://github.com/acmesh-official/acme.sh.gitcd acme.sh
# 挂载定制化路径与身份邮箱./acme.sh --install -m example@gmail.com \ --home ~/myacme \ --config-home ~/myacme/data \ --cert-home ~/mycerts \ --accountemail "my@example.com" \ --accountkey ~/myaccount.key \ --accountconf ~/myaccount.conf \ --useragent "this is my client."
# 将 acme.sh 注入终端环境变量echo '. "/opt/software/acme.sh/acme.sh.env"' >> ~/.bashrc
# 强制切换默认 CA 机构为稳定的 Let's Encrypt (默认可能是 ZeroSSL)./acme.sh --set-default-ca --server letsencrypt3. 签发实战:基于 DNS API 自动认证
Section titled “3. 签发实战:基于 DNS API 自动认证”申请泛域名证书(如 *.example.com)必须使用 DNS 验证(通过向域名商自动插入 TXT 记录证明你对该域名的所有权)。
3.1. 场景 1:华为云 (Huawei Cloud)
Section titled “3.1. 场景 1:华为云 (Huawei Cloud)”首先在终端环境中注入云账号的 API Key/Secret 令牌:
export HUAWEICLOUD_Username="your_username"export HUAWEICLOUD_Password="your_password"export HUAWEICLOUD_DomainName="your_domain"
# 发起自动签发请求 (-d 参数可以叠加,涵盖根域与泛域名)./acme.sh --issue --dns dns_huaweicloud -d example.com -d *.example.com3.2. 场景 2:Cloudflare
Section titled “3.2. 场景 2:Cloudflare”export CF_Token="your_cf_api_token"export CF_Account_ID="your_account_id"
./acme.sh --issue --dns dns_cf -d example.com -d *.example.com4. 运维挂载:安装证书至 Web 服务
Section titled “4. 运维挂载:安装证书至 Web 服务”./acme.sh --install-cert -d example.com \ --cert-file /root/certs/example.com/cert.pem \ --key-file /root/certs/example.com/key.pem \ --fullchain-file /root/certs/example.com/fullchain.pem \ --reloadcmd "systemctl restart nginx"备注:Acme.sh 会记住这条 install-cert 指令。未来触发自动续期(Renew)完成后,它将自动再次执行拷贝操作,并触发最后一行 reloadcmd 以重启 Web 服务使新证书生效。
5. 其他高频操作
Section titled “5. 其他高频操作”强制手动续期 (测试用):
acme.sh --renew -d example.com --force