yum install net-tools netstat命令
yum -y install bash-completion 命令自动补全包
https://github.com/qiueer/zabbix
基本监控流程:被监控端开启snmp或安装agent-----》zabbix端添加主机监控------》添加模板----》添加触发器
一、使用JMX(使用Zabbix Java Gateway代理)监控java应用
1、zabbix-server端安装:
#安装服务包 yum install -y http://repo.zabbix.com/zabbix/3.4/rhel/7/x86_64/zabbix-java-gateway-3.4.1-1.el7.x86_64.rpm yum -y install java-1.8.0 #配置文件 vim /etc/zabbix/zabbix_java_gateway.conf #配置文件,默认不需要修改 #启动服务 systemctl start zabbix-java-gateway.service #查看状态 [root@zabbix ~]# netstat -luntp|grep java tcp6 0 0 :::10052 :::* LISTEN 2352/java #配置zabbix-server文件 vim /etc/zabbix/zabbix_server.conf JavaGateway=10.0.0.200 #JavaGateay地址(zabbix-server地址) JavaGatewayPort=10052 #监控端口 StartJavaPollers=5 #监控JavaGateway的轮询进程 #重启zabbix-service systemctl restart zabbix-server.service
2、因是实验环境,故简单安装java应用,便于监控测试(实验使用)
详细安装过程请移步:http://blog.oldboyedu.com/java-tomcat/
约定: 软件放置目录:/usr/local/src 安装路径:/etc/应用名
2.1、下载jdk(这里选择jdk8)
下载地址:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html
2.2、安装jdk
[root@tomcat src]# pwd /usr/local/src [root@tomcat src]# tar xf jdk-8u171-linux-x64.tar.gz /etc/ [root@tomcat src]# ln -s /etc/jdk1.8.0_171/ /jdk sed -i.ori '$a export JAVA_HOME=/etc/jdk export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar' /etc/profile source /etc/profile [root@tomcat src]# java -version java version "1.8.0_171" Java(TM) SE Runtime Environment (build 1.8.0_171-b11) Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode) [root@tomcat src]#
2.3、安装tomcat
下载地址:https://tomcat.apache.org/download-80.cgi
#安装tomcat应用 cd /usr/local/src/ wget http://mirror.bit.edu.cn/apache/tomcat/tomcat-8/v8.5.28/bin/apache-tomcat-8.5.28.tar.gz tar xf apache-tomcat-8.5.28.tar.gz mv apache-tomcat-8.5.28 /usr/local/ ln -s /usr/local/apache-tomcat-8.5.28/ /usr/local/tomcat #启动服务 [root@localhost src]# /usr/local/tomcat/bin/startup.sh #查看服务状态 [root@localhost src]# netstat -luntp|grep 8080 tcp6 0 0 :::8080 :::* LISTEN 10420/java
#下载安装 catalina-jmx-remote.jar 这个文件放置到Tomcat/lib目录下
[root@tomcat lib]# ll /etc/tomcat/lib/catalina-jmx-remote.jar -rw-r--r-- 1 root root 13607 Jun 5 2018 /etc/tomcat/lib/catalina-jmx-remote.jar
#修改server.xml配置文件
[root@tomcat lib]# vim /etc/tomcat/conf/server.xml 22 <Server port="8005" 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" /> 33 <Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" 34 rmiRegistryPortPlatform="12345" rmiServerPortPlatform="12346" />
注释:33和34行内容是新添加的内容,其他均不用修改
#开启JMX远程监控
vim /etc/tomcat/bin/catalina.sh
添加到Execute The Requested Command 位置下,在最后添加不生效!!!!!!!!!
CATALINA_OPTS="$CATALINA_OPTS -Djava.rmi.server.hostname=122.114.10.146 -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false" #重启进程 /etc/tomcat/bin/shutdown.sh /etc/tomcat/bin/startup.sh #查看端口 [root@tomcat ~]# netstat -luntp tcp6 0 0 :::8080 :::* LISTEN 26311/java tcp6 0 0 :::12345 :::* LISTEN 26311/java tcp6 0 0 :::12346 :::* LISTEN 26311/java tcp6 0 0 :::45628 :::* LISTEN 26311/java tcp6 0 0 :::10050 :::* LISTEN 24935/zabbix_agentd tcp6 0 0 127.0.0.1:8005 :::* LISTEN 26311/java tcp6 0 0 :::8009 :::* LISTEN 26311/java
3、修改防火墙
firewall-cmd --zone=public --add-port=12345/tcp --permanent firewall-cmd --zone=public --add-port=12346/tcp --permanent firewall-cmd --reload
下载测试:
测试法1:
(1)下载cmdline-jmxclient-0.10.3.jar文件,下载地址http://crawler.archive.org/cmdline-jmxclient/downloads.html (2)本地执行如下命令查看tomcat的堆内存信息 java -jar cmdline-jmxclient-0.10.3.jar - 122.114.10.146:12345 java.lang:type=Memory HeapMemoryUsage 06/05/2018 11:27:46 +0800 org.archive.jmx.Client HeapMemoryUsage: committed: 30724096 init: 16777216 max: 253427712 used: 20617872
测试方法2:
3、zabbix-server服务web端配置
配置--》主机---添加主机
注:显示添加完成后,注意看出图情况,我的显示正常出图,再次就不截图了!!!!
自此监控就添加完成,但监控java或tomcat的模板大部分是没有用的,需要我们自己修改,请查 zabbix日常监控项java(四又分之一)