acme.sh从 letsencrypt 生成SSL免费证书并自动更新证书

acme.sh 实现了 acme 协议, 可以从 letsencrypt 生成免费的证书

ACME 协议:
Automatic Certificate Management Environment 自动化证书管理环境

文档:

1、安装acme.sh

方式一:从github安装

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

# 或者
wget -O -  https://get.acme.sh | sh -s email=[email protected]

方式二:如果国内网络环境不好,可以从gitee下载安装

https://gitee.com/neilpang/acme.sh

wget https://gitee.com/neilpang/acme.sh/repository/archive/master.zip
unzip master.zip

cd acme.sh-master

./acme.sh --install \
--email [email protected]

安装过程中会 自动完成 以下操作

1、安装目录:~/.acme.sh

$ ls ~/.acme.sh
account.conf  
acme.sh  
acme.sh.csh  
acme.sh.env  
deploy  
dnsapi  
notify

2、执行文件路径:~/.acme.sh/acme.sh

3、环境变量修改

$ cat ~/.bashrc
. "~/.acme.sh/acme.sh.env"

$ cat ~/.cshrc
source "~/.acme.sh/acme.sh.csh"

$ cat ~/.tcshrc
source "~/.acme.sh/acme.sh.csh"

4、添加crontab定时任务

12 0 * * * "~/.acme.sh"/acme.sh --cron --home "~/.acme.sh" > /dev/null

查看安装结果

$ source ~/.bashrc

$ acme.sh --version
https://github.com/acmesh-official/acme.sh
v3.0.5

2、申请证书

Webroot模式

acme.sh --issue \
--domain example.com \
--domain www.example.com \
--webroot /home/wwwroot/example.com

每60天会自动更新

3、安装/copy证书

acme.sh --install-cert \
--domain example.com \
--key-file       /usr/local/nginx/conf/ssl/www.example.com.key  \
--fullchain-file /usr/local/nginx/conf/ssl/www.example.com.pem \
--reloadcmd     "service nginx force-reload"

4、其他命令

# 查看帮助
acme.sh -h

# 查看证书列表
acme.sh --list
Main_Domain  KeyLength  SAN_Domains  CA           Created               Renew
example.com      "2048"     www.example.com  ZeroSSL.com  2023-04-05T12:54:46Z  2023-06-04T12:54:46Z

# 查看域名配置
acme.sh --info --domain example.com

# 切换默认证书申请服务器
# 默认使用 ZeroSSL,以下示例切换 Let's Encrypt
acme.sh  --set-default-ca  --server letsencrypt

猜你喜欢

转载自blog.csdn.net/mouday/article/details/129978475