「Certbot」- 安装 @20210223

本文档介绍了如何在CentOS 7.4和Debian 8(jessie)上安装Certbot,申请Let's Encrypt SSL证书,并设置自动续期。涉及到的步骤包括安装Certbot及相关插件,通过Nginx配置获取证书,以及添加定时任务以确保证书的自动更新。同时,还提供了解决安装Python包时可能出现的网络问题的建议和配置阿里云镜像的解决方案。
部署运行你感兴趣的模型镜像

本笔记将介绍:如何安装 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

您可能感兴趣的与本文相关的镜像

Python3.10

Python3.10

Conda
Python

Python 是一种高级、解释型、通用的编程语言,以其简洁易读的语法而闻名,适用于广泛的应用,包括Web开发、数据分析、人工智能和自动化脚本

<think> 我们正在尝试解决使用yum安装python3-certbot-apache时提示“没有可用软件包”的问题。根据引用内容,我们可以注意到以下几点: 1. 引用[1]和[2]中提到使用`python2-certbot-apache`,这表明在yum仓库中可能存在python2版本的包,但没有直接提到python3版本。 2. 引用[5]中提到了安装`python2-certbot-nginx`,并且步骤中使用了`yum install python2-certbot-nginx`。同样,对于apache,可能仓库中只有python2的包。 3. 引用[3]和[4]中提到了在使用certbot时遇到的Python模块问题,这提示我们certbot对Python版本有依赖。 考虑到用户想要安装的是python3版本的certbot-apache,而yum仓库中可能没有提供,我们可以尝试以下步骤: ### 步骤1: 检查仓库中是否存在python3-certbot-apache 首先,我们可以通过yum命令搜索相关包: ```bash yum search python3-certbot-apache ``` 或者更广泛地搜索: ```bash yum search certbot-apache ``` 看看是否有python3版本的包。 ### 步骤2: 启用必要的仓库 如果步骤1没有找到,可能是因为没有启用包含该软件包的仓库。根据引用[5],我们可以启用以下仓库: ```bash yum-config-manager --enable rhui-REGION-rhel-server-extras rhui-REGION-rhel-server-optional ``` 然后更新yum缓存: ```bash yum makecache ``` 再尝试安装。 ### 步骤3: 安装EPEL仓库 EPEL(Extra Packages for Enterprise Linux)仓库提供了许多额外的软件包。根据引用[2]和[5],我们需要安装EPEL仓库: ```bash yum install epel-release ``` 然后更新yum缓存,并再次尝试安装。 ### 步骤4: 使用certbot-auto脚本 如果yum仓库中确实没有python3-certbot-apache,我们可以考虑使用certbot官方提供的certbot-auto脚本。该脚本会自动安装正确版本的certbot及其依赖(包括Python3环境)。引用[2]和[5]提到了下载和使用certbot-auto。 下载certbot-auto: ```bash wget https://dl.eff.org/certbot-auto chmod a+x certbot-auto ``` 然后运行(针对apache): ```bash ./certbot-auto --apache ``` 注意:certbot-auto在运行时会自动安装所需的依赖,包括Python3环境。 ### 步骤5: 使用pip安装 如果上述方法都不行,可以考虑使用pip安装。但请注意,使用pip安装可能会遇到依赖问题,特别是系统级别的依赖(如apache或nginx的开发包)。根据引用[4],我们需要注意requests库的版本问题。 首先,确保安装了Python3和pip3。然后,我们可以尝试: ```bash pip3 install certbot certbot-apache ``` 但是,这种方法可能缺少一些系统依赖,因此需要根据错误信息安装相应的包。 ### 总结解决方案 1. 首先尝试启用额外仓库并安装EPEL,然后通过yum安装。 2. 如果yum仓库中没有,则使用certbot-auto脚本。 3. 最后考虑使用pip安装,但需注意系统依赖。 §§相关问题§§ 1. 如何启用EPEL仓库? 2. 使用certbot-auto脚本有哪些注意事项? 3. 如何解决pip安装certbot时的依赖问题? </think> ### 解决yum安装python3-certbot-apache提示"没有可用软件包"的方法 这个问题通常是由于缺少合适的软件仓库或软件包命名差异导致的。以下是完整的解决步骤: #### 1. **启用EPEL仓库** EPEL (Extra Packages for Enterprise Linux) 仓库包含许多额外的软件包: ```bash sudo yum install epel-release sudo yum update ``` #### 2. **启用PowerTools仓库**(CentOS 8/RHEL 8) ```bash sudo yum config-manager --set-enabled PowerTools # CentOS 8 # 或 sudo dnf config-manager --set-enabled PowerTools # RHEL 8 ``` #### 3. **添加Certbot官方仓库** ```bash sudo yum install -y yum-utils sudo yum-config-manager --add-repo https://repos.certbot.io/certbot/certbot.repo sudo yum update ``` #### 4. **尝试替代安装方案** 如果仍找不到python3-certbot-apache,可尝试: ```bash # 方案1:安装Python3版本的Certbot基础包 sudo yum install python3-certbot # 方案2:直接安装certbot-apache(自动处理Python依赖) sudo yum install certbot-apache # 方案3:使用pip安装(确保已安装Python3和pip) sudo pip3 install certbot certbot-apache ``` #### 5. **验证安装** ```bash certbot --version # 应显示类似:certbot 2.6.0 ``` #### 6. **配置Apache证书** ```bash sudo certbot --apache -d yourdomain.com ``` > **关键提示**:根据引用[5],在配置前需确保Apache已正确设置`Listen 443`和`NameVirtualHost *:443`(编辑`/etc/httpd/conf/httpd.conf`)[^5]。 --- ### 常见问题解决 1. **依赖错误**(如引用[4]的requests模块错误): ```bash sudo pip3 install --upgrade --force-reinstall requests urllib3 ``` 2. **续期错误**(如引用[3]的UnrewindableBodyError): ```bash sudo yum update python* certbot* sudo certbot renew --dry-run ``` 3. **兼容性问题**: ```bash # 如果存在Python2残留冲突(引用[1]) sudo yum remove python2-certbot* ``` > **注意**:根据引用[2][^2][^5],不同服务器环境(Nginx/Apache)需要安装对应的插件包,请确保选择正确的软件包。
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值