acme.sh自动续签证书

温馨提醒

一、安装 acme.sh

1
2
3
4
5
6
7
# 方法一
curl https://get.acme.sh | sh -s email=my@example.com

# 方法二
git clone https://github.com/acmesh-official/acme.sh.git
cd acme.sh
./acme.sh --install -m xxxx@xxx.com

二、更新版本

1
2
3
4
5
6
7
8
# 手动升级
acme.sh --upgrade

# 自动升级
acme.sh --upgrade --auto-upgrade

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

三、设置服务商

1
2
3
4
5
# 设置服务商 zerossl 或 letsencrypt
acme.sh --set-default-ca --server zerossl

# 关联下自己的邮箱
acme.sh --register-account -m acurd_com@163.com --server zerossl

四、生成证书

acme.sh 支持两种方式验证域名所有权:HTTP 和 DNS,推荐用 DNS 方式验证。

  • 阿里云

    1
    2
    3
    4
    5
    6
    7
    8
    
    export Ali_Key="xxxxxxx"
    export Ali_Secret="xxxxxxxxxxxx"
    
    # 生成单域名证书
    acme.sh --issue --dns dns_ali -d domain.com -d www.domain.com
    
    # 生成泛域名证书
    acme.sh --issue --dns dns_ali -d domain.com -d '*.domain.com' --force

    证书生成后,会自动保存 API_ID 和 APK KEY 到 ~/.acme.sh/account.conf 文件中

  • 华为云

    1
    2
    3
    4
    5
    6
    7
    
    export HUAWEICLOUD_Username=xxx		# IAM用户名
    export HUAWEICLOUD_Password=xxxx	# 账号登录密码
    export HUAWEICLOUD_DomainName=test	# 账号名
    
    acme.sh --issue --dns dns_huaweicloud -d test.com -d *.test.com
    
    acme.sh --install-cert -d test.com --key-file /etc/nginx/ssl/test.com/test.com.key --fullchain-file /etc/nginx/ssl/test.com/test.com.pem --reloadcmd "systemctl reload nginx"
  • 腾讯云

    1
    2
    3
    4
    5
    6
    
    export Tencent_SecretId="XXXXXXXXXXXXXXXX"
    export Tencent_SecretKey="XXXXXXXXXXXXXXXXXXXXXX"
    
    acme.sh --issue --dns dns_tencent -d test.com -d *.test.com
    
    acme.sh --install-cert -d test.com --key-file /etc/nginx/ssl/test.com/test.com.key --fullchain-file /etc/nginx/ssl/test.com/test.com.pem --reloadcmd "systemctl reload nginx"

五、安装证书

默认生成的证书都存放到 ~/.acme.sh/DOMAIN/ 目录下,使用 –install-cert 命令会把证书复制到相应的位置

1
2
3
4
5
# Apache
acme.sh --install-cert -d domain.com --cert-file /etc/httpd/ssl/domain.com/cert.pem --key-file /etc/httpd/ssl/domain.com/key.pem --fullchain-file /etc/httpd/ssl/domain.com/fullchain.pem --reloadcmd "service apache2 force-reload"

# Nginx
acme.sh --install-cert -d domain.com --key-file /etc/nginx/ssl/domain.com/key.pem --fullchain-file /etc/nginx/ssl/domain.com/cert.pem --reloadcmd "systemctl reload nginx"

六、撤消证书

1
2
3
4
5
6
7
# 撤销一个证书
acme.sh --list
acme.sh --revoke -d domain.com

# 删除一个证书
acme.sh --list
acme.sh --remove -d domain.com