温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2021-10-09 14:56:12 来源:亿速云 阅读:179 作者:iii 栏目:编程语言

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

问题描述

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

解决方案

注意事项

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

on Debian GNU/Linux 10 (buster)

# 环境设置
apt update
apt install python3 python3-venv libaugeas0

# 安装 certbot 命令
python3 -m venv /srv/certbot/
/srv/certbot/bin/pip install --upgrade pip
/srv/certbot/bin/pip install certbot
ln -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-release
yum -y install yum-utils
yum-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 certbot
wget https://dl.eff.org/certbot-auto
mv certbot-auto /usr/local/bin/certbot-auto
chown root /usr/local/bin/certbot-auto
chmod 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证书”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI