Letsencrypt

一、概要

1. 环境

(1) CentOS 7.9 2009

(2) Cerbot 2.3.0

2. 简介

为了在网站上启用 HTTPS,需要从证书颁发机构(CA)获取证书。 Let’s Encrypt 正是其中一家证书颁发机构。

要从Let’s Encrypt获取网站域名的证书,必须证明你对域名的实际控制权。这一过程通常由 Web 主机上运行的ACME协议客户端完成。

3. 准备

我们以example.com为例,假设它的IP地址为10.8.9.1。

(1) 首先在域名平台配置example.com的域名解析:

@        IN A 10.8.9.1
www   IN A 10.8.9.1
mail    IN A 10.8.9.1

@ IN MX 10 mail.example.com.

(2) 验证配置(Windows CMD)

nslookup -qt=A example.com
nslookup -qt=A www.example.com
nslookup -qt=A mail.example.com
nslookup -qt=MX example.com

4. Snap

(1) 安装

参考:snap的安装

(2) 启动snapd.seeded

sudo systemctl start snapd.seeded.service
systemctl status snapd.seeded.service

(3) 更新snap

sudo snap install core
sudo snap refresh core

二、Cerbot

Cerbot是一个ACME 客户端,它可以在不下线服务器的前提下自动执行证书颁发和安装。对于不需要自动配置的用户,Certbot还提供专家模式。

1. 安装

(1)  注意

如果你是使用yum安装的cerbot,那么你需要先卸载掉它:

sudo yum remove certbot

(2) 安装cerbot

sudo snap install --classic certbot

(3) 创建软链接

sudo ln -s /snap/bin/certbot /usr/bin/certbot

2. 生成证书 --- Nginx

(1) 获取证书并更新Nginx的配置文件

sudo certbot --nginx

证书和私钥的路径分别是:

/etc/letsencrypt/live/域名/fullchain.pem
/etc/letsencrypt/live/域名/privkey.pem

注意替换掉“域名”。

(2) 仅生成证书

sudo certbot certonly --nginx

3. 生成证书 --- Apache

(1) 获取证书并更新Nginx的配置文件

sudo certbot --apache

(2) 仅生成证书

sudo certbot certonly --apache

4. 定时更新证书

Letsencrypt证书的有效期是90天,官方建议每隔60天自动更新一下证书以避免证书过期。

(1) 可以定时运行以下命令以便自动更新证书:

sudo certbot renew --dry-run

(2) Crontab

a. 编辑Crontab

sudo crontab -e

b. 添加证书更新条目:

* * *  1  * certbot renew --dry-run
* * *  3  * certbot renew --dry-run
* * *  5  * certbot renew --dry-run
* * *  7  * certbot renew --dry-run
* * *  9  * certbot renew --dry-run
* * *  11  * certbot renew --dry-run

5. 测试

通过https访问你解析的域名:

https://www.example.com

三、参考

1. 官方

https://letsencrypt.org/

https://certbot.eff.org/

posted @ 2023-02-18 20:31  白马黑衣  阅读(139)  评论(0编辑  收藏  举报