Certbot自动续签多域名

发布时间:2026/11/6 7:29:42
Certbot自动续签多域名 安装Certbotyuminstall-yepel-release yuminstall-ycertbot执行续签命令certbot certonly --preferred-challenges dns--manual-d*.domain1.com-ddomain1.com-d*.domain2.com-ddomain2.com-d*.domain3.com-ddomain3.com--serverhttps://acme-v02.api.letsencrypt.org/directory --register-unsafely-without-email --config-dircert按提示前往dns解析添加对应的值完成后回车生成的证书默认位置/etc/letsencrypt/archive/domain.com–config-dir 指定生成的目录位置一键更新certbot renew开启自动续订查看自己certbot和nginx的安装位置whichcertbotwhichnginx添加续订脚本sudovi/root/renew_nginx.sh写入以下内容注意对应的指令路径要和上面查出来的一致#!/bin/bash# 日志文件LOGFILE/var/log/certbot-renew.logCERTBOT/usr/bin/certbotNGINX/usr/local/nginx/sbin/nginxecho[$(date)] 开始证书续订检查...$LOGFILE# 如果指定了路径需要修改为下面的指令# if $CERTBOT renew --config-dir /usr/local/nginx/conf/cert目录 --quiet --no-random-sleep-on-renew; thenif$CERTBOTrenew--quiet--no-random-sleep-on-renew;thenecho[$(date)] 证书检查完成正在重载 Nginx...$LOGFILE$NGINX-sreloadecho[$(date)] Nginx 已重载$LOGFILEelseecho[$(date)] Certbot 续订失败$LOGFILEexit1fi保存退出添加可执行权限sudochmodx /root/renew_nginx.sh添加定时任务sudocrontab-e这个时候会弹出一个文本编辑器里面可能已经有内容了在下面插入一行新的内容添加每天凌晨两点半执行一次脚本的任务302* * * /root/renew_nginx.sh/var/log/certbot-cron.log21保存退出测试脚本是否可用sudo/root/renew_nginx.sh查看执行的日志sudotail-f/var/log/certbot-renew.log