注意:
如果编译Zabbix Server端的时候,没有开启--enable-java (Zabbix Java gateway),那需要重新编译源码。
1、重新编译源码(源码安装建议不要删除,保存起来,以后需要重新编译很快,因为编译过的*.o,不用再进行重新编译,只编译新功能的代码)
[[email protected] ~ ]# cd zabbix-4.4.3 [[email protected]-v2 zabbix-4.4.3]# ./configure --prefix=/data/application/zabbix-4.4.3 --enable-server --enable-agent --with-mysql=/data/application/mysql-5.7.25/bin/mysql_config --enable-ipv6 --with-net-snmp --with-libcurl --with-libxml2 --enable-java [[email protected]-v2 zabbix-4.4.3]# make && make install #查看安装好,多出的程序 [[email protected]-v2 ~]# tree /data/application/zabbix-4.4.3/sbin/ /data/application/zabbix-4.4.3/sbin/ ├── zabbix_agentd ├── zabbix_java │ ├── bin │ │ └── zabbix-java-gateway-4.4.3.jar │ ├── lib │ │ ├── android-json-4.3_r3.1.jar │ │ ├── logback-classic-0.9.27.jar │ │ ├── logback-console.xml │ │ ├── logback-core-0.9.27.jar │ │ ├── logback.xml │ │ └── slf4j-api-1.6.1.jar │ ├── settings.sh │ ├── shutdown.sh │ └── startup.sh └── zabbix_server
2、配置zabbix-java-gateway
[[email protected] zabbix_java]# vi /data/application/zabbix-4.4.3/sbin/zabbix_java/settings.sh ... 4 ### Option: zabbix.listenIP 5 # IP address to listen on. 6 # 7 # Mandatory: no 8 # Default: #监听的网口地址 9 LISTEN_IP="0.0.0.0" 10 11 ### Option: zabbix.listenPort 12 # Port to listen on. 13 # 14 # Mandatory: no 15 # Range: 1024-32767 16 # Default: #监听的端口 17 LISTEN_PORT=10052 19 ### Option: zabbix.pidFile 20 # Name of PID file. 21 # If omitted, Zabbix Java Gateway is started as a console application. 22 # 23 # Mandatory: no 24 # Default: 25 # PID_FILE= 26 # 服务启动的pid文件 27 PID_FILE="/data/application/zabbix-4.4.3/log/zabbix_java.pid" 28 29 ### Option: zabbix.startPollers 30 # Number of worker threads to start. 31 # 32 # Mandatory: no 33 # Range: 1-1000 34 # Default: # 开启的工作线程数 35 START_POLLERS=5
3、zabbix-java-gateway的服务开启
# 开启zabbix-java-gateway的服务 [[email protected]-v2 zabbix-4.4.3]# /data/application/zabbix-4.4.3/sbin/zabbix_java/startup.sh # 检查端口是否开启 [[email protected]-v2 ~]# netstat -tunlp | grep java tcp6 0 0 :::10052 :::* LISTEN 95040/java
4、配置Zabbix Server端
# 配置Zabbix Server端的配置文件 [[email protected]-v2 ~]# vi /data/application/zabbix-4.4.3/etc/zabbix_server.conf ... 276 ### Option: JavaGateway 277 # IP address (or hostname) of Zabbix Java gateway. 278 # Only required if Java pollers are started. 279 # 280 # Mandatory: no 281 # Default: 282 JavaGateway=192.168.10.96 283 284 ### Option: JavaGatewayPort 285 # Port that Zabbix Java gateway listens on. 286 # 287 # Mandatory: no 288 # Range: 1024-32767 289 # Default: 290 JavaGatewayPort=10052 291 292 ### Option: StartJavaPollers 293 # Number of pre-forked instances of Java pollers. 294 # 295 # Mandatory: no 296 # Range: 0-1000 297 # Default: 298 StartJavaPollers=5 ... # 重启Zabbix Server端服务 [[email protected]-v2 ~]# /etc/init.d/zabbix_server restart
5、在Tomcat服务开启JMX协议
5.1、JMX协议开启会产生两个端口: 一、注册端口(即是我们配置【sun.management.jmxremote.port=12345】) 二、JMX服务端口,这个端口是随机生成,所以在固定下来,可以防火墙开放#注意:以上两个端口必须在防火墙开启出来。否则JMX一定不会开启成功
5.2、固定服务端口的方法:首先到官网(https://tomcat.apache.org)下载jmx扩展插件:这里使用的是Tomcat 7,根据自己版本,自己行下载,因为是官方提供的,所以放心下载。
5.3、linux下载方法 #进入tomcat jar库的目录 [[email protected]-v2 ~]# cd /data/application/apache-tomcat-8.5.38_custom/lib/ #直接使用wget下载jar包 [[email protected]-v2 lib]# wget http://mirrors.tuna.tsinghua.edu.cn/apache/tomcat/tomcat-7/v7.0.99/bin/extras/catalina-jmx-remote.jar 5.4、注册到tomcat使之生效 [[email protected]-v2 ~]# vi /data/application/apache-tomcat-8.5.38_custom/conf/server.xml ... 22 <Server port="8006" shutdown="SHUTDOWN"> 23 <Listener className="org.apache.catalina.startup.VersionLoggerListener" /> 24 <!-- Security listener. Documentation at /docs/config/listeners.html 25 <Listener className="org.apache.catalina.security.SecurityListener" /> 26 --> 27 <!--APR library loader. Documentation at /docs/apr.html --> 28 <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 29 <!-- Prevent memory leaks due to use of particular java/javax APIs--> 30 <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 31 <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 32 <Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <!-- rmiRegistryPortPlatform : 注册端口,rmiServerPortPlatform : jmx服务端口--> 33 <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="12345" rmiServerPortPlatform="10002" /> ...
5.5、Tomcat 开启jmx的配置
#复制配置密码的文件 [[email protected]-v2 ~]# cp /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.password.template /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.password #配置jmx密码文件,设置只有root用户才读写权限 [[email protected]-v2 ~]# chmod 600 /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.password #配置jmx用户权限文件,设置只有root用户才读写权限 [[email protected]-v2 ~]# chmod 600 /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.access #设置监控的账号和密码 [[email protected]-v2 ~]# vi /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.password 59 # Following are two commented-out entries. The "measureRole" role has 60 # password "QED". The "controlRole" role has password "R&D". 61 # #账号 密码 62 monitorRole abcabc123 63 # controlRole R&D #设置角色的权限 [[email protected]-v2 ~]# vi /data/application/jdk1.8.0_152/jre/lib/management/jmxremote.access 72 # o The "monitorRole" role has readonly access. 73 # o The "controlRole" role has readwrite access and can create the standard 74 # Timer and Monitor MBeans defined by the JMX API. 75 76 monitorRole readonly 77 controlRole readwrite 78 create javax.management.monitor.*,javax.management.timer.* 79 unregister [[email protected]-v2 ~]# vi /data/application/apache-tomcat-8.5.38_custom/bin/catalina.sh CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=192.168.10.95 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=/data/application/jdk1.8.0_152/jre/lib/management/jmxremote.password -Dcom.sun.management.jmxremote.access.file=/data/application/jdk1.8.0_152/jre/lib/management/jmxremote.access"
5.6、重启tomcat服务(略)
5.7、检查开启的端口
[[email protected] ~]# netstat -tunlp | grep java tcp6 0 0 :::10002 :::* LISTEN 106539/java tcp6 0 0 :::8088 :::* LISTEN 106539/java tcp6 0 0 :::12345 :::* LISTEN 106539/java tcp6 0 0 :::8443 :::* LISTEN 72188/java
6、在tomcat服务器防火墙放行jmx协议的12345和10002端口
[[email protected] ~]# firewall-cmd --permanent --add-port=12345/tcp success
[[email protected] ~]# firewall-cmd --permanent --add-port=10002/tcp success
[[email protected]-v2 ~]# firewall-cmd --reload success
7、用java自带的工具测试【jconsole.exe】和【jvisualvm.exe】
7.1、【jconsole.exe】
显示效果
7.2、【jvisualvm.exe】
显示效果
8、开始在Zabbix Server配置JMX
9、增加JMX的模板
点击【更新】
由于设置账号和密码,批量修改用户名和密码
10、查看JMX是否配置成功
11、利用jmx协议自定义监控jvm堆使用内存(必须会)
11.1、利用【jconsole.exe】工具查询key项的值【这里以堆使用内存为例】
键值格式: jmx["ObjectName",属性值]
11.2、组装jmx[]第一项值
jmx["java.lang:type=Memory",]
11.3、组装jmx[]第二项
#最终监控项组装成功jmx["java.lang:type=Memory",HeapMemoryUsage.used]
11.4、开始配置该监控项
11.5、配置画图
11.6、查看画图的效果
12、有关JVM更多参数的监控自行利用上面的工具,获取参数进行监控
原文地址:https://www.cnblogs.com/ygbh/p/12145371.html
时间: 2024-11-08 22:56:08