自動續期
Let's Encrypt申請的證書會有三個月的有效期,可以到期前手動續約,也可以自己寫定時腳本任務自動續約。嫌手動麻煩,就寫了個簡單的續期腳本。
1、腳本
#/bin/sh
#續期 說明:只用renew的話,會先檢查證書是否需要更新,大概是距離到期還有三天或者十幾天之內才會執行更新,否則會提示不需要更新。(昨天更新了證書,今天直接用renew,提示不允許更新)
#這里方便測試,增加參數--force-renew,能夠強制立即更新(但好像也會有檢查,時間會變短,比如我剛才更新過了,馬上再次執行會報錯并提示不需要更新)。
./certbot-auto renew --force-renew
#生成p12
cd /mnt/web/letsTemp && openssl pkcs12 -export -in fullchain.pem -inkey privkey.pem -out fullchain_and_key.p12 -name tomcat -passin passyourPKCS12pass -passout pass:yourPKCS12pass
#移動新生成的證書文件
cp /etc/letsencrypt/live/yourDomain/fullchain.pem /mnt/web/letsTemp
cp /etc/letsencrypt/live/yourDomain/privkey.pem /mnt/web/letsTemp
#生成jks文件
#備份并刪除原jks文件
mv /mnt/web/letsTemp/MyDSKeyStore.jks /mnt/web/letsTemp/MyDSKeyStore`date '+%Y-%m-%d'`.jks
cd /mnt/web/letsTemp && keytool -importkeystore -deststorepass yourKeyPass -destkeypass yourKeyPass -destkeystore MyDSKeyStore.jks -srckeystore fullchain_and_key.p12 -srcstoretype PKCS12 -srcstorepass yourPKCS12pass -alias tomcat
#重啟服務器
/mnt/web/tomcat/tomcat8/bin/restartup.sh
2、定時任務
腳本有了,還需要在linux中添加一個定期執行腳本的任務,這里用linux自帶的cron來處理這部分。
crontab -e
在打開的編輯器中添加如下內容(每個月1號凌晨3點更新)
0 0 3 * * sh /mnt/web/lets/ssl_auto_auth.sh >/dev/null 2>&1 &
@import url(http://www.shnenglu.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
posted on 2017-09-07 22:23
聶文龍 閱讀(293)
評論(0) 編輯 收藏 引用