为了保持系统软件的一致, CentOS 6 自带的仍是早已不被支持的 python 2.6,这将致使没法申请 Letsencrypt 证书,因此须要安装 python 2.7 以上版本。要安装新版本的 python,能够下载源代码本身编译;也能够使用SCL(可参考“如何在 CentOS 上启用 软件集 Software Collections(SCL)”);还能够找第三方软件库(如 ius)。html
下面介绍使用 ius 软件库,首先下载并安装软件库配置包:python
# 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 的相关软件包:linux
# yum -y install python27 python27-libs python27-devel python27-virtualenv python27-setuptools
接下来就能够按照 Letsencrypt 的文档 提供的步骤申请证书,先准备软件环境:git
# git clone https://github.com/letsencrypt/letsencrypt # cd letsencrypt # ./letsencrypt-auto --help
中止 Apache 服务, 根据本身的域名申请证书:
github
# /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 , 使用新的证书和私匙例如:
shell
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:.net
#!/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点更新证书一次。
code
0 2 22 */3 * /bin/sh /root/renew_cert.sh