V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
duke807
V2EX  ›  SSL

分享 Let's Encrypt SSL 每 80 天自動更新腳本,帶進度條指示

  •  
  •   duke807 · 2022-03-16 02:55:38 +08:00 · 2166 次点击
    这是一个创建于 734 天前的主题,其中的信息可能已经有所发展或是发生改变。

    因爲每次 renew 證書的時候,都要關閉一下 web 服務,網上用 cron 方式 renew 的太頻繁了,爲了減少掉線時間和次數,所以自己寫了一個腳本。

    一個很簡單的腳本,代碼:
    https://blog.d-l.io/auto-renew-letsencrypt

    開機的時候通過 screen 命令自動運行腳本,需要查看的時候用 screen -r 命令調閱:

    我一直很喜歡用 screen 工具把普通腳本當作 daemon 程序,看運行狀態比較方便,方便查錯和調試,可省掉一些複雜的 log 到文件的機制。

    8 条回复    2022-03-16 15:17:00 +08:00
    totoro625
        1
    totoro625  
       2022-03-16 10:18:33 +08:00
    为啥需要关闭一下 web 服务?
    我用的
    ```
    $ACME --issue \
    --dns dns_dp \
    --server zerossl \
    --challenge-alias acme.example.com \
    --keylength ec-256 \
    -d example.com \
    -d example2.com \
    -d *.example.com \
    -d *.example2.com
    ```
    每月 1 号运行一次 GitHub Actions ,推送证书到 COS
    需要的服务器 wget 回来
    konakona
        2
    konakona  
       2022-03-16 10:37:15 +08:00
    不用关闭 web 服务,申请证书成功后 web 服务 reload 下配置就好了。每次获取的证书难道不都是同名同姓的吗?
    mritd
        3
    mritd  
       2022-03-16 10:53:59 +08:00 via iPhone
    跑个题,要不要试试 Caddy
    duke807
        4
    duke807  
    OP
       2022-03-16 12:55:42 +08:00
    @konakona 查了一下,我沒有安裝插件 (the certbot apache plugin is not installed),我是用 --standalone 申請證書的,所以要關閉 web 服務,因爲 certbot 需要使用 web 端口。


    @totoro625 沒看懂你這個是什麼原理,certbot 不是需要在你域名所在服務器上運行才可以的嗎?
    ab
        5
    ab  
       2022-03-16 13:02:24 +08:00 via iPhone
    acme.sh 解千愁
    konakona
        6
    konakona  
       2022-03-16 13:35:22 +08:00
    @duke807 https://certbot.eff.org/instructions?ws=apache&os=ubuntubionic

    为什么会出现需要关闭 web 服务的现象?总感觉是用法不对。

    我 apache 、nginx ,用过 certbot 、lego 、traefik-acme ,都木有遇到过你这个情况耶。
    konakona
        7
    konakona  
       2022-03-16 13:40:47 +08:00
    或者你在 apache 里将 http challenge 的请求(一个路径 /.well-known/acme-challenge )做一个转发,也可以保障 web 服务不中断的情况下完成证书签发。

    https://letsencrypt.org/zh-cn/docs/allow-port-80/

    https://eff-certbot.readthedocs.io/en/stable/api/certbot.plugins.common.html?highlight=port#certbot.plugins.common.Addr.get_port
    totoro625
        8
    totoro625  
       2022-03-16 15:17:00 +08:00
    申请证书一般有两种方式验证: http 和 dns 验证
    http 方式需要服务器开启一个端口,验证 dns 的 ip 指向
    dns 方式, 在域名上添加一条 txt 解析记录, 验证域名所有权
    参考 acme.sh 的说明
    https://github.com/acmesh-official/acme.sh/wiki/%E8%AF%B4%E6%98%8E

    直接通过一个服务器申请全部证书最后分发到各个服务器即可

    我这边都是内网服务器,所以直接通过 GitHub Actions 生成了
    搜索排名第一的是这个教程: https://www.ioiox.com/archives/104.html
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5451 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 08:45 · PVG 16:45 · LAX 01:45 · JFK 04:45
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.