如何在 AlmaLinux 8 上安装 Certbot

在本教程中,我们将向您展示如何在 AlmaLinux 8 上安装 Certbot。对于那些不知道的人,Certbot 是一个客户端,它从 Let’s Encrypt 机构获取 SSL 证书并自动安装和配置。 这消除了手动完成整个过程的痛苦和喧嚣。

本文假设您至少具有 Linux 的基本知识,知道如何使用 shell,最重要的是,您将站点托管在自己的 VPS 上。 安装非常简单,假设您在 root 帐户中运行,否则您可能需要添加 ‘sudo‘ 获取 root 权限的命令。 我将向您展示如何在 AlmaLinux 8 上逐步安装 Certbot。您可以按照 CentOS 和 Rocky Linux 的相同说明进行操作。

在 AlmaLinux 8 上安装 Certbot

步骤 1. 首先,让我们先确保您的系统是最新的。

sudo dnf update sudo dnf install epel-release

步骤 2. 在 AlmaLinux 8 上安装 Certbot。

  • 安装 Certbot Apache.

运行下面的命令来安装 Certbot Apache:

sudodnf installcertbot python3-certbot-apache mod_ssl
  • 为 Nginx 安装 Certbot。

运行以下命令为 Nginx 安装 Certbot:

sudodnf installcertbot python3-certbot-nginx

要验证 Certbot 安装,请运行:

certbot --version

步骤 3. 在 AlmaLinux 上安装 SSL 证书。

成功安装后,使用 Certbot 获取 SSL 证书。 指定 --apache 或者 --nginx 取决于您的网络服务器。 也可以使用其他选项,但这是最常见的两种。 我们会用 Apache 在这个例子中:

sudo certbot --apache

在安装过程中,这将生成一组您需要回答的提示。 如果一切顺利,您应该会收到以下消息:

Requesting a certificate for yourdomain.com Performing the following challenges: http-01 challenge for your-domain.com Waiting for verification... Cleaning up challenges Subscribe to the EFF mailing list (email: [email protected]).  IMPORTANT NOTES:  - Congratulations! Your certificate and chain have been saved at:    /etc/letsencrypt/live/your-domain.com/fullchain.pem    Your key file has been saved at:    /etc/letsencrypt/live/your-domain.com/privkey.pem    Your certificate will expire on 2021-08-25. To obtain a new or    tweaked version of this certificate in the future, simply run    certbot again. To non-interactively renew *all* of your    certificates, run "certbot renew"  - If you like Certbot, please consider supporting our work by:     Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate    Donating to EFF:                    https://eff.org/donate-le

步骤 4. 配置防火墙。

现在添加防火墙规则以允许连接以及 HTTP(端口 80)和 HTTPS(端口 443)流量:

sudo firewall-cmd --permanent --add-port=80/tcp --zone=public sudo firewall-cmd --permanent --add-port=443/tcp --zone=public sudo firewall-cmd --reload

恭喜! 您已成功安装 Certbot。 感谢您使用本教程在您的 AlmaLinux 8 系统上安装 Certbot。 如需更多帮助或有用信息,我们建议您查看 Certbot 官方网站.