“配置Let's Encrypt & certbot”的版本间的差异
来自个人维基
(以“由于我们拥有服务器的命令行访问权限,故直接使用 Certbot ACME 客户端。 它可以在不下线您的服务器的前提下自动执行证书颁...”为内容创建页面) |
|||
第3行: | 第3行: | ||
官网:https://certbot.eff.org | 官网:https://certbot.eff.org | ||
− | + | ||
+ | ===安装依赖包=== | ||
<pre> | <pre> | ||
sudo apt update | sudo apt update | ||
第9行: | 第10行: | ||
</pre> | </pre> | ||
− | 设置安装环境: | + | ===设置安装环境:=== |
<pre> | <pre> | ||
sudo python3 -m venv /opt/certbot/ | sudo python3 -m venv /opt/certbot/ | ||
第15行: | 第16行: | ||
</pre> | </pre> | ||
− | + | ===安装=== | |
sudo /opt/certbot/bin/pip install certbot certbot-apache | sudo /opt/certbot/bin/pip install certbot certbot-apache | ||
第21行: | 第22行: | ||
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot | sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot | ||
+ | ===获取证书并使用=== | ||
运行此命令获取证书并让Certbot自动编辑您的Apache配置以使用它(如果担心风险,可以在执行此步骤前备份 sites-enabled/000-default 和 sites-enabled/default-ssl): | 运行此命令获取证书并让Certbot自动编辑您的Apache配置以使用它(如果担心风险,可以在执行此步骤前备份 sites-enabled/000-default 和 sites-enabled/default-ssl): | ||
sudo certbot --apache | sudo certbot --apache | ||
+ | |||
+ | *如果这里报错“ValueError: Invalid version. The only valid version for X509Req is 0.”,则是 pyOpenSSL版本不匹配(如 pyOpenSSL 23.2.0),需要指定版本: | ||
+ | :<pre>/opt/certbot/bin/pip install pyOpenSSL==23.1.1</pre> | ||
至此,应该新的ssl证书就生效了(一般有效期是3个月)。 | 至此,应该新的ssl证书就生效了(一般有效期是3个月)。 | ||
+ | |||
+ | ===设置自动更新证书任务=== | ||
<pre> | <pre> | ||
echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null | echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null | ||
</pre> | </pre> | ||
− | 定期(官方建议Monthly)更新 | + | ===定期(官方建议Monthly)更新 certbot=== |
sudo /opt/certbot/bin/pip install --upgrade certbot certbot-apache | sudo /opt/certbot/bin/pip install --upgrade certbot certbot-apache | ||
如果出错: | 如果出错: | ||
If this step leads to errors, run sudo rm -rf /opt/certbot and repeat all installation instructions. | If this step leads to errors, run sudo rm -rf /opt/certbot and repeat all installation instructions. |
2025年2月5日 (三) 15:45的版本
由于我们拥有服务器的命令行访问权限,故直接使用 Certbot ACME 客户端。 它可以在不下线您的服务器的前提下自动执行证书颁发和安装。 对于不需要自动配置的用户,Certbot 还提供专家模式。
目录[隐藏] |
安装依赖包
sudo apt update sudo apt install python3 python3-venv libaugeas0
设置安装环境:
sudo python3 -m venv /opt/certbot/ sudo /opt/certbot/bin/pip install --upgrade pip
安装
sudo /opt/certbot/bin/pip install certbot certbot-apache
配置软链接,便于执行命令:
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
获取证书并使用
运行此命令获取证书并让Certbot自动编辑您的Apache配置以使用它(如果担心风险,可以在执行此步骤前备份 sites-enabled/000-default 和 sites-enabled/default-ssl):
sudo certbot --apache
- 如果这里报错“ValueError: Invalid version. The only valid version for X509Req is 0.”,则是 pyOpenSSL版本不匹配(如 pyOpenSSL 23.2.0),需要指定版本:
/opt/certbot/bin/pip install pyOpenSSL==23.1.1
至此,应该新的ssl证书就生效了(一般有效期是3个月)。
设置自动更新证书任务
echo "0 0,12 * * * root /opt/certbot/bin/python -c 'import random; import time; time.sleep(random.random() * 3600)' && sudo certbot renew -q" | sudo tee -a /etc/crontab > /dev/null
定期(官方建议Monthly)更新 certbot
sudo /opt/certbot/bin/pip install --upgrade certbot certbot-apache
如果出错:
If this step leads to errors, run sudo rm -rf /opt/certbot and repeat all installation instructions.