千家信息网

如何安装并申请Let's Encrypt证书

发表于:2025-11-15 作者:千家信息网编辑
千家信息网最后更新 2025年11月15日,本篇内容介绍了"如何安装并申请Let's Encrypt证书"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有
千家信息网最后更新 2025年11月15日如何安装并申请Let's Encrypt证书

本篇内容介绍了"如何安装并申请Let's Encrypt证书"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

问题描述

该笔记将记录:在 Linux 中,如何安装 Certbot 工具,并使用它申请证书,以及相关问题的处理。

解决方案

注意事项

该部分内容属于简述,详细内容请参考 certbot instructions 官方页面,依据提示操作即可。以下是操作大致流程:
1)选择站点服务器软件,以及操作系统发行版
2)查看是否满足条件
3)依据提示安装软件包
4)执行命令生成证书
5)访问站点以检查证书是否生效
6)添加定时任务以实现证书自动续期

on Debian GNU/Linux 10 (buster)

# 环境设置apt updateapt install python3 python3-venv libaugeas0# 安装 certbot 命令python3 -m venv /srv/certbot//srv/certbot/bin/pip install --upgrade pip/srv/certbot/bin/pip install certbotln -s /srv/certbot/bin/certbot /usr/bin/certbot# 证书申请操作...# 定时任务,以完成证书自动续期echo "0 0,12 * * * root /srv/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew -q --post-hook 'systemctl reload nginx'" \    | sudo tee -a /etc/crontab > /dev/null

on CentOS 7.4 with PIP3.6

经验:这种东西就应该在虚拟环境里搞,但凡与应用有关且与系统管理无关的 Python 应用,都应该在虚拟环境里搞。要是在系统环境里搞,直接 yum install,pip2.7 install,等着吧,早晚有难受的时候。

我们并没有在虚拟环境里,因为系统没有使用 Python 3.6 环境,因此我们可以直接使用:

pip3.6 install certbot certbot-nginx certbot-dns-aliyun

Certbot 1.0.0 on CentOS 7.4

################################################################################# 安装 Certbot 工具################################################################################# 安装相关软件包yum install -y epel-releaseyum -y install yum-utilsyum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional# 安装并获取证书yum install certbot python2-certbot-nginx################################################################################# 申请证书并配置################################################################################# 申请 Nginx 证书,并自动修改 Nginx 配置certbot --nginx# 仅仅生成证书,不修改配置# certbot certonly --nginx# 配置证书自动续期echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && certbot renew" \    | tee -a /etc/crontab > /dev/null################################################################################# 验证配置正确################################################################################# 访问站点确认 HTTPS 是否生效

Certbot on Debian 8 (jessie)

################################################################################## 第一步、安装 Certbot 工具################################################################################apt-get remove certbotwget https://dl.eff.org/certbot-automv certbot-auto /usr/local/bin/certbot-autochown root /usr/local/bin/certbot-autochmod 0755 /usr/local/bin/certbot-auto################################################################################## 第二步、申请证书并配置################################################################################# 申请证书/usr/local/bin/certbot-auto --nginx# /usr/local/bin/certbot-auto certonly --nginx # 或者仅仅生成证书,不修改配置# 配置证书自动续期echo "0 0,12 * * * root python -c 'import random; import time; time.sleep(random.random() * 3600)' && /usr/local/bin/certbot-auto renew" \    | tee -a /etc/crontab > /dev/null################################################################################## 第三步、验证配置正确################################################################################# 访问站点,以确认 HTTPS 是否生效

附加说明

自动重启服务

在自动证书续期后,可能需要重启服务以加载证书:

certbot -q renew --renew-hook "/etc/init.d/nginx reload"

关于定时任务

定时任务用于完成证书续期。其中 sleep() 以秒为单位,random() 在 0-1 之间,因此每天 12:00、00:00 执行,在执行时,最多休眠 1 小时。

常见问题汇总

卡在 installing python packages 步骤

no response "Installing Python packages" #2516

问题描述:在Debian中,执行/usr/local/bin/certbot-auto --nginx命令后,它会调用pip命令安装相关Python包,这是时候会卡住。

问题原因:在执行pip命令时,它访问官方仓库,由于网络原因导致无法正常快速下载。

解决办法:修改$HOME/.pip/pip.conf文件,配置如下内容(使用阿里云镜像):

[global]index-url = http://mirrors.aliyun.com/pypi/simple/[install]trusted-host=mirrors.aliyun.com

"如何安装并申请Let's Encrypt证书"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!

0