Let's Encrypt是很火的一個免費SSL證書發行項目,自動化發行證書,證書有90天的有效期。Let's Encrypt已經發布了工具certbot,用此工具生成證書、證書續期非常簡單。
以下是用certbot生成通配符域名證書的使用方法(Centos7為例):
執行:
certbot certonly -d *.domain.com --manual --preferred-challenges dns --server https://acme-v02.api.letsencrypt.org/directory
Are you OK with your IP being logged?
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Please deploy a DNS TXT record under the name _acme-challenge.domain.com with the following value: ************* Before continuing, verify the record is deployed.
根據提示,這里需要手動到域名解析的地方添加域名的TXT解析,完成后過幾分鍾等待生效,並使用nslookup命令檢查一下是否生效:
nslookup -q=TXT _acme-challenge.domain.com
若TXT解析已生效,在certbot命令行界面敲入回車,進行校驗,證書生成成功后提示如下如下:
IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/domain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/domain.com/privkey.pem Your cert will expire on 2019-11-19. To obtain a new or tweaked version of this certificate in the future, simply run certbot again. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le
然后回到阿里雲SLB中,找到添加證書的地方,選擇已有證書方式進行添加。
cat命令查看公鑰、私鑰,並復制到阿里雲添加證書的界面中。
查看公鑰:
cat /etc/letsencrypt/live/domain.com/fullchain.pem
阿里雲要求私鑰是-----BEGIN RSA PRIVATE KEY-----開頭,所以需要先處理以下私鑰文件,轉換成RSA私鑰,執行以下命令:
openssl rsa -in /etc/letsencrypt/live/domain.com/privkey.pem -out /etc/letsencrypt/live/domain.com/privkey.rsa.pem
查看私鑰:
cat /etc/letsencrypt/live/domain.com/privkey.rsa.pem
以后若需要續SSL證書,只需在該服務器上執行以下命令,並按提示繼續:
certbot renew
以下是certbot-auto的使用方法,內容來源於網絡,供參考借鑒:
安裝方法:
如果是CentOS 6、7,先執行:yum install epel-release
cd /root/
wget https://dl.eff.org/certbot-auto --no-check-certificate
chmod +x ./certbot-auto
./certbot-auto -n
./certbot-auto -n只是用來安裝依賴包的,也可以跳過直接到下面的生成證書的步驟,國內VPS或服務器上使用的話建議先修改為國內的pip源。
單域名生成證書:
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net
多域名單目錄生成單證書:(即一個網站多個域名使用同一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net
多域名多目錄生成一個證書:(即一次生成多個域名的一個證書)
./certbot-auto certonly --email youemail@vpser.net --agree-tos --no-eff-email --webroot -w /home/wwwroot/www.vpser.net -d www.vpser.net -d bbs.vpser.net -w /home/wwwroot/lnmp.org -d www.lnmp.org -d lnmp.org
證書續期
cerrbot的續期比原來的更加簡單,因為證書只有90天,所以建議使用crontab進行自動續期:
crontab 里加上如下規則:0 3 */5 * * /root/certbot-auto renew --disable-hook-validation --renew-hook "/etc/init.d/nginx reload" 這樣每5天就會執行一次所有域名的續期操作。當然時間也可以自行進行調整,建議別太頻繁,因為他們都有請求次數的限制,如果需要強制更新可以在前面命令上加上 --force-renew 參數。