步驟1:創建密鑰庫
Java KeyStore(JKS)是安全證書的存儲庫。keytool是用于創建和管理密鑰庫的命令行實用程序。JDK和JRE都可以使用此命令。我們只需要確保JDK或JRE配置了PATH環境變量。
$ keytool -genkey -aliassvr1.tecadmin.net-keyalg RSA -keystore/etc/pki/keystore
輸出:
Enter keystore password: Re-enter new password: What is your first and last name? [Unknown]:Rahul KumarWhat is the name of your organizational unit? [Unknown]:WebWhat is the name of your organization? [Unknown]:TecAdmin Inc.What is the name of your City or Locality? [Unknown]:DelhiWhat is the name of your State or Province? [Unknown]:DelhiWhat is the two-letter country code for this unit? [Unknown]:INIs CN=Rahul Kumar, OU=Web, O=TecAdmin Inc., L=Delhi, ST=Delhi, C=IN correct? [no]:yesEnter key password for(RETURN if same as keystore password): Re-enter new password:
步驟2:獲取CA簽名的SSL[忽略自簽名用戶]
如果要使用自簽名SSL證書,則無需執行此步驟。如果要從證書頒發機構購買有效的ssl,則需要先創建CSR,使用以下命令執行此操作。
創建CSR:
$ keytool -certreq -keyalg RSA -alias svr1.tecadmin.net -file svr1.csr -keystore /etc/pki/keystore
上面的命令將提示輸入密鑰庫密碼并生成CSR文件。使用此CSR并從任一證書頒發機構購買ssl證書。
CA頒發證書后,將擁有以下文件: root certificate,intermediate certificate 和Issued certificate by CA。在此例中,文件名是
A. root.crt (root certificate)
B. intermediate.crt (intermediate certificate)
C. svr1.tecadmin.net.crt ( Issued certificate by CA )
安裝root certificate:
$ keytool -import -alias root -keystore/etc/pki/keystore-trustcacerts -fileroot.crt
安裝intermediate certificate:
$ keytool -import -alias intermed -keystore/etc/pki/keystore-trustcacerts -fileintermediate.crt
安裝Issued certificate by CA
$ keytool -import -aliassvr1.tecadmin.net-keystore/etc/pki/keystore-trustcacerts -filesvr1.tecadmin.net.crt
步驟3:設置Tomcat密鑰庫
現在,轉到你的Tomcat安裝目錄并在你喜歡的編輯器中編輯conf/server.xml文件,并按如下所示更新配置。如果需要,也可以將端口從8443更改為其他端口。
<Connector port="8443" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" SSLEnabled="true" scheme="https" secure="true" sslProtocol="TLS" keystoreFile="/etc/pki/keystore" keystorePass="_password_" />
步驟4:重新啟動Tomcat
使用init腳本(如果有)重新啟動Tomcat服務,在這個例子中,我們使用的是shell腳本(startup.sh和shutdown.sh)來停止和啟動Tomcat。
$ ./bin/shutdown.sh $ ./bin/startup.sh
步驟5:驗證安裝程序
因為我們已經完成了Tomcat設置所需的所有配置。就可以在步驟2中的配置端口上訪問瀏覽器中的Tomcat。
本篇文章到這里就已經全部結束了,更多其他精彩內容可以關注PHP中文網的Java視頻教程欄目!
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com