安装acme.sh

curl  https://get.acme.sh | sh
  • acme.sh默认安装到了当前家目录。
[root@iZbp17hycbhnayg00ohec9Z ~]# ~/.acme.sh/
[root@iZbp17hycbhnayg00ohec9Z ~]# ll .acme.sh/
total 492
-rw-r--r-- 1 root root    296 Aug 15 14:28 account.conf
-rwxr-xr-x 1 root root 190583 Aug 15 14:28 acme.sh
-rw-r--r-- 1 root root     78 Aug 15 14:10 acme.sh.csh
-rw-r--r-- 1 root root     78 Aug 15 14:10 acme.sh.env
-rw-r--r-- 1 root root 269335 Aug 15 14:28 acme.sh.log
drwxr-xr-x 4 root root   4096 Aug 15 14:12 ca
drwxr-xr-x 2 root root   4096 Aug 15 14:28 deploy
drwxr-xr-x 2 root root   4096 Aug 15 14:28 dnsapi
-rw-r--r-- 1 root root   2777 Aug 15 14:28 http.header
drwxr-xr-x 2 root root   4096 Aug 15 14:28 notify
  • 此次安装,会在crontab创建定时任务。
[root@iZbp17hycbhnayg00ohec9Z ~]# crontab -l
5 0 * * * "/root/.acme.sh"/acme.sh --cron --home "/root/.acme.sh" > /dev/null

添加自动DNS验证

  • 需要阿里云添加子账号,并授权“管理云解析权限”,添加API,阿里云 AK 是使用阿里云子账户来添加的。
  • 其它自动DNS API验证方法参考:https://github.com/Neilpang/acme.sh/wiki/dnsapi

  • 设置阿里云子账号环境变量。

[root@iZbp17hycbhnayg00ohec9Z ~]# cat .bashrc
export Ali_Key="xxxx"
export Ali_Secret="xxx"
[root@iZbp17hycbhnayg00ohec9Z ~]# source .bashrc

申请证书

  • 申请证书
[root@iZbp17hycbhnayg00ohec9Z ~]# acme.sh --issue --dns dns_ali -d domain.com -d *.domain.com
  • 安装证书
acme.sh --install-cert -d domain.com -d *.domain.com\
  --key-file       /etc/nginx/sslkey/domain.com.key  \
  --fullchain-file /etc/nginx/sslkey/domain.com.pem \
  --reloadcmd     "/etc/init.d/nginx force-reload"
  • acme.sh自动更新
[root@iZbp17hycbhnayg00ohec9Z ~]# acme.sh  --upgrade  --auto-upgrade
[root@iZbp17hycbhnayg00ohec9Z ~]# cat .bashrc
. "/root/.acme.sh/acme.sh.env"
#证书列表
[root@iZbp17hycbhnayg00ohec9Z ~]# acme.sh list
Main_Domain  KeyLength  SAN_Domains   Created                       Renew
eoecfd.com   ""         *.domain.com  Thu Aug 15 06:13:10 UTC 2019  Mon Oct 14 06:13:10 UTC 2019
02-01 01:47