华为云 acme.sh 使用

阅读 (682)
免费的域名通配https证书

1.安装acme.sh

这里我安装到/root目录

cd /rootcurl  https://get.acme.sh | sh -s email=my@example.com

有时请求会超时,可换wget方式

wget -O -  https://get.acme.sh | sh -s email=my@example.com

2.建立软连接

alias acme.sh=/root/.acme.sh/acme.sh

这里注意,该文件夹前面带点,查看目录使用

ls -a

3.查看及编辑对应云服务商dns配置

cd /root/.acme.sh/dnsapi

这里有很多dns服务商的脚本,找到你对应的服务商,比如阿里云是 dns_ali.sh

vi dns_ali.sh 

可以用vi命令编缉查看

对应的配置项是:

Ali_Key="LTqIA87hOKdjevsf5"
Ali_Secret="0p5EYueFNq501xnCPzKNbx6K51qPH2"

华为云是:

dns_huaweicloud.sh

对应的配置项是:

HUAWEICLOUD_Username
HUAWEICLOUD_Password
HUAWEICLOUD_DomainNamet

每家服务商的配置可能不一样,找到自己域名服务商对应的api配置进行配置

可以用export设置全局变量

也可以在编辑对应dnsapi文件时,直接将变量赋值,例如华为云

vim /root/.acme.sh/dnsapi/dns_huaweicloud.sh 
HUAWEICLOUD_Username=test123   # 从华为云控制台找 在华为云的“我的凭证”中,是“帐号名”
HUAWEICLOUD_Password=123123123 # 就是你华为云登录的密码
HUAWEICLOUD_DomainName=test123 # 从华为云控制台找,在华为云的“我的凭证”中,也是“帐号名”,这里我其实也没太明白为什么都是“帐号名”

4.申请证书命令中的参数说明

--issue 使用dns脚本必须要用这个参数
--dns dns_huaweicloud 使用华为脚本 -d returnc.com主域名 -d '*.returnc.com' 申请泛域名证书 --post-hook 在证书申请成功后要执行的操作--renew-hook 在证书自动续期后要执行的操作--install-cert 安装证书
--key-file 复制到指定位置 --fullchain-file 复制到指定位置 --reloadcmd 安装完成后要执行的命

默认ca服务商是ZeroSSL但我用华为云的脚本尝试了几次都超时了,所以后来改了默认服务商,改成letsencrypt

4.1设置默认ca服务商

acme.sh --set-default-ca --server letsencrypt 

4.2 也可以在申请时加上参数:

 --server letsencrypt

5.发布和安装二合一,所以最后要执行的命令就是

acme.sh --issue --dns dns_huaweicloud -d returnc.com -d '*.returnc.com' \
--post-hook "acme.sh --install-cert -d returnc.com --key-file /usr/local/nginx/conf/ssl/returnc.key.pem --fullchain-file /usr/local/nginx/conf/ssl/returnc.cert.pem --reloadcmd \"service nginx restart\"" \
--renew-hook "acme.sh --install-cert -d returnc.com --key-file /usr/local/nginx/conf/ssl/returnc.key.pem --fullchain-file /usr/local/nginx/conf/ssl/returnc.cert.pem --reloadcmd \"service nginx restart\"" 

上述命令中,我在使用时 --post-hook 或者 --renew-hook这一步执行错误,这里也可以单步执行

acme.sh --issue --dns dns_huaweicloud --server letsencrypt -d returnc.com -d '*.returnc.com'
acme.sh --install-cert -d returnc.com --key-file /usr/local/nginx/conf/ssl/returnc.key.pem --fullchain-file /usr/local/nginx/conf/ssl/returnc.cert.pem --reloadcmd "service nginx restart"

至于错误原因,也许是路径问题,按照其他博主写的文章,可能--post-hook中 acme.sh应该写绝对路径

acme.sh --issue --dns dns_huaweicloud --server letsencrypt -d returnc.com -d '*.returnc.com' \
--post-hook "/root/.acme.sh/acme.sh --install-cert -d returnc.com --key-file /usr/local/nginx/conf/ssl/returnc.key.pem --fullchain-file /usr/local/nginx/conf/ssl/returnc.cert.pem --reloadcmd \"service nginx restart\"" \
--renew-hook "/root/.acme.sh/acme.sh --install-cert -d returnc.com --key-file /usr/local/nginx/conf/ssl/returnc.key.pem --fullchain-file /usr/local/nginx/conf/ssl/returnc.cert.pem --reloadcmd \"service nginx restart\""
 

这个问题需要再验证一下,另外有说--reloadcmd "service nginx restart"不生效,需要用“service nginx force-reload”,这个情况我没遇到,如果有service nginx restart不生效,可以试下service nginx force-reload

6.其它命令

#查看证书列表
acme.sh --list

#查看证书信息
openssl x509 -noout -text -in fullchain.cer

acme.sh --info -d returnc.com

#吊销证书
acme.sh --revoke --domain returnc.com

#从列表中删除证书
acme.sh --remove -d returnc.com

#acme.sh脚本升级acme.sh --upgrade
#acme.sh脚本开启自动升级 acme.sh --upgrade --auto-upgrade
更新于:2022-12-20 16:15:12
返回顶部