美文网首页kafka
为Kafka配置JMX进行指标监控

为Kafka配置JMX进行指标监控

作者: bilibili_877b | 来源:发表于2022-07-10 10:41 被阅读0次

    设置不受保护的JMX

    在此选项中,您将在不使用任何认证的情况下在 Kafka 上激活 JMX。

    要点: 您可以在 com.sun.management.jmxremote.port 选项中指定的端口连接至服务器的 JMX 接口,而不必提供任何类型的凭证。但是,建议不要对生产环境使用此选项,不过此选项对于在测试环境或本地环境中使用 JMX 很有用。

    Linux:
    
    # for JMX monitoring
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=1099"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false"
    
    Microsoft Windows:
    
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote=true
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1099
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.authenticate=false
    

    如果您使用IDEA运行的Kafka客户端程序(例如收集Kafka Stream指标),也可以这样配置:


    4.png

    其中具有焦点的输入框内容如下:

    -Dcom.sun.management.jmxremote.port=1099
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=false
    -Dcom.sun.management.jmxremote=true
    

    最后就可以使用Kafka Assistant收集Kafka指标了:

    1-3.png

    或者您也可以使用 JConsole 进行连接,请转至 JAVA_HOME/jdk/bin 目录并启动 JConsole。
    在远程过程字段中,输入 192.168.1.106:1099,然后单击连接。其中192.168.1.106是我本地的IP地址,换成你的。

    设置 JMX 以进行客户机认证

    在此选项中,您将在不使用 SSL 的情况下根据用户标识和密码在 Kafka 上激活 JMX 以进行客户机认证。

    控制该认证的属性为 com.sun.management.jmxremote.authenticate,必须将其设置为 true。该认证由下列两个其他属性和配置文件进行管理:

    • com.sun.management.jmxremote.access.file:此属性指定文件的位置,该文件包含有关访问用户角色和相关联的许可权的信息。
    • com.sun.management.jmxremote.password.file:此属性指定文件的位置,该文件包含每个角色的密码。

    可使用名为 jmxremote.accessjmxremote.password 的两个样本文件作为用户角色和密码。

    要点: 因为 jmxremote.password 文件中存储了明文密码,所以此文件必须设置为只读,否则程序将关闭并显示错误。

    对于Windows系统,可以使用以下命令设置文件为当前用户只读(其中chenjing是我的Windows用户名):

    cacls jmxremote.password /P chenjing:R
    

    对于Linux系统,可以使用以下命令设置文件为只读

    sudo chmod 444 jmxremote.password
    

    jmxremote.access 文件的内容如下:

    monitorRoleUser   readonly
    controlRoleUser   readwrite \
                      create javax.management.monitor.*,javax.management.timer.* \
                      unregister
    

    jmxremote.password 文件的内容如下:

    monitorRoleUser  1234
    controlRoleUser  1234
    

    设置VM选项:

    Linux:
    
    # for JMX monitoring
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote=true"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=1099"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=true"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.access.file=Path_to_access_file/jmxremote.access"
    JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.password.file=Path_to_password_file/jmxremote.password"
    
    Microsoft Windows:
    
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote=true
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.port=1099
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.ssl=false
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.authenticate=true
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.access.file=Path_to_access_file\jmxremote.access
    set JAVA_OPTS=%JAVA_OPTS% -Dcom.sun.management.jmxremote.password.file=Path_to_password_file\jmxremote.password
    

    如果您使用IDEA运行的Kafka客户端程序(例如收集Kafka Stream指标),也可以这样配置:

    4.png

    其中具有焦点的输入框内容如下:

    -Dcom.sun.management.jmxremote.port=1099
    -Dcom.sun.management.jmxremote.ssl=false
    -Dcom.sun.management.jmxremote.authenticate=true
    -Dcom.sun.management.jmxremote=true
    -Dcom.sun.management.jmxremote.access.file=Path_to_access_file\jmxremote.access
    -Dcom.sun.management.jmxremote.password.file=Path_to_password_file\jmxremote.password
    

    最后就可以使用Kafka Assistant收集Kafka指标了:

    1-1.png

    推荐一个Kafka GUI客户端,不用部署,颜值不错,小巧干净,提供实时监控功能,生成Kafka Stream拓扑图。官网地址:http://www.redisant.cn/ka

    相关文章

      网友评论

        本文标题:为Kafka配置JMX进行指标监控

        本文链接:https://www.haomeiwen.com/subject/cajwbrtx.html