zoukankan      html  css  js  c++  java
  • JConsole和VisualVM远程访问JMX

    1.jvisualvm监控tomcat

    修改tomcat的bin目录下的 catalina.sh文件,搜索JAVA_OPTS="",在引号中添加参数

    JAVA_OPTS="$JAVA_OPTS $JSSE_OPTS 
    -Djava.rmi.server.hostname=192.168.1.123
    -Dcom.sun.management.jmxremote.port=12345 
    -Dcom.sun.management.jmxremote.ssl=false 
    -Dcom.sun.management.jmxremote.authenticate=false "

    2.jvisualvm监控可执行jar

    nohup java -Djava.rmi.server.hostname=192.168.1.123 -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -jar test.jar &

    3.打开本地JVisualVM,右击"远程"->添加添加远程主机(H),输入服务器地址

    4.右击服务器地址->添加JMX连接,输入服务器地址和jmx端口

    5.输入完成后即可监控到远程jar文件内存使用情况

    可能出现异常情况:VisualVM 无法使用 service:jmx:rmi:///jndi/rmi:///jmxrmi 连接到xx.xx.xx.xx,关闭远程机器的防火墙即可
    原因:除了JMX server指定的监听端口号外,JMXserver还会监听一到两个随机端口号,可以通过命netstat -tupln |grep <pid> 来查看当前java进程需要监听的随机端口号,将两个随机端口加入入站规则即可。
     

    ###开启用户认证

    com.sun.management.jmxremote.authenticate=true
    a)  jmx连接使用安全凭证,需要单独设置
     
    b)  jar程序启动命令
    java  -Djava.rmi.server.hostname=192.168.1.123 
    -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.access.file=/usr/local/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/usr/local/jmxremote.password -jar test.jar
    c) jmxremote.access内容
    admin readwrite
     jmxremote.access模板:
    [用户名]      [权限]
    d) jmxremote.password内容
    admin 123456

    jmxremote.password模板:

    [用户名]       [密码]
    test          test
    e) 两个文件授权
    注意:jmxremote.password和jmxremote.access文件只允许启动用户名对该文件拥有读写权限 ,我们服务用root启动 ,必须按下面方式授权,chmod777都不行
    chmod 600 jmxremote.access
    chmod 600 jmxremote.password
    chown root:root jmxremote.access
    chown root:root jmxremote.password

    如果权限设置不正确会报错:Error: Password file read access must be restricted

  • 相关阅读:
    python RabbitMQ队列/redis
    python 协程
    Python 线程
    Python Socket网络编程
    Python 面向对象编程进阶
    Python 面向对象
    python 模块
    Python 迭代器&生成器&装饰器
    Python 集合操作
    Java多态--构造方法的内部方法多态
  • 原文地址:https://www.cnblogs.com/aaron911/p/10998585.html
Copyright © 2011-2022 走看看