python acme_acme.sh 的简单使用

acme.sh 是纯 shell script 写的,它实现了 acme 协议, 可以从 letsencrypt 生成免费的证书。它不依赖于 python,也不需要 root 权限,而且支持不少云服务商,可以实现全自动证书生成与续期。

acme.sh 安装步骤如下:

wget -O – https://get.acme.sh | sh

该命令的输出大致如下:

[2020年 07月 08日 星期三 16:20:30 CST] Installing from online archive.

[2020年 07月 08日 星期三 16:20:30 CST] Downloading https://github.com/acmesh-official/acme.sh/archive/master.tar.gz

[2020年 07月 08日 星期三 16:20:34 CST] Extracting master.tar.gz

[2020年 07月 08日 星期三 16:20:34 CST] It is recommended to install socat first.

[2020年 07月 08日 星期三 16:20:34 CST] We use socat for standalone server if you use standalone mode.

[2020年 07月 08日 星期三 16:20:34 CST] If you don't use standalone mode, just ignore this warning.

[2020年 07月 08日 星期三 16:20:34 CST] Installing to /home/manjaro/.acme.sh

[2020年 07月 08日 星期三 16:20:34 CST] Installed to /home/manjaro/.acme.sh/acme.sh

[2020年 07月 08日 星期三 16:20:34 CST] Installing alias to '/home/manjaro/.zshrc'

[2020年 07月 08日 星期三 16:20:34 CST] OK, Close and reopen your terminal to start using acme.sh

[2020年 07月 08日 星期三 16:20:34 CST] Installing cron job

no crontab for manjaro

no crontab for manjaro

[2020年 07月 08日 星期三 16:20:34 CST] Good, bash is found, so change the shebang to use bash as preferred.

[2020年 07月 08日 星期三 16:20:35 CST] OK

[2020年 07月 08日 星期三 16:20:35 CST] Install success!

通过输出,我们应该明白,acme.sh 会安装到用户目录的 .acme.sh 下面,并且会在 .zshrc 或者 .bashrc 里添加别名,最后出创建一个 cron 任务,我们可以通过 crontab -e 查看,比如我的就如下:

34 0 * * * “/home/manjaro/.acme.sh”/acme.sh –cron –home “/home/manjaro/.acme.sh” > /dev/null

即 每天 0 点 34 分执行 /home/manjaro/.acme.sh”/acme.sh –cron –home “/home/manjaro/.acme.sh 至于 cron 表达式,以后有空再写。

接着 终端执行:

export Ali_Key="xxx"

export Ali_Secret="xxx"

acme.sh --issue --dns dns_ali -d *.kpromise.top

执行完毕以上命令,即可生成证书,之后,只需要修改下 nginx 配置即可,也支持其他云服务商,这里是以 阿里云 为例,且 key 和 secret 是你的子账号的,子账号需要有 管理云解析(DNS)的权限,其他云服务商,请参考:https://github.com/acmesh-official/acme.sh/wiki/dnsapi 目前支持 100多家,足够了。

nginx 配置大致如下:

server {

listen 443 ssl;

server_name www.kpromise.top;

ssl_certificate /root/.acme.sh/kpromise.top/fullchain.cer;

ssl_certificate_key /root/.acme.sh/kpromise.top/kpromise.top.key;

}

唯一的问题是 你需要 在 证书重新生成后,执行 nginx -s reload 不然还是旧证书,仅此而已!当然也可以使用它的 install 命令

acme.sh --install-cert -d kpromise.top

--cert-file /etc/nginx/certs/kpromise.top/cert

--key-file /etc/nginx/certs/kpromise.top/key

--fullchain-file /etc/nginx/certs/kpromise.top/fullchain

--reloadcmd "systemctl reload nginx.service"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值