Zabbix版本:3.2.4
介绍
zabbix监控tomcat,需要zabbix_server开启java poller,zabbix_java开启javaGateway,端口10052,Tomcat JMX开启12345端口,提供性能数据。
数据获取流程为:java poller<-->javaGateway:10052<-->Tomcat:12345
1.1 配置Tomcat JMX
这里需要注意,必须增加-Djava.rmi.server.hostname选项,并且后面的IP就是tomcat服务器的IP
#配置jmx,在需要监控的tomcat服务器上,编辑catalina.sh,加入如下配置
[root@Tomcat bin]# sed -n '249p' /usr/local/tomcat/bin/catalina.sh
CATALINA_OPTS="-server -Xms256m -Xmx512m -XX:PermSize=64M -XX:MaxPermSize=128m -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=192.168.0.224 -Dcom.sun.management.jmxremote.port=12345"
1.2 重启Tomcat
[root@Tomcat bin]# /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/jdk
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
[root@Tomcat ~]# netstat -antup | grep java
[root@Tomcat bin]# /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/jdk
Using CLASSPATH: /usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar
Tomcat started.
[root@Tomcat zabbix]# netstat -antup | grep java
tcp 0 0 :::54031 :::* LISTEN 1521/java
tcp 0 0 :::8080 :::* LISTEN 1521/java
tcp 0 0 :::53881 :::* LISTEN 1521/java
tcp 0 0 :::12345 :::* LISTEN 1521/java #新增端口
tcp 0 0 ::ffff:127.0.0.1:8005 :::* LISTEN 1521/java
tcp 0 0 :::8009 :::* LISTEN 1521/java
1.3 编译zabbix,加入java支持
在zabbix server服务器上,编译安装zabbix-server,需要加上--enable-java,以支持jmx监控,如果之前的zabbix server没加此选项,那么需要重新编译安装,编译参数如下:
./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --enable-java --with-libxml2
特别提示: 在启用--enable-java编译zabbix之前,zabbix server服务器上需要安装JDK,并需要设置JAVA_HOME,以让系统能够识别到jdk的路径
1.3.1 在zabbix-server端安装JDK
#解压jdk
[root@Zabbix_Server ~]# tar xf jdk-8u60-linux-x64.tar.gz -C /usr/local/
[root@Zabbix_Server ~]# ln -s /usr/local/jdk1.8.0_60/ /usr/local/jdk
#配置java环境变量
[root@Zabbix_Server ~]# sed -i.ori '$a export JAVA_HOME=/usr/local/jdk\nexport PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH\nexport CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar' /etc/profile
[root@Zabbix_Server ~]# tail -3 /etc/profile
export JAVA_HOME=/usr/local/jdk
export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH
export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
#让环境变量立刻生效
[root@Zabbix_Server ~]# source /etc/profile
#检查java环境变量情况
[root@Zabbix_Server ~]# which java
/usr/local/jdk/bin/java
[root@Zabbix_Server ~]# java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
1.3.2 重新编译zabbix-server服务器端
#重新编译zabbix-server服务器端之前
[root@Zabbix_Server ~]# ll /usr/local/zabbix/sbin/
total 8604
-rwxr-xr-x 1 root root 1165774 Jan 20 15:16 zabbix_agentd
-rwxr-xr-x 1 root root 3672055 Jan 20 15:16 zabbix_proxy
-rwxr-xr-x 1 root root 3966037 Jan 20 15:16 zabbix_server
#开始重新编译zabbix-server服务器端
[root@Zabbix_Server ~]#
[root@Zabbix_Server ~]# /etc/init.d/zabbix_server stop
Shutting down zabbix_server: [ OK ]
[root@Zabbix_Server ~]# cd /usr/src/zabbix-3.2.4/
[root@Zabbix_Server zabbix-3.2.4]# ./configure --prefix=/usr/local/zabbix --with-mysql --with-net-snmp --with-libcurl --enable-server --enable-agent --enable-proxy --enable-java --with-libxml2
[root@Zabbix_Server zabbix-3.2.4]# make && make install
#重新编译zabbix-server服务器端之后
[root@Zabbix_Server zabbix-3.2.4]# cd /usr/local/zabbix/sbin/
[root@Zabbix_Server sbin]# ll
total 8608
-rwxr-xr-x 1 root root 1165774 Jan 25 22:22 zabbix_agentd
drwxr-xr-x 4 root root 4096 Jan 25 22:22 zabbix_java #多了一个目录
-rwxr-xr-x 1 root root 3672055 Jan 25 22:22 zabbix_proxy
-rwxr-xr-x 1 root root 3966037 Jan 25 22:22 zabbix_server
[root@Zabbix_Server sbin]# cd zabbix_java/
[root@Zabbix_Server zabbix_java]# ll
total 20
drwxr-xr-x 2 root root 4096 Jan 25 22:22 bin
drwxr-xr-x 2 root root 4096 Jan 25 22:22 lib
-rw-r--r-- 1 root root 791 Jan 25 22:22 settings.sh #java gateway配置脚本
-rwxr-xr-x 1 root root 545 Jan 25 22:22 shutdown.sh #停止java gateway服务
-rwxr-xr-x 1 root root 2025 Jan 25 22:22 startup.sh #启动java gateway服务
提示: java gateway服务的配置脚本settings.sh不需要修改任何配置。
1.3.3 启动java Gateway服务
[root@Zabbix_Server zabbix_java]# /usr/local/zabbix/sbin/zabbix_java/startup.sh
[root@Zabbix_Server zabbix_java]# netstat -antup | grep 10052
tcp 0 0 :::10052 :::* LISTEN 13126/java
1.4 修改zabbix server 配置
默认的情况下,zabbix server未启用javaPollers,需要修改zabbix_server.conf的如下配置
[root@Zabbix_Server zabbix]# cd /usr/local/zabbix/etc/
#修改以下配置文件的内容
[root@Zabbix_Server etc]# cat -n zabbix_server.conf | sed -n '215p;223p;231p'
215 # JavaGateway=
223 # JavaGatewayPort=10052
231 # StartJavaPollers=0
#将上述配置文件内容修改成如下
[root@Zabbix_Server etc]# cat -n zabbix_server.conf | sed -n '215p;223p;231p'
215 JavaGateway=127.0.0.1 #JavaGateway的地址
223 JavaGatewayPort=10052
231 StartJavaPollers=5
#查看已经打开的java poller进程
[root@Zabbix_Server ~]# ps -ef | grep "java poller" | grep -v grep
zabbix 13233 13172 0 Jan25 ? 00:00:00 /usr/local/sbin/zabbix_server: java poller #1 [got 0 values in 0.000001 sec, idle 5 sec]
zabbix 13234 13172 0 Jan25 ? 00:00:00 /usr/local/sbin/zabbix_server: java poller #2 [got 0 values in 0.000015 sec, idle 5 sec]
zabbix 13235 13172 0 Jan25 ? 00:00:00 /usr/local/sbin/zabbix_server: java poller #3 [got 0 values in 0.000001 sec, idle 5 sec]
zabbix 13236 13172 0 Jan25 ? 00:00:00 /usr/local/sbin/zabbix_server: java poller #4 [got 0 values in 0.000001 sec, idle 5 sec]
zabbix 13237 13172 0 Jan25 ? 00:00:00 /usr/local/sbin/zabbix_server: java poller #5 [got 0 values in 0.000001 sec, idle 5 sec]
1.5 重启zabbix_server服务
[root@Zabbix_Server ~]# /etc/init.d/zabbix_server start
Starting zabbix_server: [ OK ]
[root@Zabbix_Server ~]# netstat -antup | grep 10051
tcp 0 0 0.0.0.0:10051 0.0.0.0:* LISTEN 13172/zabbix_server
tcp 0 0 192.168.0.220:10051 192.168.0.221:56752 TIME_WAIT -
tcp 0 0 192.168.0.220:10051 192.168.0.221:56754 TIME_WAIT -
tcp 0 0 192.168.0.220:10051 192.168.0.221:56751 TIME_WAIT -
tcp 0 0 192.168.0.220:10051 192.168.0.220:47162 TIME_WAIT -
1.6 Zabbix图形界面配置
略....和导入Apache流程一致