AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1062849
Accepted
Walf
Walf
Asked: 2021-05-07 20:31:09 +0800 CST2021-05-07 20:31:09 +0800 CST 2021-05-07 20:31:09 +0800 CST

使用 Let's Encrypt certbot 时,如何仅在证书实际更新时才重新启动/重新加载网络服务?

  • 772

该certbot命令提供了两个在自动续订后运行的挂钩,来自文档:

 --post-hook POST_HOOK
                       Command to be run in a shell after attempting to
                       obtain/renew certificates. Can be used to deploy
                       renewed certificates, or to restart any servers that
                       were stopped by --pre-hook. This is only run if an
                       attempt was made to obtain/renew a certificate. If
                       multiple renewed certificates have identical post-
                       hooks, only one will be run. (default: None)
 --deploy-hook DEPLOY_HOOK
                       Command to be run in a shell once for each
                       successfully issued certificate. For this command, the
                       shell variable $RENEWED_LINEAGE will point to the
                       config live subdirectory (for example,
                       "/etc/letsencrypt/live/example.com") containing the
                       new certificates and keys; the shell variable
                       $RENEWED_DOMAINS will contain a space-delimited list
                       of renewed certificate domains (for example,
                       "example.com www.example.com" (default: None)

这个问题在这个(现已关闭的)LE 线程中进行了概述,基本上是关于最大限度地减少对服务的中断。POST_HOOK每次尝试更新时都会执行,即使没有颁发证书,但只有一次。这使得不必要地重新启动服务成为可能。DEPLOY_HOOK为每个成功的证书续订运行。如果一个人使用DEPLOY_HOOK, 并且有多个证书,则每个服务可能会在一次足够的情况下重新启动多次。有关更新挂钩的更多信息,请点击此处。

我使用一种完全不会中断我的服务的发行方法,例如:

certbot certonly --webroot ...

或者

certbot certonly --dns-PROVIDER ...

我只想重新启动/重新加载每个依赖服务一次,并且只有在其证书实际更改的情况下。

certbot lets-encrypt ssl-certificate-renewal
  • 1 1 个回答
  • 3314 Views

1 个回答

  • Voted
  1. Best Answer
    Walf
    2021-05-07T20:31:09+08:002021-05-07T20:31:09+08:00

    通过使用两个钩子和一个简单的脚本来保存状态,我能够克服这个限制。例如,要重新加载 nginx,并在他们都使用的证书被更新时重新启动 vsftpd:

    certbot certonly ... \
        --deploy-hook '/usr/local/sbin/read-new-certs-services nginx --restart vsftpd' \
        --post-hook /usr/local/sbin/read-new-certs-services
    

    脚本/usr/local/sbin/read-new-certs-services是这样的:

    #!/bin/sh
    
    run_base=/run
    dir_reloads="$run_base/new-cert-reloads"
    dir_restarts="$run_base/new-cert-restarts"
    
    if [ $# -gt 0 ]; then
        some=0
        dir="$dir_reloads"
        while [ $# -gt 0 ]; do
            case $1 in
                -h|--help)
                    >&2 cat <<-'EOHELP'
                        Usage:
    
                          read-new-certs-services [-l|-s] service1 [[-l|-s] service2]
                          or
                          read-new-certs-services
    
                          When called without arguments, marked services will be reloaded or restarted.
    
                        Arguments:
    
                          -h, --help
                            This help.
    
                          -l, --reload
                            Mark all subsequently listed services for reloading. This is the default.
    
                          -s, --restart
                            Mark all subsequently listed services for restarting.
                        EOHELP
                    exit
                    ;;
                -l|--reload)
                    dir="$dir_reloads"
                    ;;
                -s|--restart)
                    dir="$dir_restarts"
                    ;;
                *)
                    if [ -n "$1" ]; then
                        some=1
                        run_file="$dir/$1"
                        if [ ! -f "$run_file" ] && ! install -D /dev/null "$run_file"; then
                            >&2 echo "Service could not be marked: $run_file"
                            exit 1
                        fi
                    fi
                    ;;
            esac
            shift
        done
        if [ $some -eq 0 ]; then
            >&2 echo 'No service(s) specified.'
            exit 1
        fi
        exit
    fi
    
    if [ -d "$dir_restarts" ]; then
        find "$dir_restarts" -mindepth 1 -printf '%P\t%p\n' | while IFS="$(printf '\t')" read -r svc run_file; do
            systemctl restart "$svc" && rm "$run_file"
            # no need to reload as well if restarting
            run_file="$dir_reloads/$svc"
            if [ -f "$run_file" ]; then
                rm "$run_file"
            fi
        done
    fi
    
    if [ -d "$dir_reloads" ]; then
        find "$dir_reloads" -mindepth 1 -printf '%P\t%p\n' | while IFS="$(printf '\t')" read -r svc run_file; do
            systemctl reload "$svc" && rm "$run_file"
        done
    fi
    

    这必须用于每个证书问题,以便他们不会使用冲突的重新启动服务的方法。

    您可以更改现有证书续订以使用此方法,方法是编辑其/etc/letsencrypt/renewal/*.conf文件以包含如下[renewalparams]部分中的钩子:

    renew_hook = /usr/local/sbin/read-new-certs-services nginx -s vsftpd
    post_hook = /usr/local/sbin/read-new-certs-services
    
    • 1

相关问题

  • Certbot 允许在 443 以外的不同端口上加密

  • 无法在 ubuntu 14 服务器上运行 certbot 进行加密

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve