certbot-auto 脚本

这个错误表示系统中找不到 certbot-auto 脚本 —— 因为 certbot-auto 已被官方废弃(自 2021 年起),不再推荐使用,现在需要通过系统包管理器或官方仓库安装标准 certbot 工具。

以下是不同系统的 免费、合规安装方案,适配 IT 运维场景(支持 Nginx/Apache 等 Web 服务器,用于 Let’s Encrypt 证书申请 / 自动续期):

一、先卸载旧版(若曾安装过 certbot-auto)

如果之前手动下载过 certbot-auto,先清理避免冲突:

bash

运行

# 1. 删除旧脚本(若存在)
sudo rm -f /usr/sbin/certbot-auto /usr/local/bin/certbot-auto

# 2. 清理残留依赖(可选)
sudo apt-get purge certbot-auto 2>/dev/null || sudo yum remove certbot-auto 2>/dev/null

二、按系统选择安装 certbot(推荐方案)

场景 1:Ubuntu/Debian 系统(最常用,如 Ubuntu 20.04+/Debian 10+)

bash

运行

# 1. 更新软件源
sudo apt update

# 2. 安装 certbot(及 Web 服务器插件,二选一)
# 若用 Nginx:
sudo apt install -y certbot python3-certbot-nginx

# 若用 Apache:
sudo apt install -y certbot python3-certbot-apache

场景 2:CentOS/RHEL 系统(CentOS 7/8、RHEL 8+)

CentOS 7 需先启用 EPEL 源,CentOS 8 直接安装:

bash

运行

# 1. CentOS 7 专用:安装 EPEL 源
sudo yum install -y epel-release

# 2. 安装 certbot(及 Web 服务器插件,二选一)
# 若用 Nginx:
sudo yum install -y certbot python3-certbot-nginx

# 若用 Apache:
sudo yum install -y certbot python3-certbot-apache

场景 3:其他系统(如 Fedora、Rocky Linux)或无 root 权限

用 Python pip 安装(需先安装 Python3 和 pip):

bash

运行

# 1. 安装依赖(以 Ubuntu 为例,其他系统替换 apt 为 yum/dnf)
sudo apt install -y python3 python3-pip

# 2. 用 pip 安装 certbot(全局可用)
sudo pip3 install certbot certbot-nginx  # Nginx 插件
# 或 Apache 插件:sudo pip3 install certbot certbot-apache

三、验证安装 & 运维常用操作

1. 确认 certbot 可用

bash

运行

certbot --version  # 输出类似:certbot 2.6.0 表示安装成功

2. 申请 Let’s Encrypt 证书(自动配置 Web 服务器)

bash

运行

# Nginx 用户:自动获取证书并配置 Nginx
sudo certbot --nginx -d your-domain.com -d www.your-domain.com

# Apache 用户:自动获取证书并配置 Apache
sudo certbot --apache -d your-domain.com -d www.your-domain.com
  • 按提示输入邮箱(用于证书到期提醒)、同意协议、选择是否重定向 HTTP 到 HTTPS 即可。

3. 证书自动续期(运维核心需求)

Let’s Encrypt 证书有效期 90 天,certbot 会自动配置定时任务(cron),无需手动续期:

bash

运行

# 验证续期功能
sudo certbot renew --dry-run  # 输出 "No renew failures" 表示正常

4. 查看 / 管理证书

bash

运行

# 列出已申请的证书
sudo certbot certificates

# 吊销证书(如需)
sudo certbot revoke --cert-path /etc/letsencrypt/live/your-domain.com/cert.pem

四、常见问题排查

  1. 找不到 certbot 命令
    • 若用 pip 安装,可能是路径问题,执行 sudo ln -s /usr/local/bin/certbot /usr/bin/certbot 建立软链接。
  2. Web 服务器插件安装失败
    • 换用 “手动模式” 申请证书(适合自定义配置):sudo certbot certonly --manual -d your-domain.com,按提示验证域名后,手动将证书文件(默认在 /etc/letsencrypt/live/your-domain.com/)配置到 Web 服务器。
  3. CentOS 7 安装 EPEL 源失败
    • 执行 sudo yum install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm 手动安装 EPEL 源。

总结

废弃 certbot-auto 后,通过系统包管理器(apt/yum)安装的 certbot 更稳定、易维护,且自动配置续期,完全满足 IT 运维场景的 HTTPS 证书管理需求。按上述步骤安装后,即可快速完成证书申请与长期自动化运维。

类似文章

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注