[17.0.0.1 以及更新版本]

在 Docker 上動態啟動 Product Insights

您可以將在具有 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 機器或虛擬機器。

註: 在 Kubernetes 環境內配置 Liberty 時, 需要採取動態新增 IBM Cloud Product Insights 時的類似作法。您可以建立 Kubernetes 密碼或含有 productInsights.xmldigicert.jks 檔的配置對映,並且在應用程式部署 YAML 檔案中指定裝載點,將這些檔案裝載到正在執行的 Docker 映像檔。

關於這項作業

定義 Liberty 群體,並在 Docker 儲存器中建立 Docker 映像檔之後,請使用「部署」工具,將映像檔安裝在群體內的 Docker 主機上。

程序

  1. 建置 Docker 映像檔。
    1. 如果要置換 Liberty 伺服器配置中的預設值,請重新命名現有的 server.xml 檔,您可以建立和配置新的 server.xml 檔。Product Insights 會動態啟用,且不需要任何額外的 Product Insights 配置。 以下是 websphere-liberty:webProfile7 Docker 映像檔所包含的伺服器配置。
      <server>
          <featureManager>
             <feature>webProfile-7.0</feature>
          </featureManager>
         <!-- To allow access to this server from a remote client host="*" has been added to the following element -->
      
         <httpEndpoint id="defaultHttpEndpoint"
                        host="*"
                        httpPort="9080"
                        httpsPort="9443" />
          <!-- Automatically expand WAR files and EAR files -->
          <applicationManager autoExpand="true"/>
      </server>
    2. 建立一個安裝 Dockerfile。server.xml 檔的相同目錄中,建立一個 Dockerfile,以用來安裝 productInsights-1.0 Liberty 特性。
      FROM websphere-liberty:webProfile7
      COPY server.xml /config
      RUN installUtility install --acceptLicense productInsights-1.0\
          && rm -rf /output/workarea /output/logs
      如果您未在步驟 1 建立自己的 server.xml 檔,請移除或註銷下面這行:
      COPY server.xml /config
    3. 建置 Docker 映像檔。 執行 docker build 指令,來建置 Docker 映像檔。您藉以建置 Docker 映像檔的機器,必須有權存取網際網路,因為它需要下載 Liberty Docker 映像檔和 productInsights-1.0 Liberty 特性。
      docker build -t liberty-product-insights-example
  2. 執行 Docker 儲存器中的映像檔。
    1. 執行一個 Docker 映像檔實例。 如果要執行一個 Docker 映像檔實例,請使用 Liberty 伺服器儲存器上所代管的應用程式名稱。下列範例說明命名的最佳作法。
      docker run -d --volume=/opt/docker/libertyConfig:/config/configDropins/overrides -e CONTAINER_HOST=' myApplication' liberty-product-insights-example
      註: 針對執行中的伺服器實例,提報給 Product Insights 的預設主機名稱會是儲存器名稱,每當執行或調整 Docker 映像檔時,就會重新指派該名稱。若要能夠固定追蹤伺服器的度量,您必須設定 CONTAINER_HOST 環境變數的值,以置換預設主機名稱值。
    2. 執行多個 Docker 映像檔實例。 如果要針對同一應用程式,執行多個 Docker 映像檔實例,請將相同的 CONTAINER_HOST 值用於每一個實例。當傳送對應至 CONTAINER_HOST 的登錄和使用情形資料給 Product Insights 服務時,該服務會結合這些資訊(宛如來自單一實例),這樣您就可以查看該應用程式所有相關聯的使用情形。
      註: 如果要選擇性地置換伺服器名稱,請設定 CONTAINER_NAME 環境變數。如果未設定此變數,所有映像檔會將 defaultServer 當成伺服器名稱,提報給 Product Insights 服務。
      docker run -d --volume=/opt/docker/libertyConfig:/config/configDropins/overrides -e CONTAINER_HOST=' myApplication' -e CONTAINER_NAME=' myServerName' liberty-product-insights-example
  3. 動態新增 IBM Cloud Product Insights 配置。
    1. 下載 digicert.jks 憑證檔的 IBM Cloud 副本,並放到 /opt/docker/libertyConfig 目錄中。
    2. 在相同目錄中,建立一個名為 productInsights.xml 的配置檔。將 <apiHost> 換成您服務的 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 伺服器
  4. 驗證已向 IBM Cloud Product Insights 登錄。
    1. 執行 docker ps 指令,尋找儲存器 ID。
      docker ps
    2. 透過 Bash 將 STDIN 連接至 Docker 儲存器,以便與 Docker 儲存器檔案系統互動。
      docker exec -it <containerId> bash
    3. 檢查 Liberty 日誌,驗證伺服器已向 Product Insights 服務登錄。/logs 目錄中,開啟 messages.log 檔,並尋找下列訊息。
      CWWKR0400I: 伺服器已向位於指定 URL <apiHost> 的 IBM Cloud Product Insights 登錄。
    4. 在瀏覽器中,移至您在 IBM Cloud 上的 Product Insights 服務儀表板,以檢視新登錄的伺服器。

結果

將在具有 IBM Cloud Product Insights 的 Docker 上執行的 IBM WebSphere Liberty 伺服器登錄來支援伺服器登錄和使用情形。


指示主題類型的圖示 作業主題

檔名:twlp_dynamic_docker_product_insights.html