Let's Encrypt证书自动续期的设置方法主要依赖于Certbot工具,该工具是Let's Encrypt官方推荐的客户端,用于获取和续订SSL证书。以下是详细的设置步骤:
一、安装Certbot
-
Ubuntu/Debian系统:
- 更新系统:
sudo apt update && sudo apt upgrade -y
- 安装Certbot:
sudo apt install certbot python3-certbot-nginx
(如果使用Apache,则替换为python3-certbot-apache
)
- 更新系统:
-
CentOS/RHEL系统:
- 安装EPEL仓库:
sudo yum install epel-release
- 安装Certbot:
sudo yum install certbot python3-certbot-nginx
(如果使用Apache,则替换为python3-certbot-apache
)
- 安装EPEL仓库:
-
Fedora系统:
- 安装Certbot:
sudo dnf install certbot python3-certbot-nginx
(如果使用Apache,则替换为python3-certbot-apache
)
- 安装Certbot:
-
使用Snap安装(适用于支持Snap的系统):
- 安装Snap:
sudo apt install snapd
- 安装Certbot:
sudo snap install --classic certbot
- 创建软链接:
sudo ln -s /snap/bin/certbot /usr/bin/certbot
- 安装Snap:
二、申请证书
- 使用Nginx:
sudo certbot --nginx -d example.com -d www.example.com
- 使用Apache:
sudo certbot --apache -d example.com -d www.example.com
- 独立模式:
sudo certbot certonly --standalone -d example.com
(确保80端口未被占用)
三、配置自动续期
-
测试续期:
- 运行
sudo certbot renew --dry-run
以测试续期过程,确保没有错误。
- 运行
-
设置定时任务:
- 编辑cron作业:
sudo crontab -e
- 添加以下行以每天凌晨2点执行续期检查:
0 2 * * * /usr/bin/certbot renew --quiet
--quiet
参数表示仅在出现问题时输出信息。
- 编辑cron作业:
-
重新加载Web服务器:
- 对于Nginx,添加
&& systemctl reload nginx
到cron作业中。 - 对于Apache,添加
&& systemctl reload apache2
到cron作业中。
- 对于Nginx,添加
四、注意事项
- 防火墙设置:确保开放80和443端口,以便Let's Encrypt进行域名验证和证书续期。
- 证书有效期:Let's Encrypt证书的有效期为90天,Certbot会在证书过期前自动尝试续订。
- 日志检查:定期检查
/var/log/letsencrypt/
目录下的日志文件,确保续订过程顺利进行。
五、其他工具和方法
- 宝塔面板:在宝塔面板中,可以通过计划任务添加Shell脚本实现自动续期。
- Certimate:专业的SSL证书自动续签、部署工具,支持多种DNS服务商和部署方式。
- Httpsok:专为Nginx和OpenResty服务器设计的HTTPS证书自动续签工具。
Certimate 是一个开源的 SSL 证书管理工具,可以帮助用户自动申请、部署 SSL 证书,并在证书即将过期时自动续期。以下是 Certimate 工具的使用步骤:
一、安装 Certimate
Certimate 支持多种安装方式,用户可以根据自身需求选择适合的方式:
-
二进制文件安装
- 从 Certimate 的 GitHub Releases 页面下载对应操作系统的预编译二进制文件。
- 解压下载的文件,在终端中进入到解压缩后的目录。
- 执行
./certimate serve
命令启动服务。
注意:在 MacOS 上执行二进制文件时,可能会提示无法打开,因为 Apple 无法检查其是否包含恶意软件。此时,可在“系统设置 > 隐私与安全性 > 安全性”中点击“仍然允许”,然后再次尝试执行二进制文件。
-
Docker 安装
- 确保系统已安装 Docker 环境。
- 在终端中执行以下命令拉取 Certimate 的 Docker 镜像:
docker pull usual2970/certimate
。 - 使用以下命令启动容器:
docker run -d -p 8090:8090 usual2970/certimate serve
。
-
源代码安装
- 克隆 Certimate 的 GitHub 仓库:
git clone https://github.com/usual2970/certimate.git
。 - 进入克隆的目录:
cd certimate
。 - 执行
go run main.go serve
命令启动服务。
- 克隆 Certimate 的 GitHub 仓库:
二、使用 Certimate
-
访问管理页面
- 安装完成后,在浏览器中访问
http://127.0.0.1:8090
即可进入 Certimate 管理页面。 - 使用默认的管理员账号和密码登录(账号:
admin@certimate.fun
,密码:1234567890
)。
- 安装完成后,在浏览器中访问
-
配置域名和 DNS 提供商信息
- 在管理页面中,添加需要申请 SSL 证书的域名以及对应的 DNS 提供商信息。
- Certimate 会通过自动添加一个 TXT 记录的方式进行 DNS 验证,以证明域名的所有权。
-
申请和部署 SSL 证书
- 配置完成后,Certimate 会自动向证书颁发机构(如 Let's Encrypt)发起 SSL 证书的申请请求。
- 证书申请完成后,Certimate 可以将 SSL 证书自动部署到指定的平台,如阿里云 CDN、腾讯云 CDN 或本地服务器等。
-
自动续期
- Certimate 会每天检查证书的有效期,并在证书即将过期时自动进行续期申请。
- 用户无需进行额外操作,即可确保 SSL 证书的持续有效性。
三、注意事项
- 数据安全:由于 Certimate 支持私有部署,所有数据均存储在本地,确保数据的安全性。
- 支持的服务商:Certimate 支持多个 DNS 和托管服务商,包括阿里云、腾讯云、Cloudflare 等,方便用户跨平台部署 SSL 证书。
- 配置灵活性:用户可以根据自身需求,在 Certimate 管理页面中灵活配置域名、DNS 提供商信息以及部署目标等。