监控Tomcat

 

监控Tomcat

  无论是使用Zabbix、还是jconsole等其他工具,当需要监控Tomcat时,需对Tomcat进行jmx配置。此处以Linux系统为例,配置Tomcat。

  注意:

    下文中出现的:$TOMCATHOME 代表Tomcat安装的路径;$JAVA_HOME代表Java jdk的安装路径。

    如果,将Tomcat安装在: /u01/app/tomcat 这个目录中,那么$TOMCATHOME= /u01/app/tomcat 

  1. 在$TOMCATHOME/bin/catalina.sh中的CATALINA_OPTS 属性中添加如下内容:

  

CATALINA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=8999 -Dcom.sun.management.jmxremote.rmi.port=8999 -Djava.rmi.server.hostname=192.168.43.130 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/u02/app/svnadmin-tomcat/conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/u02/app/svnadmin-tomcat/conf/jmxremote.access"

-Dcom.sun.management.jmxremote.port 代表jmx监控的端口,这个端口号自定义,只要端口不冲突即可。
-Djava.rmi.server.hostname 这个配置当前系统的ip地址
 -Dcom.sun.management.jmxremote.ssl

我也不知道这个干啥用的,看官网配置时就有:http://tomcat.apache.org/tomcat-6.0-doc/monitoring.html#Enabling_JMX_Remote

 -Dcom.sun.management.jmxremote.authenticate 是否需要密码验证,配置true:需要密码。如果配置false下面两项就无需配置
-Dcom.sun.management.jmxremote.password.file 配置监控的账户密码
-Dcom.sun.management.jmxremote.access.file 配置监控账户
     
  1. 拷贝$JAVA_HOME/jre/lib/management 中的两个文件:jmxremote.access、jmxremote.password.template 至 $TOMCATHOME/conf 目录中

    注意:

      $TOMCATEHOME/conf文件夹下的jmxremote.password.template 名字需要重新命令:jmxremote.password

      指令:mv jmxremote.password.template jmxremote.password

  1. 在$TOMCATHOME/conf中的配置文件中(jmxremote.access)添加用户名:charles(用户名自定义),在配置文件(jmxremote.password)文件中添加用户名和密码:charles charles@1314

      jmxremote.access 文件:

        在文件最下方,注释了monitorRole   readonly ,在上面新增了一行:charles readonly

      

      jmxremote.password 文件

        在文件最下方,新增一行:charles Charles@1314

       

  1. 配置jmxremote.access和jmxremote.password 权限为:600

    指令: chmod 600 jmxremote.* 

    

  1. 使用root用户配置 /etc/hosts文件,添加 :本机IP    本机主机名

    指令:vim /etc/hosts 

    

    添加完成后,测试ping 一下,是否能ping通? 我的能ping通,说明没问题。

    

  1. 重启应用服务器

    

    指令:

      ps -ef | grep java ,查看Tomcat的进程PID

      kill -9 进程 PID

      cd $TOMCATHOME/bin

      sh startup.sh

      

  1. 测试:使用jconsole远程连接监控

        

   

 

 

注意:

  由于虚拟机中的linux系统没有关闭防火墙,所以我在宿主机上初次远程链接的时候没有成功。经排查,是由于防火墙原因。在虚拟机中将8999端口释放即可。或者关闭防火墙。

  

  释放8999端口指令:

    vim /etc/sysconfig/iptables

    添加一行:-A INPUT -m state --state NEW -m tcp -p tcp --dport 8999 -j ACCEPT

    重启防火墙:service iptables restart

    

如有问题,欢迎纠正!!!

如有转载,请标明源处:https://www.cnblogs.com/Charles-Yuan/p/9735293.html

原文地址:https://www.cnblogs.com/Charles-Yuan/p/9735293.html