6-25
Wednesday
标签
梦涛笔记

CentOS Certbot SSL

HTML CentOS Apache 发布时间:2025-05-29 17:16:47

安装命令

yum install certbot

获取证书命令

certbot certonly --manual -m jason@zhisg.com -d *.zhisg.com
certbot certonly --webroot -w /var/www/html/zhisg/ -d www.zhisg.com
certbot renew   #继订全部证书
certbot renew --cert-name domain.com  #指定证书
certbot certificates                                         # 列出当前系统上所有由 Certbot 管理的证书
certbot delete --cert-name domain.com       # 删除指定的证书及其配置


certonly 表示安装模式,Certbot 有安装模式和验证模式两种类型的插件。
–manual 表示手动安装插件,Certbot 有很多插件,不同的插件都可以申请证书,用户可以根据需要自行选择
-d 为那些主机申请证书,如果是通配符,输入 *.domain.com (替换为你自己的域名)
–preferred-challenges dns,使用 DNS 方式校验域名所有权
–server,Let’s Encrypt ACME v2 版本使用的服务器不同于 v1 版本,需要显示指定。
评论:
Jason
2025-05-31 15:34:16

使用DNS方式校验时,阿里云DNS自动解析脚本:

vi /home/certbot-dns-aliyun.sh
ALI_ID="id"
ALI_SECRET="secret"

if [ "$1" = "delete" ]; then
    curl -sX DELETE "https://www.zhisg.com/route.php/ddns/ali/acme_challenge?id=$ALI_ID&secret=$ALI_SECRET&domain=$CERTBOT_DOMAIN"
else
    curl -sX GET "https://www.zhisg.com/route.php/ddns/ali/acme_challenge?id=$ALI_ID&secret=$ALI_SECRET&domain=$CERTBOT_DOMAIN&txt=$CERTBOT_VALIDATION"
fi
chmod +x /home/certbot-dns-aliyun.sh

获取证书命令:

certbot certonly --manual --preferred-challenges dns --manual-auth-hook /home/certbot-dns-aliyun.sh  -d *.domain.com --manual-cleanup-hook "/home/certbot-dns-aliyun.sh delete"

更新证书命令

certbot renew --cert-name domain.com --post-hook 'systemctl reload httpd'

--post-hook 为证书续签成功自动执行的指令操作,实现自动化重载证书