在 CentOS 6 上使用 Letsencrypt 證書

爲了保持系統軟件的一致, 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
相關文章
相關標籤/搜索