之前一直使用certbot-auto来获取https证书,后来更换了新域名, 重新生成证书时,报:“Your system is not supported by certbot-auto anymore.”,
查了一下是因为certbot-auto团队没有精力为所有操作系统进行维护,所以包括centos7在内的许多系统已不被支持,目前certbot不推荐在centos7上使用仓库安装,官方建议使用snap进行certbot的安装和更新。官方原文如下:

While the Certbot team tries to keep the Certbot packages offered by various operating systems working in the most basic sense, due to distribution policies and/or the limited resources of distribution maintainers, Certbot OS packages often have problems that other distribution mechanisms do not. The packages are often old resulting in a lack of bug fixes and features and a worse TLS configuration than is generated by newer versions of Certbot. They also may not configure certificate renewal for you or have all of Certbot’s plugins available. For reasons like these, we recommend most users follow the instructions at https://certbot.eff.org/instructions and OS packages are only documented here as an alternative.

翻译:

尽管Certbot团队试图保持各操作系统的Certbot包在最基本的功能上运作,但由于各发行版的政策和有限的维护人员,Certbot OS包通常存在其他发行版本没有的问题。这些包通常很旧,导致缺少bug修复和一些特性,并且TLS的配置比新版本Certbot生成的较差。他们也可能没有为你配置证书更新,或者没有Certbot的全部可用插件。出于这些原因,我们建议大多数用户按照https://certbot.eff.org/instructions而操作系统包在这里只是作为一个替代方案。  

安装Snapd

官方给出的文档https://snapcraft.io/docs/installing-snapd,这里翻译一下CentOS版本

Snap在CentOS 7.6版本以上均可用

添加EPEL repository后,进行Snapd的安装

安装后,需要启用管理snap通信套接字的systemd unit

为了启用classic snap的支持,需要创建如下软连接

重新登录或者重启你的系统,以确保snap的路径正确更新,至此snap安装完成。

安装Certbot

升级snap

执行如下命令以保证Snap为最新的版本

卸载Certbot和其他Certbot OS包

如果使用操作系统包管理器(如apt、dnf或yum)安装了任何Certbot包,则应在安装Certbot snap之前将其删除,以确保在运行命令Certbot时使用snap,而不是从操作系统包管理器安装。执行此操作的确切命令取决于你的操作系统,常见的示例有sudo apt get remove certbot、sudo dnf remove certbot或sudo yum remove certbot。

如果以前通过Certbot auto脚本使用Certbot,还应该按照此处的说明删除其安装。

安装Certbot

依次执行下列命令

当执行snap install –classic certbot命令时,可能会有如下报错

解决:

创建一个软链:

 

执行如下命令以确保Certbot命令行可用

 

下面是生成两个域名的SSL证书

当然, 我们用Let’s Encrypt生成 泛域名ssl证书最方便了, 这样所有子域名都可以直接使用一个证书

官网文档:https://certbot.eff.org/docs/using.html

直接使用官网首页的安装方法是无法使用最新的Let’s Encrypt的v2 API,这里加参数–server https://acme-v02.api.letsencrypt.org/directory ,还需要增加DNS验证,需要添加参数–preferred-challenges dns,而我用的DNS服务器商没有API来自动验证,故需要添加参数–manual,还需要注意的是:域名不能只添加*.xxx.com, 还需要增加xxx.com, 不然只能子域名用,xxx.com域名就用不了了, 所以最后的命令为:

签发证书时提示添加TXT记录,需要打开域名注册网站,按要求添加一下TXT记录,等记录生效后, 按回车,这样等待签发完成即可

 

 

生成证书时, 会在/etc/letsencrypt/renewal目录下生成配置文件open010.com.conf,生成前可以将旧的配置文件先删除

申请 成功后,证书会保存在/etc/letsencrypt/live/open010.com下面

配置nginx证书,配置中用到一个 /data/secret/dhparam.pem 文件,该文件是一个 PEM 格式的密钥文件,用于 TLS 会话中。用来加强 ssl 的安全性。生成该文件方法,

配置到nginx:

自动续期证书

Certbot包带有cron作业或systemd计时器,它将在证书过期之前自动续订证书。除非更改配置,否则不需要再次运行Certbot。通过运行以下命令,可以测试证书的自动续订

 

Let’s Encrypt证书有效期为90天,设置一个定时任务来运行certbot命令来自动续期

这样,系统就会每月1日凌晨两点续期证书了

Categories: SECURITY

0 Comments

Leave a Reply

Avatar placeholder

Your email address will not be published. Required fields are marked *