• 部署tomcat

    yum install jdk-8u241-linux-x64.rpm
    #
    vim /etc/profile.d/java.sh
    export JAVA_HOME=/usr/java/latest
    export PATH=$JAVA_HOME/bin:$PATH
    . /etc/profile.d/java.sh
    #
    tar xf apache-tomcat-8.5.53.tar.gz -C /usr/local/
    cd /usr/local/
    ln -sv apache-tomcat-8.5.53 tomcat
    #
    vim /etc/profile.d/tomcat.sh
    export CATALINA_HOME=/usr/local/tomcat
    export PATH=$CATALINA_HOME/bin:$PATH
    . /etc/profile.d/tomcat.sh
    #
    catalina.sh start
    

    安装配置java gateway

    yum install gcc libxml2-devel net-snmp net-snmp-devel curl curl-devel php php-bcmath php-mbstring mariadb-devel java-1.8.0-openjdk-devel -y
    wget https://cdn.zabbix.com/zabbix/sources/stable/4.0/zabbix-4.0.23.tar.gz
    tar -zxf zabbix-4.0.23.tar.gz
    cd zabbix-4.0.23
    ./configure --prefix=/usr/local/zabbix --enable-java --with-net-snmp --with-mysql --with-ssh2
    make && make install
    

    修改配置文件

    vim /usr/local/zabbix/sbin/zabbix_java/settings.sh
    LISTEN_IP="0.0.0.0"
    LISTEN_PORT=10052
    #启动多少个进程轮训java,要和java 应用保持一定关系
    START_POLLERS=5
    TIMEOUT=30
    

    启动java-gateway

/usr/local/zabbix/sbin/zabbix_java/startup.sh ss -tnl LISTEN 0 50 :::10052 :::*
```

 配置tomcat 监控参数
 
 ```
 vim /usr/local/tomcat/bin/catalina.sh
 #在第一个非注释行添加,以下内容写成一行
 CATALINA_OPTS="$CATALINA_OPTS
 #启用远程监控JMX
 -Dcom.sun.management.jmxremote
 #默认启动的JMX端口号,要和zabbix添加主机时候的端口一致即可
 -Dcom.sun.management.jmxremote.port=12345
 #不使用用户名密码

-Dcom.sun.management.jmxremote.authenticate=false #不使用ssl认证 -Dcom.sun.management.jmxremote.ssl=false #tomcat主机自己的IP地址,不要写zabbix服务器的地址 -Djava.rmi.server.hostname=172.24.77.243" ```

 配置JDK 环境
 
 ```
 tar -xvf jdk-8u241-linux-x64.tar.gz
 ln -sv /usr/local/src/jdk1.8.0_241/ /usr/local/jdk
 vim /etc/profile
 export JAVA_HOME=/usr/local/jdk

export TOMCAT_HOME=/usr/local//tomcat export PATH=$JAVA_HOME/bin:$JAVA_HOME/jre/bin:$TOMCAT_HOME/bin:$PATH export CLASSPATH=.$CLASSPATH:$JAVA_HOME/lib:$JAVA_HOME/jre/lib:$JAVA_HOME/lib/tools.jar source /etc/profile java -version ```

 重启tomcat并在windows 验证
     ./catalina.sh stop
./catalina.sh start
     C:\Program Files\Java\jdk1.8.0_191\bin\jconsole.exe
172.24.77.243:12345

Tomcat端安装zabbix agent

编译安装zabbix 客户端

tar -zxf zabbix-4.0.23.tar.gz
cd zabbix-4.0.23
./configure --enable-agent --prefix=/usr/local/zabbix
make && make install
cp misc/init.d/fedora/core/zabbix_agentd /etc/init.d/
vim /etc/init.d/zabbix_agentd
 BASEDIR=/usr/local/zabbix
useradd zabbix -s /sbin/nologin

修改zabbix-agentd配置文件

vim /usr/local/zabbix/etc/zabbix_agentd.conf
LogFile=/tmp/zabbix_agentd.log
     DebugLevel=4
#zabbix服务器地址
Server=172.24.77.227
 Hostname=172.24.77.243

重启zabbix agentd服务

/usr/local/zabbix/sbin/zabbix_agentd -c /usr/local/zabbix/etc/zabbix_agentd.conf
/etc/init.d/zabbix_agentd restart

配置zabbix server调用java gateway

vim /usr/local/zabbix/etc/zabbix_server.conf
#安装有tomcat的服务器地址
JavaGateway=172.24.77.243
JavaGatewayPort=10052
#启动多少个进程去轮训 java gateway,要和java gateway的配置一致
StartJavaPollers=5

在zabbix 添加主机并关联模板

配置--主机--创建主机

导入自定义模块并关联tomcat

监控Java排错方法

测试能否获取到java 当前已经分配的 线程数

java -jar cmdline-jmxclient-0.10.3.jar - 172.18.200.104:12345 'Catalina:name="http-bio-8080",type=ThreadPool' currentThreadCount
java -jar cmdline-jmxclient-0.10.3.jar - 172.18.200.104:12345 'Catalina:name="http-bio-8080",type=ThreadPool' maxThreads