Centos7安装certbot获得并更新证书(使用Snap)

背景

目前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版本以上均可用,如果不知道你的版本,使用如下命令查看

cat /etc/centos-release
  • 添加CentOS repository

CentOS 8

sudo dnf install epel-release
sudo dnf upgrade

CentOS 7

sudo yum install epel-release
  • 添加EPEL repository后,进行Snapd的安装
sudo yum install snapd
  • 安装后,需要启用管理snap通信套接字的systemd unit
sudo systemctl enable --now snapd.socket
  • 为了启用classic snap的支持,需要创建如下软连接
sudo ln -s /var/lib/snapd/snap /snap
  • 重新登录或者重启你的系统,以确保snap的路径正确更新,至此snap安装完成。

安装Certbot

  • 升级snap

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

sudo snap install core
sudo snap refresh core
  • 卸载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
sudo snap install --classic certbot
  • 配置Certbot命令行

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

sudo ln -s /snap/bin/certbot /usr/bin/certbot
  • 运行Certbot(二选一) 

1、运行此命令获取证书,并让Certbot自动编辑Nginx配置以提供服务,只需一步即可打开HTTPS访问

sudo certbot --nginx

注:Certbot默认nginx配置文件在 /etc/nginx/nginx.conf 或 /usr/local/etc/nginx/nginx.conf,若你的nginx配置文件不在此处(以/usr/local/nginx/conf/nginx.conf为例),需在命令后加上 --nginx-server-root /usr/local/nginx/conf

2、仅获得证书。如果你希望手动配置nginx,输入如下命令

sudo certbot certonly --nginx

注:同上

  • 自动续期

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

sudo certbot renew --dry-run

renew的命令被配置到以下位置中的一个:

/etc/crontab/
/etc/cron.*/*
systemctl list-timers

参考

  • 1
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值