LINUX配置JMX監控tomcat7

    1) 正常安裝JDK和Tomcat 配置環境變量(此步略過)

    2) 配置JMX訪問文件
    # cd $CATALINA_HOME/conf/
    # cp $JAVA_HOME/jre/lib/management/jmxremote.password.template jmxremote.password
    # chmod 700 jmxremote.password    (必定注意這個文件默認是不可寫的)
    # vi $CATALINA_HOME/conf/jmxremote.password

    在最下面添加一個用戶(第一個是用戶名 第二個是密碼)
    fox        123456

    # chmod 400 jmxremote.password    (要求該文件是任何用戶均不可寫的)
    # cp $JAVA_HOME/jre/lib/management/jmxremote.access jmxremote.access
    # vi jmxremote.access    (該文件是對jmx用戶的受權)

    到最後一行 將
    monitorRole   readonly
    controlRole   readwrite
    註釋 更改成
    # monitorRole   readonly
    # controlRole   readwrite
    而後在最後添加一行
    fox    readwrite

    # chmod 400 jmxremote.access

    3) 配置Tomcat啓動參數
    # cd $CATALINA_HOME/bin
    # vi catalina.sh

    找到如下一行
    # ----- Execute The Requested Command -----------------------------------------
    在其上方添加一段腳本 加在最後的目的是要沿用以前的JAVA_OPTS和CATALINA_HOME變量設置(特別是堆內存參數設置) 網上文章說法有直接設置JAVA_OPTS的 不過這樣設置在stop的時候會有異常拋出 雖然不影響使用
    (參數意義依次是:
        -Dcom.sun.management.jmxremote 啓用JMX遠程監控
        -Dcom.sun.management.jmxremote.port=9004 使用端口9004(可隨意指定只要不衝突)
        -Dcom.sun.management.jmxremote.authenticate=true 遠程鏈接須要密碼認證
        -Dcom.sun.management.jmxremote.ssl=false 不使用SSL(SSL我試了屢次都沒有配置成功:P 暫時不開啓)
        -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access 使用指定的JMX賬號受權文件
        -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password 使用指定的JMX賬號文件)


    # ----- JMX Config Start -----
    if [ "$1" = "run" ]; then
      JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password"
    elif [ "$1" = "start" ]; then
      JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=$CATALINA_HOME/conf/jmxremote.access -Dcom.sun.management.jmxremote.password.file=$CATALINA_HOME/conf/jmxremote.password"
    fijava

   
    # ----- JMX Config End -----shell

   也就是說須要在tomcat的bin下須要在catalina.sh下加入以下代碼便可。tomcat

    # ----- JMX Config Start -----
    if [ "$1" = "run" ]; then
      JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.password"
    elif [ "$1" = "start" ]; then
      JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=10207 -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.access.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.access -Dcom.sun.management.jmxremote.password.file=/usr/java/jdk1.6.0_32/jre/lib/management/jmxremote.password"
    fi
    # ----- JMX Config End -----

export JAVA_OPTS  (重要)服務器

   而後咱們要作的就是進入的/usr/java/jdk1.6.0_32/jre/lib/management下.net

   

  有個模板,拷貝一份做爲jmxremote.password,切記,這個文件權限比較特殊,我用的時候用的400blog

   記得jmsremote.password最後內存

        monitorRole  QED
        controlRole   R&Dssl

   前的註釋去掉(系統自帶的帳號和密碼,建議本身新增一個,新增的時候記得去jmxremote.access中付給帳號讀寫權限) rem

        而後就能夠了。get

       

       再就是注意一下hostname那部分,應該就直接能夠在客戶端輸入jconsole而後輸入IP地址,端口,帳號,密碼,你就能夠監控tomcat了

        再次感謝@逝水fox大神

       vi /etc/hosts 修改主機名爲外網IP地址,這個很重要,要否則鏈接不上...

WIndows訪問Linux服務器Tomcat:使用JDK自帶jvisualvm監控tomcat

相關文章
相關標籤/搜索