1. 准备JDK环境
#vim /etc/profile
export JAVA_HOME=/usr/local/jdk
export TOMCAT_HOME=/usr/local/tomcat
export PATH=$PATH:$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOMOE/bin
[root@CentOS8 ~]# source /etc/profile
[root@CentOS8 ~]# java -version
openjdk version "1.8.0_312"
OpenJDK Runtime Environment (build 1.8.0_312-b07)
OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
2. 准备tomcat
[root@CentOS8 tomcat]# cd /usr/local/tomcat
[root@CentOS8 tomcat]# pwd
/usr/local/tomcat
[root@CentOS8 tomcat]# ls -al
total 136
drwxr-xr-x. 9 root root 220 Nov 13 11:42 .
drwxr-xr-x. 18 root root 220 Nov 16 09:41 ..
-rw-r-----. 1 root root 21039 Nov 8 06:28 BUILDING.txt
-rw-r-----. 1 root root 6166 Nov 8 06:28 CONTRIBUTING.md
-rw-r-----. 1 root root 60393 Nov 8 06:28 LICENSE
-rw-r-----. 1 root root 2333 Nov 8 06:28 NOTICE
-rw-r-----. 1 root root 3298 Nov 8 06:28 README.md
-rw-r-----. 1 root root 6776 Nov 8 06:28 RELEASE-NOTES
-rw-r-----. 1 root root 16109 Nov 8 06:28 RUNNING.txt
drwxr-x---. 2 root root 4096 Nov 16 23:58 bin
drwx------. 3 root root 254 Nov 13 11:44 conf
drwxr-x---. 2 root root 4096 Nov 13 11:42 lib
drwxr-x---. 2 root root 4096 Nov 16 23:58 logs
drwxr-x---. 2 root root 30 Nov 13 11:42 temp
drwxr-x---. 7 root root 81 Nov 8 06:28 webapps
drwxr-x---. 3 root root 22 Nov 13 11:44 work
[root@CentOS8 tomcat]# /usr/local/tomcat/bin/catalina.sh start
3. 验证tomcat web页面
4. 部署java gateway服务器
java gateway是一台独立于zabbix server和zabbix agent的组件,也就是java gateway可以是一台单独的服务器。
本次实验和zabbix server部署在同一台服务器上。
#sudo rpm -Uvh https://repo.zabbix.com/zabbix/6.0/rhel/8/x86_64/zabbix-release-6.0-4.el8.noarch.rpm
# sudo dnf clean all
# dnf install zabbix-gateway -y
[root@zabbix ~]# cat /etc/zabbix/zabbix_java_gateway.conf | egrep -v "^#|^$"
LISTEN_IP="0.0.0.0"
LISTEN_PORT=10052
PID_FILE="/var/run/zabbix/zabbix_java_gateway.pid"
START_POLLERS=5
TIMEOUT=3
#systemctl restart zabbix-java-gateway.service
#systemctl status zabbix-java-gateway.service
[root@zabbix ~]# lsof -i :10052
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
java 65523 zabbix 13u IPv6 1403001 0t0 TCP *:10052 (LISTEN)
5. 配置zabbix-server调用java gateway
[root@zabbix ~]# cat /etc/zabbix/zabbix_server.conf | egrep -v "^#|^$"
LogFile=/var/log/zabbix/zabbix_server.log
LogFileSize=0
PidFile=/run/zabbix/zabbix_server.pid
SocketDir=/run/zabbix
DBName=zabbix
DBUser=zabbix
DBPassword=Passw0rd
JavaGateway=10.211.55.13 #监听地址
JavaGatewayPort=10052 # 指定java gateway的服务器监听端口,如果默认端口可以不写
StartJavaPollers=5 # 启动多少个进程去轮询java gateway
SNMPTrapperFile=/var/log/snmptrap/snmptrap.log
Timeout=4
LogSlowQueries=3000
StatsAllowedIP=127.0.0.1
6. 验证java Pollers
# systemctl restart zabbix-server
[root@zabbix ~]# ps -ef| grep java
zabbix 31783 31759 0 11月13 ? 00:00:05 /usr/sbin/zabbix_server: java poller #1 [got 0 values in 0.000081 sec, idle 5 sec]
zabbix 31784 31759 0 11月13 ? 00:00:05 /usr/sbin/zabbix_server: java poller #2 [got 0 values in 0.000061 sec, idle 5 sec]
zabbix 31785 31759 0 11月13 ? 00:00:05 /usr/sbin/zabbix_server: java poller #3 [got 0 values in 0.000029 sec, idle 5 sec]
zabbix 31786 31759 0 11月13 ? 00:00:05 /usr/sbin/zabbix_server: java poller #4 [got 0 values in 0.000060 sec, idle 5 sec]
zabbix 31787 31759 0 11月13 ? 00:00:05 /usr/sbin/zabbix_server: java poller #5 [got 0 values in 0.000022 sec, idle 5 sec]
zabbix 65523 1 0 11月14 ? 00:03:23 java -server -Dlogback.configurationFile=/etc/zabbix/zabbix_java_gateway_logback.xml -classpath lib:lib/android-json-4.3_r3.1.jar:lib/logback-classic-1.2.9.jar:lib/logback-core-1.2.9.jar:lib/slf4j-api-1.7.32.jar:bin/zabbix-java-gateway-6.0.35.jar -Dzabbix.pidFile=/var/run/zabbix/zabbix_java_gateway.pid -Dzabbix.listenIP=0.0.0.0 -Dzabbix.listenPort=10052 -Dzabbix.startPollers=5 -Dzabbix.timeout=3 -Dsun.rmi.transport.tcp.responseTimeout=3000 com.zabbix.gateway.JavaGateway
7. tomcat开启jmx监控
#vim /usr/local/tomcat/bin/catalina.sh
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote" #启用远程监控jmx
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=10.211.55.10" # tomcat主机自己的地址
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.port=12345" # 默认启动的jmx端口号,要和zabbix添加主机的端口一致即可
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.rmi.port=12345"
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.authenticate=false" # 不使用用户名密码
JAVA_OPTS="$JAVA_OPTS -Dcom.sun.management.jmxremote.ssl=false" # 不使用ssl认证
#/usr/local/tomcat/bin/catalina.sh stop
#/usr/local/tomcat/bin/catalina.sh start
8. 通过jconsole验证jmx数据
在windows或者其他带图形桌面的机器安装jdk,安装完成后在bin目录下会自动安装jconsole
9. 非安全连接
10. 验证当前连接
11. zabbix-server关联模版
12. 验证当前jmx状态和数据
验证jmx状态
验证jmx数据
参考链接:
https://www.cnblogs.com/think-in-java/p/6138439.html
https://www.bookstack.cn/read/zabbix-6.0-zh/b656c6b018d62ee
https://www.cnblogs.com/Sherry-XRJ/p/11857632.html