Zabbix监控篇-通过JMX监控Tomcat

释放双眼,带上耳机,听听看~!

系统环境

Zabbix_Server

[root@Zabbix_Server_56 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@Zabbix_Server_56 ~]# uname -r
3.10.0-862.el7.x86_64
[root@Zabbix_Server_56 ~]# hostname
Zabbix_Server_56.7
[root@Zabbix_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

[root@Zabbix_Client_56 ~]# cat /etc/redhat-release 
CentOS Linux release 7.5.1804 (Core) 
[root@Zabbix_Client_56 ~]# uname -r 
3.10.0-862.el7.x86_64
[root@Zabbix_Client_56 ~]# hostname
Zabbix_Client_56.8
[root@Zabbix_Client_56 ~]# ip a| grep 192.168.
    inet 192.168.56.8/24 brd 192.168.56.255 scope global noprefixroute dynamic eth0

JDK环境部署

注意:Zabbix监控tomcat需要通过JMX方式监控,JMX监控方式依赖JAVA环境,在此安装JDK1.8,以下是JDK下载页面,下载完成上传到服务器

JDK下载地址:https://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
[root@Zabbix_Server_56 src]# tar xf jdk-8u161-linux-x64.tar.gz  
[root@Zabbix_Server_56 src]# mv jdk1.8.0_161 /usr/local/java 
[root@Zabbix_Server_56 src]# vim /etc/profile           
#################JAVA#################
export JAVA_HOME=/usr/local/java
export JRE_HOME=/usr/local/java/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
export PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH
[root@Zabbix_Server_56 src]# source /etc/profile
[root@Zabbix_Server_56 src]# java -version
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_Server编译选项

注意:编译是需要加上 --enable-java来启用通过JMX监控tomcat的支持,zabbix server安装请看Zabbix4.0 Server安装部署

./configure --prefix=/usr/local/zabbix\
--enable-server\
--enable-agent\
--with-mysql\
--enable-java\      #添加--enable-java
--enable-ipv6\
--with-net-snmp\
--with-libcurl\
--with-libxml2\
--enable-mbstring

修改Zabbix配置文件

修改Zabbix_Server的java配置文件

[root@Zabbix_Server_56 /]# grep -Ev "#|^$" /usr/local/zabbix/sbin/zabbix_java/settings.sh 
LISTEN_IP="0.0.0.0"             #监听服务器地址
LISTEN_PORT=10052                  #监听zabbix_java进程的端口,默认是10052
PID_FILE="/tmp/zabbix_java.pid"  #zabbix_java的pid路径
START_POLLERS=5                  #zabbix_java的进程数
TIMEOUT=10                          #zabbix_java的超时时间

修改Zabbix_server的主配置文件

[root@Zabbix_Server_56 /]# grep -Ev "#|^$" /usr/local/zabbix/etc/zabbix_server.conf
    LogFile=/tmp/zabbix_server.log
    DBHost=localhost
    DBName=zabbix
    DBUser=zabbix
    StartPollers=5
    StartPollersUnreachable=1
    StartTrappers=5
    StartPingers=5
    StartDiscoverers=1
    StartHTTPPollers=1
    JavaGateway=192.168.56.7           #Java网关地址,即为Zabbix Server本身地址
    JavaGatewayPort=10052              #Java网关监控端口
    StartJavaPollers=5                 #启动Java监控的进程数
    CacheSize=1G
    HistoryCacheSize=256M
    HistoryIndexCacheSize=256M
    Timeout=10
    AlertScriptsPath=/usr/local/zabbix/etc/alertscripts  
    FpingLocation=/usr/sbin/fping
    LogSlowQueries=3000
    AllowRoot=1
    User=zabbix
    Include=/usr/local/zabbix/etc/zabbix_server.conf.d/*.conf

重启Zabbix_Server

[root@Zabbix_Server_56 /]# /usr/local/zabbix/sbin/zabbix_java/startup.sh    #启动zabbix_java进程
[root@Zabbix_Server_56 /]# ss -anplt | grep java                        #查看10052端口已经被java所占用
LISTEN     0      50          :::10052                   :::*                   users:(("java",pid=10328,fd=14))
[root@Zabbix_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 in 0.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:lib/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.JavaGateway
root      10362   1645  0 14:20 pts/0    00:00:00 grep --color=auto java
[root@Zabbix_Server_56 /]# /etc/init.d/zabbix_server restart
[root@Zabbix_Server_56 /]# ps -ef|grep zabbix_server               #查看zabbix server进程

Zabbix_Client配置

修改tomcat配置文件

[root@Zabbix_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"

下载相应监控的JMXjar包

注意:Tomcat可以通过jmx进行监控,默认是没有开启。在 tomcat 下载页面 Extras 类别中下载 JMX Remote jar 二进制包。放在 tomcat的lib目录下面。Jar包名称为catalina-jmx-remote.jar,该jar包需要相应版本需要对应tomcat版本。

该链接是下载catalina-jmx-remote.jar的链接,进去找到相应版本进行下载
下载地址:http://archive.apache.org/dist/tomcat/

[root@Zabbix_Client_56 /]# /usr/local/tomcat/bin/version.sh     #查看tomcat版本
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Server version: Apache Tomcat/9.0.12                        #该版本为9.0.12
Server built:   Sep 4 2018 22:13:41 UTC
Server number:  9.0.12.0
OS Name:        Linux
OS Version:     3.10.0-862.el7.x86_64
Architecture:   amd64
JVM Version:    1.8.0_181-b13
JVM Vendor:     Oracle Corporation

tomcat 9.0.12下载地址

wget http://archive.apache.org/dist/tomcat/tomcat-9/v9.0.12/bin/extras/catalina-jmx-remote.jar 
[root@Zabbix_Client_56 src]# mv catalina-jmx-remote.jar  /usr/local/tomcat/lib/
然后再到下面地址中去下载jmxcmd测试jar包
https://sourceforge.net/projects/jmxcmd/
[root@Zabbix_Client_56 src]# mv jmxcmd.jar /usr/local/tomcat/bin/

重启Tomcat和agent

[root@Zabbix_Client_56 src]# /usr/local/tomcat/bin/shutdown.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@Zabbix_Client_56 src]# /usr/local/tomcat/bin/startup.sh 
Using CATALINA_BASE:   /usr/local/tomcat
Using CATALINA_HOME:   /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME:        /usr/local/java/jre
Using CLASSPATH:       /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@Zabbix_Client_56 src]# /etc/init.d/zabbix_agentd restart
Zabbix agent terminated.
Zabbix agent started.
[root@Zabbix_Client_56 src]# ss -anplt | grep java          #可以看到12345端口已经被java占用
LISTEN     0      50          :::42526                   :::*                   users:(("java",pid=36174,fd=21))
LISTEN     0      1         ::ffff:127.0.0.1:8005                    :::*                   users:(("java",pid=36174,fd=74))
LISTEN     0      50          :::38760                   :::*                   users:(("java",pid=36174,fd=19))
LISTEN     0      100         :::8009                    :::*                   users:(("java",pid=36174,fd=58))
LISTEN     0      100         :::8080                    :::*                   users:(("java",pid=36174,fd=54))
LISTEN     0      50          :::12345                   :::*                   users:(("java",pid=36174,fd=20))

然后测试网络是否通讯,如果网络无问题,在Web页面添加监控即可

人已赞赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧