「Certbot」- 安装 @20210223

本笔记将介绍:如何安装 Certbot 工具;如何使用它获取证书;如何处理在操作过程中遇到的问题。

注意事项

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

CentOS 7.4, PIP3.6 and Certbot

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

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

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

CentOS 7.4 and Certbot 1.0.0

#!/bin/sh

################################################################################
# 安装 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 是否生效

Debian 8 (jessie)

#!/bin/sh

################################################################################
# 安装 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是否生效

常见问题汇总

#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

附加说明

自动重启服务

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

#!/bin/sh

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

相关文章

「Certbot」- 在内网中申请证书的方法
「Certbot」- SERVFAIL looking up CAA for
「Certbot」- ocsp.int-x3.letsencrypt.org Read timed out
「Certbot」- ImportError: 'pyOpenSSL' module missing required functionality
「Certbot」- The manual plugin is not working

参考文献

certbot instructions
Let’s Encrypt: Reload Nginx after Renewing Certificates
Let's Encrypt and Certbot

猜你喜欢

转载自blog.csdn.net/u013670453/article/details/113984813