申請Let's Encrypt泛域名免費證書(無需域名80埠)
1、前言
最近有個外網域名需要申請證書,準備用Let's Encrypt證書,畢竟免費嗎。可惜指令碼中會驗證域名的80埠,很不幸80埠因為某些原因無法開放,後來無意中發現一個方法,結合Neilpang/acme.sh和泛域名,這裡記錄下。
Neilpang/acme.sh參考:https://github.com/Neilpang/acme.sh/wiki/%E8%AF%B4%E6%98%8E
2、步驟
2.1 執行安裝指令碼
curl https://get.acme.sh | sh 或者
wget -O - https://get.acme.sh | sh 或者
curl https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1 sh 或者
wget -O - https://raw.githubusercontent.com/Neilpang/acme.sh/master/acme.sh | INSTALLONLINE=1 sh
指令碼安裝在~/.acme.sh目錄下
2.2 申請泛域名證書
./acme.sh --issue -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
2.3 域名解析伺服器新增域名的TXT解析
紅方框中就是需要的資訊。
2.4 獲取Let's Encrypt泛域名證書
2.4.1 檢視TXT資訊步驟:
2.4.1.1 安裝nslookup
yum install -y bind-utils
2.4.1.2 檢視資訊
nslookup -q=TXT baidu.com
2.4.2 DSN解析生效後,執行命令
./acme.sh --renew -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
2.5 證書說明
在~/.acme.sh目錄下會產生“*.域名”的資料夾,裡面就是證書,fullchain.cer是完整的證書,具體的證書區分見
證書格式說明 openssl生成自簽證書 中的證書型別說明。
[[email protected] .acme.sh]# tree *.qwcsp.cf
*.qwcsp.cf
├── ca.cer
├── fullchain.cer
├── *.qwcsp.cf.cer 證書
├── *.qwcsp.cf.conf
├── *.qwcsp.cf.csr 證書申請檔案
├── *.qwcsp.cf.csr.conf
├── *.qwcsp.cf.key 私鑰
└── qwcsp.cf.pem
附:
pem格式生成命令:
cat fullchain.cer \*.qwcsp.cf.key | tee qwcsp.cf.pem
強制更新命令:
./acme.sh --force --renew -d *.qwcsp.cf -d *.qwcsp.tk --dns --yes-I-know-dns-manual-mode-enough-go-ahead-please
2.6 生成tomcat的證書
# 匯出.p12格式的證書
/root/.acme.sh/*.qwcsp.cf
[[email protected] *.qwcsp.cf]# openssl pkcs12 -export -in fullchain.cer -inkey *.qwcsp.cf.key -out *.qwcsp.cf.p12 -name tomcat_letsencrypt
Enter Export Password:
Verifying - Enter Export Password:
# 再將證書由.p12格式轉換成.jks格式
$ keytool -importkeystore -deststorepass '123456' -destkeypass '123456' -destkeystore *.qwcsp.cf.jks -srckeystore *.qwcsp.cf.p12 -srcstoretype PKCS12 -srcstorepass '123456' -alias tomcat_letsencrypt
# 修改tomcat配置
修改 %tomcat%/conf/server.xml 檔案,新增 keystoreFile 和 keystorePass 兩行配置。其中,keystoreFile 指向 jks 證書檔案,而 keystorePass 則為證書的金鑰。修改後的關鍵配置如下:
<Connector port="8443" protocol="org.apache.coyote.http11.Http11Protocol" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"
keystoreFile="/home/test/*.qwcsp.cf.jks"
keystorePass="123456"
/>