3.3. 使用 Cryostat 代理和 JMX 连接配置应用程序


您可以配置在 Java 虚拟机(JVM)上运行的目标应用程序,以使用 Cryostat 代理和 Java 管理扩展(JMX)连接的组合来检测并与目标应用程序通信。

您可以使用 Cryostat 代理来检测和与目标应用程序通信,并使用 JMX 来公开 Java Flight Recorder (JFR)数据。

您必须将 Cryostat 代理配置为与 Cryostat 通信,并且代理可以通过 JMX 而不是通过 HTTP 访问。

前提条件

  • 登录到您的 Cryostat web 控制台。
  • 在项目中创建 Cryostat 实例。

流程

  1. 安装 Cryostat 代理。对于使用 Maven 的应用构建,请使用 Cryostat 代理 JAR 文件信息更新应用 pom.xml 文件。

    pom.xml 文件示例

    <project>
      ...
      <repositories>
        <repository>
          <id>redhat-maven-repository</id>
          <url>https://maven.repository.redhat.com/earlyaccess/all/</url>
        </repository>
      </repositories>
      ...
      <build>
        <plugins>
          <plugin>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>3.3.0</version>
            <executions>
              <execution>
                <phase>prepare-package</phase>
                <goals>
                  <goal>copy</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>io.cryostat</groupId>
                      <artifactId>cryostat-agent</artifactId>
                      <version>0.3.0.redhat-00001</version>
                      <classifier>shaded</classifier>
                    </artifactItem>
                  </artifactItems>
                  <stripVersion>true</stripVersion>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
        ...
      </build>
      ...
    </project>
    Copy to Clipboard Toggle word wrap

  2. 修改应用程序部署:

    示例

    apiVersion: apps/v1
    kind: Deployment
    ...
    spec:
      ...
      template:
        ...
        spec:
          containers:
            - name: sample-app
              image: docker.io/myorg/myapp:latest
              env:
                - name: CRYOSTAT_AGENT_APP_NAME
                  value: "myapp"
                  # Replace this with the Kubernetes DNS record
                  # for the Cryostat Service
                - name: CRYOSTAT_AGENT_BASEURI
                  value: "http://cryostat.mynamespace.mycluster.svc:8181"
                - name: POD_IP
                  valueFrom:
                    fieldRef:
                      fieldPath: status.podIP
                - name: CRYOSTAT_AGENT_CALLBACK
                  value: "http://$(POD_IP):9977"
                - name: CRYOSTAT_AGENT_AUTHORIZATION
                  # Replace "abcd1234" with a base64-encoded authentication token
                  value: "Bearer abcd1234"
                  # This environment variable is key to the Cryostat agent
                  # and JMX "hybrid" setup.
                  # Set the Cryostat agent to register itself with Cryostat
                  # as reachable through JMX, rather than reachable through HTTP.
                - name: CRYOSTAT_AGENT_REGISTRATION_PREFER_JMX
                  value: "true"
                  # Configure the application to load the agent JAR file and
                  # to enable JMX, so that the Cryostat agent can register
                  # itself as reachable through JMX.
                  # To configure authentication and SSL/TLS for the JMX
                  # connections, see <1>.
                - name: JAVA_OPTS
                  value: >-
                    -javaagent:/deployments/app/cryostat-agent-shaded.jar
                    -Dcom.sun.management.jmxremote.port=9091 
    1
    
              ports:
                - containerPort: 9977
                  protocol: TCP
              resources: {}
          restartPolicy: Always
    status: {}
    Copy to Clipboard Toggle word wrap

    <1>:要为 JMX 连接配置身份验证和 SSL/TLS,并查看更多配置选项,请参阅使用 JMX 连接 配置应用程序

  3. 要启用 Cryostat 来检测目标应用程序并连接到 Cryostat 代理,请配置 应用程序服务

    示例

    apiVersion: v1
    kind: Service
    ...
    spec:
      ports:
        - name: "jfr-jmx"
          port: 9091
          targetPort: 9091
        - name: "cryostat-agent"
          port: 9977
          targetPort: 9977
    ...
    Copy to Clipboard Toggle word wrap

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2026 Red Hat