Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Zabbix monitors Tomcat and Nginx

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Note: this blog post is based on the environment in which the zabbix monitoring server is deployed. Here we will open a client server (the monitored side) for testing.

Blog outline:

1. Monitoring Tomcat

2. Monitor Nginx server

1. Monitoring Tomcat

Monitoring Tomcat requires the use of zabbix_java_gateway (a feature introduced in zabbix2.0), as the name implies: Java gateway, similar to agentd, but only for Java. It should be noted that it can only obtain data actively, not passively. Its data will eventually be submitted to the server or proxy.

If you need to enable the monitoring Tomcat function, you need to add the-- enable_java parameter when compiling the zabbix server side.

1. Zabbix Server installs the zabbix_java_gateway program

The zabbix_java_gateway program can be installed on either the zabbix server side or the monitored side, but it is usually installed on the Zabbix server side, and here I install it on the Zabbix Server side.

Note: all the source packages used in this article can be downloaded from my network disk link.

# before executing the following command Please download the corresponding rpm package [root@zabbix ~] # rpm-ivh zabbix-java-gateway-3.2.1-1.el7.x86_64.rpm# in the link to my network disk and modify the java_gateway configuration file [root@zabbix ~] # cd / etc/zabbix/ [root@zabbix zabbix] # sed-I's LISTEN_IP= # LISTEN_IP= "0.0.0.0" / LISTEN_IP= "0.0.0.0" / g 'zabbix_java_gateway.conf [root @ zabbix zabbix] # sed-I's java-gateway # LISTEN_PORT=10052/LISTEN_PORT=10052/g' zabbix_java_gateway.conf [root@zabbix zabbix] # egrep-v'^ $| ^ # 'zabbix_java_gateway.conf # determine the modified profile LISTEN_IP= "0.0.0.0" LISTEN_PORT=10052PID_FILE= "/ var/run/zabbix/zabbix_java.pid" TIMEOUT=3# launch java-gateway [root@zabbix zabbix] # systemctl start zabbix-java-gateway.service # determine the port Listening to [root@zabbix zabbix] # netstat-anpt | grep 10052tcp6 00:: 10052: * LISTEN 3112/java # modify the configuration file of Zabbix-Server [root@zabbix zabbix] # cd / usr/local/zabbix/etc/ [root@zabbix etc] # sed-I's sed # JavaGateway=/JavaGateway=192.168.20.2/g' zabbix_server.conf [ Root@zabbix etc] # sed-I's zabbix etc # JavaGatewayPort=10052/JavaGatewayPort=10052/g' zabbix_ server.confession [root @ zabbix etc] # StartJavaPollers=0/StartJavaPollers=5/g' zabbix_ server.confession # / etc/init.d/zabbix_server restart # restart zabbix server2, Tomcat is configured on the test side

Start a server with an IP of 192.168.20.3 as a Tomcat server for testing.

# install Tomcat [root @ tomcat ~] # rpm-qa | grep jdk # query the default JAVA package java-1.8.0-openjdk-1.8.0.102-4.b14.el7.x86_64java-1.8.0-openjdk-headless-1.8.0.102-4.b14.el7.x86_64java-1.7.0-openjdk-1.7.0.111-2.6.7.8.el7.x86copyright copyright Jdklics- 1.2-1.el7.noarchjava-1.7.0-openjdk-headless-1.7.0.111-2.6.7.8.el7.x86_64 [root@tomcat ~] # rpm-e java-1.8.0-openjdk-headless-- nodeps # Uninstall Java1.8 [root@tomcat ~] # rpm-e java-1.7.0-openjdk-headless--nodeps # Uninstall Java1.7 [root@tomcat ~] # cd / usr/ Src [root@tomcat src] # rz # upload the two source code packages provided by me [root@tomcat src] # ls # source code package as follows: apache-tomcat-8.5.35.tar.gz jdk-8u211-linux-x64.tar.gz [root@tomcat ~] # tar zxf jdk-8u211-linux-x64.tar.gz-C / usr/local/ # decompress JDK to the specified path [root@tomcat src] # tar zxf apache-tomcat-8.5 .35.tar.gz # extract the Tomcat source package [root@tomcat src] # mv apache-tomcat-8.5.35 / usr/local/tomcat # move the extracted directory to the specified directory and name it tomcat [root@tomcat ~] # vim / etc/profile # Edit environment variables Add the following content export JAVA_HOME=/usr/local/jdk1.8.0_211export JRE_HOME=/usr/local/jdk1.8.0_211/jreexport CLASSPATH=$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jarexport PATH=$JAVA_HOME/bin:$JRE_HOME/bin:$PATH [root@tomcat ~] # at the end of the configuration file. / etc/profile # reload environment variable [root@tomcat ~] # java-version # View java version java version "1.8.0mm 211" Java (TM) SE Runtime Environment (build 1.8.0_211-b12) Java HotSpot (TM) 64-Bit Server VM (build 25.211-b12, mixed mode) # enable Tomcat's JMX remote management function [root@tomcat src] # vim / usr/local/tomcat/bin/catalina.shexport JDK_JAVA_OPTIONS # jump to line 306 CATALINA_OPTS= "$CATALINA_OPTS-Dcom.sun.management.jmxremote-Dcom.sun.management.jmxremote.port=8888-Dcom.sun.management.jmxremote.ssl=false-Djava.rmi.server.hostname=192.168.20.3-Dcom.sun.management.jmxremote.authenticate=false" # Note: the above IP is the native IP of Tomcat, and port "8888" can be customized. Without conflict, [root@tomcat src] # / usr/local/tomcat/bin/startup.sh # start Tomcat# to make sure that the relevant port is listening [root@tomcat src] # netstat-anpt | grep 8080tcp6 0: 8080: * LISTEN 3871/java [root@tomcat src] # netstat-anpt | grep 8888tcp6 00:: : 8888:: * LISTEN 3871/java 3, Go back to Zabbix-server to test the JMX connection

Note: this test requires the system to support graphical desktops. If there is no graphical desktop, this verification process can be omitted.

[root@zabbix ~] # jconsole # executes this command, which is provided by Java-gateway.

After executing the above command, the following prompt box pops up (enter the IP+JMX listening port of Tomcat to connect):

Just make sure you can see the following picture:

4. Log in to the web interface of Zabbix Server to configure

Wait a moment, and the display is as follows:

You can see information about the JVM virtual machine by doing the following:

2. Monitor Nginx server

Install and deploy Nginx yourself, and here I also configure Nginx on the host Tomcat. For deployment of Nginx, please refer to the blog post: building Nginx Server and Deep Optimization

1 、 Deploy agent client on Nginx server # install zabbix-agent [root@tomcat src] # tar zxf zabbix-3.2.1.tar.gz [root@tomcat src] # cd zabbix-3.2.1/ [root@tomcat zabbix-3.2.1] #. / configure-- prefix=/usr/local/zabbix-- enable-agent & & make & & make install [root@tomcat zabbix-3.2.1] # cp misc/init.d/fedora/core/zabbix_agentd / Etc/init.d/ [root@tomcat zabbix-3.2.1] # chmod + x / etc/init.d/zabbix_agentd # modify the startup script [root@tomcat zabbix-3.2.1] # sed-I'UniBASEDIR =\ / usr\ / local/BASEDIR=\ / usr\ / local\ / zabbix/g' / etc/init.d/zabbix_agentd [root@tomcat zabbix-3.2.1] # sed-I's UniPIDFILE =\ / tmp\ / $BINARY_NAME.pid/ PIDFILE=$BASEDIR\ / logs\ / $BINARY_NAME.pid/g' / etc/init.d/zabbix_ agentd [root @ tomcat zabbix-3.2.1] # useradd-M-s / sbin/nologin zabbix [root@tomcat ~] # mkdir-p / usr/local/zabbix/logs/ [root@tomcat ~] # chown-R zabbix:zabbix / usr/local/zabbix [root@tomcat zabbix-3.2.1] # chkconfig-add zabbix_ agentd [root @ tomcat zabbix-3.2.1] # chkconfig Zabbix_agentd on [root@tomcat zabbix-3.2.1] # systemctl start zabbix_ agentd [root @ tomcat zabbix-3.2.1] # netstat-anpt | grep zabbixtcp 00 0.0.0.0systemctl start zabbix_ 10050 0.0.0.0systemctl start zabbix_ * LISTEN 97364/zabbix_agentd # modify the agent configuration file [root@tomcat zabbix-3.2.1] # cd / usr/local/zabbix/etc/ [root@ Tomcat etc] # sed-I's tomcat etc # PidFile=\ / tmp\ / zabbix_agentd.pid/PidFile=\ / usr\ / local\ / zabbix\ / logs\ / zabbix_agentd.pid/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I's Universe LogFile =\ / tmp\ / zabbix_agentd.log/LogFile=\ / usr\ / zabbix\ / logs\ / zabbix_agentd.log/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I 's/Server=127.0 .0.1 / Server=192.168.20.2/g' zabbix_ agentd.confession [root @ tomcat etc] # ListenPort=10050/ListenPort=10050/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I bank # ListenIP=0.0.0.0/ListenIP=0.0.0.0/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I ListenIP=0.0.0.0/ListenIP=0.0.0.0/g' zabbix_ agentd.confession 127.0.0.1 @ tomcat etc] # sed-I 's/Hostname=Zabbix server/Hostname=192.168.20.3/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I's pick # Timeout=3/Timeout=15/g' zabbix_ agentd.confession [root @ tomcat etc] # sed-I's tag # Include=\ / usr\ / etc\ / zabbix_agentd.conf.d\ / Include=\ / usr\ / local\ / zabbix\ / etc\ / zabbix_agentd.conf.d\ / / g 'zabbix_agentd .conf [root@tomcat etc] # sed-I's Union # UnsafeUserParameters=0/UnsafeUserParameters=1/g' zabbix_ agentd.confession [root @ tomcat etc] # echo 'UserParameter=nginx.info [*] / usr/local/zabbix/scripts/nginx.sh $1'> > zabbix_ agentd.confs [root @ tomcat etc] # echo "UserParameter=nginx.ping [*] Netstat-anput | grep-w 80 | grep-w LISTEN | wc-l "> > zabbix_ agentd.confession [root @ tomcat etc] # egrep-v'^ $| ^ # 'zabbix_agentd.conf # make sure the configuration is correct PidFile=/usr/local/zabbix/logs/zabbix_agentd.pidLogFile=/usr/local/zabbix/logs/zabbix_agentd.logServer=192.168.20.2ListenPort=10050ListenIP=0.0.0.0ServerActive=192.168.20.2Hostname=192.168.20.3Timeout=15Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d / Include=/usr/local/zabbix/etc/zabbix_agentd.conf.d/*.confUnsafeUserParameters=1UserParameter=nginx.info [*] / usr/local/zabbix/scripts/nginx.sh $1UserParameter=nginx.ping [*], netstat-anput | grep-w 80 | grep-w LISTEN | wc-L2, write Nginx script on Nginx server

Note: this script is available in the download link at the beginning of my article.

[root@tomcat etc] # mkdir / usr/local/zabbix/scripts/ [root@tomcat etc] # cd / usr/local/zabbix/scripts/ [root@tomcat scripts] # cat nginx.sh # script is as follows: all IP are Nginx's IP packages / binbinbins $1 inindex) RS= `curl-s-I 192.168.20.3/index.html | head-N1 | awk'{print $2} '`echo $RS;; WorkerProcesses) RS= `ps aux | grep nginx | grep-w worker | wc-l`echo $RS Bps) RS= `ab-Q-n 1000-c 1000 http://192.168.20.3/index.html | grep Request | awk'{print $4} '`echo $RS;; Current) LINES= `cat / usr/local/nginx/logs/access.log | wc-l`cat 1 NOW_LINES= `cat / usr/local/nginx/logs/access.log | wc-l`echo $NOW_LINES $LINES | awk' {print $1-$2}' IP) RS= `cat / usr/local/nginx/logs/access.log | awk'{print $1}'| sort-u | wc-l`cat $RS;; VirtualHost) RS= `cat / usr/local/nginx/conf/nginx.conf | grep-v'#'| grep server_name | wc-l`cat $RS;; MD5) RS= `md5sum / usr/local/nginx/conf/nginx.conf | awk'{print $1} '`echo $RS PV) RS= `wc-l / usr/local/nginx/logs/access.log | awk'{print $1} '`echo $RS;; esac [root@tomcat scripts] # / etc/init.d/zabbix_agentd restart # restart agent# to adjust the corresponding permissions. All users need to execute the netstat command [root@tomcat scripts] # chmod + s / usr/bin/netstat [root@tomcat scripts] # chmod + x nginx.sh3, configure Zabbix-Server Web interface

1. Before configuring the web, you can now test whether the relevant information is available on the Zabbix-Server side in order to verify the correctness of the script (at the same time, ab stress testing is required, and this command should be installed on both the server side and the Agent side).

[root@zabbix fonts] # yum-y install httpd-tools # install ab stress test command [root@zabbix fonts] # ab-Q-n 1000-c 1000 http://192.168.20.3/index.html | grep Request | awk'{print $4} '2117.31 # normal if a message is returned

Configure the Web interface:

1) configure the application set

2) configure monitoring items

Monitor the total number of Nginx visits:

Next, each time you add a monitoring item, you have to click the button below. For simplicity, you will not cut the picture of the page below.

Independent IP number

Status of the Nginx home page

Current concurrency of Nginx

The profile MD5 value is used to monitor whether the nginx profile has been changed (note the type of information in the diagram)

Current throughput bps with an update time of 60 seconds (note its information type)

Monitor the number of nginx worker processes

Monitor the number of Nignx virtual hosts

3) create a trigger

Nginx service unexpected stop working trigger

Create a trigger that is not accessible to the Nginx home page

Create Nginx profile modified trigger

4) add monitored hosts

5) View the data monitored by Zabbix

6) add mapping to monitoring nginx status (more friendly)

Confirm that the following has been added:

Associate to a monitoring item

Simulate concurrency on the server side, and then view the graphic detection page:

[root@zabbix ~] # vim a.sh # script #! / bin/bashwhile truedoab-n 1000-c 100 192.168.20.3/index.html & > / dev/nulldone [root@zabbix ~] # sh a.sh # execute script

After executing the script, the graphical interface is as follows:

You can also customize the chart as follows:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report