Zabbix using JMX to monitor Tomcat
- JDK Environment Deployment
- Zabbix compilation options
- Modifying the Zabbix configuration file
- Restart Zabbix
- Tomcat Side Change configuration file
- Download the appropriate monitor JMX jar package
- Zabbix Web page Monitoring
System environment
Zabbix_server
[[email protected]_Server_56 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [[email protected]_Server_56 ~]# uname -r3.10.0-862.el7.x86_64[[email protected]_Server_56 ~]# hostnameZabbix_Server_56.7[[email protected]_Server_56 ~]# ip a | grep 192.168. inet 192.168.56.7/24 brd 192.168.56.255 scope global noprefixroute dynamic eth0
Zabbix_client
[[email protected]_Client_56 ~]# cat /etc/redhat-release CentOS Linux release 7.5.1804 (Core) [[email protected]_Client_56 ~]# uname -r 3.10.0-862.el7.x86_64[[email protected]_Client_56 ~]# hostnameZabbix_Client_56.8[[email protected]_Client_56 ~]# ip a| grep 192.168. inet 192.168.56.8/24 brd 192.168.56.255 scope global noprefixroute dynamic eth0
JDK Environment Deployment
Note: Zabbix monitor tomcat needs to be monitored by JMX, jmx monitoring relies on the Java environment, where JDK1.8 is installed, the following is the JDK download page, download complete upload to the server
https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html[[email protected]_Server_56 src]# tar xf jdk-8u161-linux-x64.tar.gz [[email protected]_Server_56 src]# mv jdk1.8.0_161 /usr/local/java [[email protected]_Server_56 src]# vim /etc/profile #在profile文件最后添加java的环境变量#################JAVA#################export JAVA_HOME=/usr/local/javaexport JRE_HOME=/usr/local/java/jreexport CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/libexport PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH[[email protected]_Server_56 src]# source /etc/profile[[email protected]_Server_56 src]# java -version #查看java版本信息java version "1.8.0_161"Java(TM) SE Runtime Environment (build 1.8.0_161-b12)Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
Zabbix compilation options
Compile is required to add--enable-java to enable monitoring Tomcat through JMX support, Zabbix server installation see the corresponding document in the station
./configure --prefix=/usr/local/zabbix --enable-server --enable-agent --with-mysql --enable-java --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-mbstring
Modifying the Zabbix configuration file
Modifying the Zabbix Java configuration file
[[email protected]_Server_56 /]# grep -Ev "#|^$" /usr/local/zabbix/sbin/zabbix_java/settings.sh LISTEN_IP="0.0.0.0" #监听服务器地址LISTEN_PORT=10052 #监听zabbix_java进程的端口,默认是10052PID_FILE="/tmp/zabbix_java.pid" #zabbix_java的pid路径START_POLLERS=5 #zabbix_java的进程数TIMEOUT=10 #zabbix_java的超时时间
Modifying the Zabbix_server configuration file
[[email protected]_Server_56 /]# grep -Ev "#|^$" /usr/local/zabbix/etc/zabbix_server.confLogFile=/tmp/zabbix_server.logDBHost=localhostDBName=zabbixDBUser=zabbixStartPollers=5StartPollersUnreachable=1StartTrappers=5StartPingers=5StartDiscoverers=1StartHTTPPollers=1JavaGateway=192.168.56.7 #Java网关地址,即为Zabbix Server本身地址JavaGatewayPort=10052 #Java网关监控端口StartJavaPollers=5 #启动Java监控的进程数CacheSize=1GHistoryCacheSize=256MHistoryIndexCacheSize=256MTimeout=10AlertScriptsPath=/usr/local/zabbix/etc/alertscripts FpingLocation=/usr/sbin/fpingLogSlowQueries=3000AllowRoot=1User=zabbixInclude=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf
Restart Zabbix Server
[[email protected]_server_56/]#/usr/local/zabbix/sbin/zabbix_java/startup.sh #启动zabbix_java进程 [[email protected]_server_56/]# SS-ANPLT | grep java #查看10052端口已经被java所占用LISTEN 0:: 10052:::* Users: (("Java", pid=10328,fd=14)) [[email protected]_server_56/]# ps-ef|grep Java #ps所看到的进程也是zabbix_java进程root 8829 8811 0 13:37? 00:00:00/usr/local/zabbix/sbin/zabbix_server:java poller #1 [got 0 values in 0.000001 sec, idle 5 sec]root 8830 8811 0 13:37? 00:00:00/usr/local/zabbix/sbin/zabbix_server:java poller #2 [got 0 values in 0.000002 sec, idle 5 sec]root 8831 8811 0 13:37? 00:00:00/usr/local/zabbix/sbin/zabbix_server:java poller #3 [got 0 values in 0.000022 sec, idle 5 sec]root 8832 8811 0 13:37? 00:00:00/usr/local/zabbix/sbin/zabbix_server:java poller #4 [got 0 values in0.000001 sec, idle 5 sec]root 8833 8811 0 13:37? 00:00:00/usr/local/zabbix/sbin/zabbix_server:java poller #5 [got 0 values in 0.000001 sec, idle 5 sec]root 10328 1 0 14:19 pts/0 00:00:00 java-server-classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-0.9.27.jar:l ib/logback-core-0.9.27.jar:lib/slf4j-api-1.6.1.jar:bin/zabbix-java-gateway-4.0.0.jar-dzabbix.pidfile=/tmp/ ZABBIX_JAVA.PID-DZABBIX.LISTENIP=0.0.0.0-DZABBIX.LISTENPORT=10052-DZABBIX.STARTPOLLERS=5-DZABBIX.TIMEOUT=10- dsun.rmi.transport.tcp.responsetimeout=10000 com.zabbix.gateway.JavaGatewayroot 10362 1645 0 14:20 pts/0 00:00: --color=auto grep java[[email protected]_server_56/]#/etc/init.d/zabbix_server restart[[email protected]_server_56/]# ps-ef|grep zabbix_server #查看zabbix Server Process
Tomcat Side Change configuration file
The monitored side tomcat also needs to change the configuration file
[[email protected]_Client_56 /]# vim /usr/local/tomcat/bin/catalina.sh #在catalina文件中添加以下内容,端口为12345,hostanme为tomcat被监控的IP地址CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.56.8"
Download the appropriate monitor JMX jar package
Note: Tomcat can be monitored by jmx and is not turned on by default. Download the JMX Remote jar binary package in the Tomcat download page Extras category. Put it under Tomcat's Lib directory. The jar package name is Catalina-jmx-remote.jar, and the jar package requires the corresponding version of the Tomcat version
http://archive.apache.org/dist/tomcat/ #该链接是下载catalina-jmx-remote.jar的链接,进去找到相应版本进行下载[[email protected]_Client_56 /]# /usr/local/tomcat/bin/version.sh #查看tomcat版本Using CATALINA_BASE: /usr/local/tomcatUsing CATALINA_HOME: /usr/local/tomcatUsing CATALINA_TMPDIR: /usr/local/tomcat/tempUsing JRE_HOME: /usr/local/java/jreUsing CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jarServer version: Apache Tomcat/9.0.12 #该版本为9.0.12Server built: Sep 4 2018 22:13:41 UTCServer number: 9.0.12.0OS Name: LinuxOS Version: 3.10.0-862.el7.x86_64Architecture: amd64JVM Version: 1.8.0_181-b13JVM Vendor: Oracle Corporation
wget http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.12/bin/extras/catalina-jmx-remote.jar #9.0.12
[[email protected]_Client_56 src]# mv catalina-jmx-remote.jar /usr/local/tomcat/lib/然后再到下面地址中去下载jmxcmd测试jar包https://sourceforge.net/projects/jmxcmd/[[email protected]_Client_56 src]# mv jmxcmd.jar /usr/local/tomcat/bin/
Restarting Tomcmat and Agentd
[[email protected]_client_56 src]#/usr/local/tomcat/bin/shutdown.sh Using catalina_base:/usr/local/tomcatUsi Ng Catalina_home:/usr/local/tomcatusing catalina_tmpdir:/usr/local/tomcat/tempusing JRE_HOME:/usr/local/java/j Reusing CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar[[email protected]_client_56 src]#/usr/local/tomcat/bin/startup.sh Using catalina_base:/usr/local/tomcatusing CATALINA_ HOME:/usr/local/tomcatusing catalina_tmpdir:/usr/local/tomcat/tempusing jre_home:/usr/local/java/jreusing CLAS Spath:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jartomcat started. [[email protected]_client_56 src]#/etc/init.d/zabbix_agentd Restartzabbix agent terminated. Zabbix agent started. [[Email protected]_client_56 src]# SS-ANPLT | grep java #可以看到12345端口已经被java占用LISTEN 0::: 42526:::* US ERS: (("Java", PID=36174,fd=21)) LISTEN 0 1:: ffff:127.0.0.1:8005:::* Users: (("Java", p id=36174,fd=74)) LISTEN 0::: 38760:::* Users: (("Java", pid=36174,f d=19) LISTEN 0::: 8009:::* Users: (("Java", pid=36174,fd=58) LIST EN 0::: 8080:::* Users: (("Java", pid=36174,fd=54)) LISTEN 0 -:: 12345:::* Users: (("Java", pid=36174,fd=20))
Zabbix Web page Monitoring
Zabbix page added monitoring of Tomcat needs to be JMX-style
First temporarily add the Zabbix default comes with the Jmx template, back to the requirements of their own write monitoring Tomcat monitoring key values, create a template
Once added, you can see that the jmx turns green.
Zabbix self-contained monitoring of the monitoring items are not in Tomcat, so there will be a lot to find the key value and other errors, it is recommended that you write the Tomcat monitoring key values, self-template
Zabbix using JMX to monitor Tomcat