在 CentOS 6 上使用 Letsencrypt 证书

为了保持系统软件的一致, CentOS 6 自带的还是早已不被支持的 python 2.6,这将导致无法申请 Letsencrypt 证书,所以需要安装 python 2.7 以上版本。要安装新版本的 python,可以下载源代码自己编译;也可以使用SCL(可参考“如何在 CentOS 上启用 软件集 Software Collections(SCL)”);还可以找第三方软件库(如 ius)。

下面介绍使用 ius 软件库,首先下载并安装软件库配置包:

# wget http://dl.iuscommunity.org/pub/ius/stable/Redhat/6/x86_64/ius-release-1.0-14.ius.el6.noarch.rpm
# yum -y install ius-release-1.0-14.ius.el6.noarch.rpm

然后可以安装所需 python 2.7 的相关软件包:

# yum -y install python27 python27-libs python27-devel python27-virtualenv python27-setuptools


接下来就可以按照 Letsencrypt 的文档 提供的步骤申请证书,先准备软件环境:

# git clone https://github.com/letsencrypt/letsencrypt
# cd letsencrypt
# ./letsencrypt-auto --help

停止 Apache 服务, 根据自己的域名申请证书:

# /etc/init.d/httpd stop
# ./letsencrypt-auto certonly --standalone --email admin@thing.com -d thing.com -d www.thing.com -d otherthing.net

如果看见 Congratulations 说明证书申请成功了。fullchain.pem 是 Apache >=2.4.8 用的, privkey.pem 是私匙,cert.pem是证书,详细请看“Where are my certificates?”。修改 /etc/httpd/conf.d/ssl.conf , 使用新的证书和私匙例如:

SSLCertificateFile /etc/letsencrypt/live/thing.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/thing.com/privkey.pem

重新启动 Apache 服务:

# /etc/init.d/httpd start

使用 https 访问网站,可以看到浏览器自动接受了证书,不会再有自己签发证书的烦恼。


Letsencript 证书目前有效期是90天,可以编写更新脚本,让cron自动执行。更新脚本renew_cert.sh:

#!/bin/sh

# 假设 letsencrypt 安装在 /opt/letsencrypt
cd /opt/letsencrypt/

# 更新 letencrypt
git pull

# 停止 Apache
/etc/init.d/httpd stop

# 更新证书
./letsencrypt-auto certonly --standalone --renew-by-default --email  admin@thing.com -d thing.com -d www.thing.com -d otherthing.net

# 启动 Apache
/etc/init.d/httpd start

运行  crontab -e ,添加一行,每隔3个月的22日2点更新证书一次。

0 2 22 */3 * /bin/sh /root/renew_cert.sh

转载于:https://my.oschina.net/u/444663/blog/550754

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值