一、安装JAVA环境
安装JDK
yum install java-11-openjdk-devel -y
验证
java -version
配置环境变量
vi /etc/profile export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.22.0.7-1.el7_9.x86_64/ export PATH=$PATH:$JAVA_HOME/bin export CALSSPATH=.:$JAVA_HOME
使配置生效
source /etc/profile
检查配置
echo $JAVA_HOME /usr/lib/jvm/java-11-openjdk-11.0.22.0.7-1.el7_9.x86_64/
二、安装Tomcat
下载Tomcat
wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.85/bin/apache-tomcat-9.0.85.tar.gz
解压
tar -zxvf apache-tomcat-9.0.85.tar.gz
移动Tomcat文件夹到/usr/local
mv apache-tomcat-9.0.85 /usr/local/
三、开启JMX协议
配置jmxremote远程监控功能
vi /usr/local/apache-tomcat-9.0.85/bin/catalina.sh
定位到CATALINA_OPTS后在下方添加监控参数
参数解析:
-Dcom.sun.management.jmxremote # 启动JMX监控
-Djava.rmi.server.hostname=10.77.1.53 # 指定本地IP
-Dcom.sun.management.jmxremote.port=12345 # JMX远程连接端口
-Dcom.sun.management.jmxremote.rmi.port=12345 #实际通信用的端口(可以指定同一个端口)
-Dcom.sun.management.jmxremote.ssl=false # 禁用ssl加密
-Dcom.sun.management.jmxremote.authenticate=false #禁用身份认证# CATALINA_OPTS (Optional) Java runtime options used when the "start", # "run" or "debug" command is executed. # Include here and not in JAVA_OPTS all options, that should # only be used by Tomcat itself, not by the stop process, # the version command etc. # Examples are heap size, GC logging, JMX ports etc. CATALINA_OPTS="-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=10.77.1.53 -Dcom.sun.management.jmxremote.port=12345 -Dcom.sun.management.jmxremote.rmi.port=12345 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false"
启动Tomcat
/usr/local/apache-tomcat-9.0.85/bin/startup.sh
检查端口,出现12345端口代表启动成功
netstat -ntlp | grep 12345 tcp6 0 0 :::12345 :::* LISTEN 21294/java
四、安装zabbix-java-gateway
安装zabbix4.0的rpm(建议根据实际的zabbix版本安装,虽然说高版本的agent会向下兼容)
rpm -Uvh https://mirrors.aliyun.com/zabbix/zabbix/4.0/rhel/7/x86_64/zabbix-release-4.0-2.el7.noarch.rpm
清理缓存
yum clean all
安装
yum install zabbix-java-gateway -y
修改配置文件
vi /etc/zabbix/zabbix_java_gateway.conf
定位到LISTEN_IP后在下方添加监控参数
参数解析:
LISTEN_IP="0.0.0.0" # java网关的监听地址,保持0.0.0.0即可
LISTEN_PORT=10052 # java网关的监听端口
START_POLLERS=5 # 启用多线程### Option: zabbix.listenIP # IP address to listen on. # # Mandatory: no # Default: # LISTEN_IP="0.0.0.0" LISTEN_IP="0.0.0.0" LISTEN_PORT=10052 START_POLLERS=5
启动
systemctl start zabbix-java-gateway
设置开启自启
systemctl start zabbix-java-gateway
检查端口,出现10052端口代表启动成功
netstat -ntlp | grep 10052 tcp6 0 0 :::10052 :::* LISTEN 21800/java
五、配置zabbix-server
编辑zabbix_server配置文件
vi /etc/zabbix/zabbix_server.conf
定位到JavaGateway后在下方添加监控参数
参数解析:
JavaGateway=10.77.1.53 # 指定java网关地址
JavaGatewayPort=10052 # 指定java网关端口
StartJavaPollers=5 # 启动多线程### Option: JavaGateway # IP address (or hostname) of Zabbix Java gateway. # Only required if Java pollers are started. # # Mandatory: no # Default: # JavaGateway= JavaGateway=10.77.1.53 JavaGatewayPort=10052 StartJavaPollers=5
重启zabbix-server
systemctl restart zabbix-server
重启zabbix-java-gateway
systemctl restart zabbix-java-gateway
六、到zabbix-server端配置JVM监控
- 添加主机
- 添加JVM模板(注意要先点击添加,模板添加上去再更新,不然会导致获取不到监控数据)
- 查看数据
至此,JVM监控已完成
0 条评论