[17.0.0.1 and later]

IBM Cloud Product Insights 注册 Docker 上的 Liberty 服务器

可向 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 的虚拟机。

关于此任务

定义 Liberty 集合体并在 Docker 容器中创建 Docker 映像后,使用部署工具在集合体内的 Docker 主机上安装映像。

过程

  1. 构建 Docker 映像。
    1. 配置与 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 容器的机器通过网关或代理服务器连接至 Product Insights 服务,那么配置稍有不同。有关更多信息,请参阅使用网关或代理服务器
    2. 创建安装 Dockerfile。server.xml 文件所在的目录中,创建用于安装 Liberty 映像、productInsights-1.0 Liberty 功能部件和 IBM Cloud digicert.jks 证书文件的 Dockerfile。以下 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
    3. 构建 Docker 映像。 通过运行 docker build 命令来构建 Docker 映像。您通过其构建 Docker 映像的机器必须可访问互联网,因为它需要下载 Liberty Docker 映像、productInsights-1.0 Liberty 功能部件和所需的 IBM Cloud digicert.jks 证书。
      docker build -t liberty-product-insights-example
  2. 在 Docker 容器中运行该映像。
    1. 运行 Docker 映像的一个实例。 要运行 Docker 映像的一个实例,请使用位于 Liberty 服务器容器上的该应用程序的名称。以下示例演示命名的最佳范例。
      docker run -d -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 -e CONTAINER_HOST=' myApplication' -e CONTAINER_NAME=' myServerName' liberty-product-insights-example
  3. 验证向 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_docker_product_insights.html