您可以將在具有 Bluemix® Product Insights 的 Docker 上執行的 IBM WebSphere Liberty 伺服器登錄來報告伺服器登錄以及使用情形和其他資訊,例如:作用中的 WebSphere Liberty 伺服器數目、每一個伺服器的主機位置、每一個伺服器的產品版別和版本號碼,以及每一個伺服器的忙碌程度。
開始之前
IBM Cloud
Product Insights 需要 WebSphere Application
Server Liberty 17.0.0.1 版或更新版本。
Liberty Docker 建置包括從 Docker Hub 取回最新版的 WebSphere Liberty Docker 映像檔。Liberty Docker Hub 映像檔包含一份
ILAN 授權,也就是說,它們是免費、不提供支援且無保固的產品版本。如果要更新支援產品的授權,請參閱將 Docker Hub 中的映像檔升級至正式作業映像檔。
將 IBM WebSphere Liberty 伺服器實例連接至 Product Insights 之前,您必須具有一個
IBM Cloud 帳戶,並在組織和空間中建立服務。請遵循入門步驟,來設定帳戶並配置
Product Insights 服務。請記下指示中說明的 API 主機和 API 金鑰。
配置 Docker 上的 WebSphere Liberty 伺服器時,需要一部已安裝 Docker 的
Linux 機器或虛擬機器。
關於這項作業
定義 Liberty 群體,並在 Docker 儲存器中建立 Docker 映像檔之後,請使用「部署」工具,將映像檔安裝在群體內的 Docker 主機上。
程序
- 建置 Docker 映像檔。
- 配置 Product Insights 服務的連線。 在 Liberty 伺服器的 server.xml 檔中,配置
Product Insights 服務的連線。將
<apiHost> 換成您 Product Insights 服務的 API 主機。將
<apiKey> 換成您服務的 API 金鑰。
<server>
<featureManager>
<feature>productInsights-1.0</feature>
</featureManager>
<productInsights url="<apiHost>" apiKey="<apiKey>" sslRef="productInsightsSSL"
groups="DockerImages"/>
<keyStore id="productInsightsKeyStore" location="/config/digicert.jks" type="JKS"/>
<ssl id="productInsightsSSL"
keyStoreRef="productInsightsKeyStore"
trustStoreRef="productInsightsKeyStore"
sslProtocol="TLSv1.2"/>
</server>
註: 如果執行 Docker 儲存器的機器是透過閘道或 Proxy 伺服器,來連接至
Product Insights 服務,則配置略有不同。如需相關資訊,請參閱
使用閘道或 Proxy 伺服器。
- 建立一個安裝 Dockerfile。 在 server.xml 檔的相同目錄中,建立一個 Dockerfile,用來安裝
Liberty 映像檔、productInsights-1.0
Liberty 特性和 IBM Cloud
digicert.jks 憑證檔案。下列 Dockerfile 會從 Docker Hub 取回
websphere-liberty:webProfile7 映像檔,並使用該
Liberty 版本來建置新映像檔。如需其他您可以安裝的 Liberty Docker 映像檔,請參閱 Docker Hub 上的 websphere-liberty 儲存庫。
FROM websphere-liberty:webProfile7
COPY server.xml /config/
RUN apt-get update \
&& apt-get install -y --no-install-recommends unzip curl \
&& rm -rf /var/lib/apt/lists/*
RUN installUtility install --acceptLicense productInsights-1.0\
&& rm -rf /output/workarea /output/logs
RUN cd /opt/ibm/wlp/usr/servers/defaultServer \
&& curl -O https://wlpcfg.ng.bluemix.net/productinsights/digicert.jks
- 建置 Docker 映像檔。 執行 docker build 指令,來建置 Docker 映像檔。您藉以建置 Docker 映像檔的機器,必須有權存取網際網路,因為它需要下載
Liberty Docker 映像檔、
productInsights-1.0
Liberty 特性,以及必要的 IBM Cloud
digicert.jks
憑證。
docker build -t liberty-product-insights-example
- 執行 Docker 儲存器中的映像檔。
- 執行一個 Docker 映像檔實例。 如果要執行一個 Docker 映像檔實例,請使用
Liberty 伺服器儲存器上所代管的應用程式名稱。下列範例說明命名的最佳作法。
docker run -d -e CONTAINER_HOST='myApplication' liberty-product-insights-example
註: 針對執行中的伺服器實例,提報給 Product Insights 的預設主機名稱會是儲存器名稱,每當執行或調整 Docker 映像檔時,就會重新指派該名稱。若要能夠固定追蹤伺服器的度量,您必須設定
CONTAINER_HOST 環境變數的值,以置換預設主機名稱值。
- 執行多個 Docker 映像檔實例。 如果要針對同一應用程式,執行多個 Docker 映像檔實例,請將相同的
CONTAINER_HOST 值用於每一個實例。當傳送對應至
CONTAINER_HOST 的登錄和使用情形資料給 Product Insights 服務時,該服務會結合這些資訊(宛如來自單一實例),這樣您就可以查看該應用程式所有相關聯的使用情形。
註: 如果要選擇性地置換伺服器名稱,請設定
CONTAINER_NAME 環境變數。如果未設定此變數,所有映像檔會將
defaultServer 當成伺服器名稱,提報給
Product Insights
服務。
docker run -d -e CONTAINER_HOST=' myApplication' -e CONTAINER_NAME=' myServerName' liberty-product-insights-example
- 驗證已向 IBM Cloud
Product Insights 登錄。
- 執行 docker ps 指令,尋找儲存器 ID。
docker ps
- 透過 Bash 將 STDIN 連接至 Docker 儲存器,以便與 Docker 儲存器檔案系統互動。
docker exec -it <containerId> bash
- 檢查 Liberty 日誌,驗證伺服器已向 Product Insights 服務登錄。 在 /logs 目錄中,開啟 messages.log 檔,並尋找下列訊息。
CWWKR0400I: 伺服器已向位於指定 URL <apiHost> 的 IBM Cloud Product Insights 登錄。
- 在瀏覽器中,移至您在 IBM Cloud 上的 Product Insights 服務儀表板,以檢視新登錄的伺服器。
結果
將在具有 IBM Cloud Product Insights 的 Docker 上執行的 IBM WebSphere Liberty 伺服器登錄來支援伺服器登錄和使用情形。