[17.0.0.1 and later]

在 Docker 上动态激活 Product Insights

可向 Bluemix® Product Insights 注册正在 Docker 上运行的 IBM WebSphere Liberty 服务器以报告服务器注册、使用情况及其他信息,例如,活动 WebSphere Liberty 服务器数、每个服务器的主机位置、每个服务器的产品版本以及每个服务器的繁忙程度。

开始之前

IBM Cloud Product Insights 需要 WebSphere Application Server Liberty V17.0.0.1 或更高版本。

Liberty Docker 构建包括 Docker Hub 中的最新 WebSphere Liberty Docker 映像版本。Liberty Docker Hub 映像包括 ILAN 许可证,这表示它们是产品的免费版本,没有支持服务,且没有任何保证。要将该许可证更新至有支持服务的产品,请参阅 Upgrading the image from Docker Hub to a production image

将 IBM WebSphere Liberty 服务器实例连接至 Product Insights 之前,必须具有 IBM Cloud 帐户,并在某个组织和空间中创建该服务。遵循入门步骤以设置帐户并分配 Product Insights 服务。记录指示信息中描述的 API 主机API 密钥

在 Docker 上配置 WebSphere Liberty 服务器需要 Linux 机器或已安装 Docker 的虚拟机。

注: 在 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 文件所在的目录中,创建用于安装 productInsights-1.0 Liberty 功能部件的 Dockerfile。
      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 容器的机器通过网关或代理服务器连接至 Product Insights 服务,那么配置稍有不同。有关更多信息,请参阅使用网关或代理服务器
  4. 验证向 IBM Cloud Product Insights 进行的注册。
    1. 通过运行 docker ps 命令来查找容器标识。
      docker ps
    2. 通过 Bash 将 STDIN 附加至 Docker 容器,以便您可与 Docker 容器文件系统交互。
      docker exec -it <containerId> bash
    3. 通过检查 Liberty 日志来验证服务器是否已向 Product Insights 服务注册。/logs 目录中,打开 messages.log 文件并查找以下消息。
      CWWKR0400I: The server was registered with the IBM Cloud Product Insights service on the specified URL <apiHost>.
    4. 在浏览器中,转至 IBM Cloud 上的 Product Insights 服务仪表板以查看新注册的服务器。

结果

正在带有 IBM Cloud Product Insights 的 Docker 上运行的 IBM WebSphere Liberty 服务器已注册以支持服务器注册和使用。


用于指示主题类型的图标 任务主题

文件名:twlp_dynamic_docker_product_insights.html