CentOS 7.7 yum installation and configuration Zabbix 4.0 LTS details (6)
8. Monitor Nginx, httpd, Tomcat, php-fpm, Redis, MySQL and web page access and response speed:
1. Monitor Nginx:
(1) install Nginx on node-122 node
(2) Open the Nginx status page:
# cd / etc/nginx
# cp nginx.conf {, .bak}
# vim nginx.conf, add the following code to the server configuration section:
Location = / nginx_status {
Stub_status
}
# nginx-t
# systemctl start nginx
# systemctl status nginx
(3) browser access status page: http://192.168.0.122/nginx_status
Description: page status information
Active connections: number of client connections currently active, including Waiting connections
Accepts: total number of client connections received
Handled: the total number of connections handled, which is usually the same as the value of accepts, unless certain resource limits, such as worker_connections, are reached
Requests: total number of client requests
Reading:Nginx is reading the current number of connections in the request header
The current number of connections that Writing:Nginx is writing the response back to the client
Waiting: the number of idle client connections currently waiting for requests
(4) upload the nginx_monitor.sh script file to the / scripts directory and grant execution permission: # chmod + x / scripts/nginx_monitor.sh
(5) upload the nginx_status.conf configuration file to the / etc/zabbix/zabbix_agentd.d directory and restart Zabbix Agent:
# systemctl restart zabbix-agent
(6) zabbix-server nodes use zabbix-get for value testing:
# zabbix_get-s 192.168.0.122-k nginx_ status [active]
# zabbix_get-s 192.168.0.122-k nginx_ status [gifts]
# zabbix_get-s 192.168.0.122-k nginx_ status [examples]
If the above error occurs, the node-122 node can delete the / tmp/nginx_status.txt file.
(7) Zabbix Web imports Nginx monitoring template zbx_nginx_templates.xml:
Configuration-- > Templates-- > Import-- > Import
The default Nginx port defined in the template is 80:
(8) node-122 node links Nginx monitoring template:
Check all Nginx monitoring items and click "Check now":
(9) View the latest monitoring data:
2. Monitor httpd:
(1) install httpd on node-122 node
(2) https://github.com/lorf/zapache downloads the script files, configuration files and template files needed to monitor httpd
(3) upload the httpd-server-status.conf configuration file to the / etc/httpd/conf.d directory and open the httpd status page
Description: httpd-server-status.conf already contains the following configuration
# httpd-t
# systemctl start httpd
# systemctl status httpd
(4) the browser accesses the status page:
Http://192.168.0.122/server-status or http://192.168.0.122/server-status?auto&refresh=3
(5) upload the zapache script file to the / scripts directory and grant execution permission: # chmod + x / scripts/zapache
(6) upload the userparameter_zapache.conf configuration file to the / etc/zabbix/zabbix_agentd.d directory and restart Zabbix Agent:
# systemctl restart zabbix-agent
(7) zabbix-server nodes use zabbix-get for value testing:
# zabbix_get-s 192.168.0.122-k zapache [Uptime]
# zabbix_get-s 192.168.0.122-k zapache [ping]
(8) Zabbix Web imports httpd monitoring template zapache-template-active.xml:
(9) node-122 node links httpd monitoring template:
Check all httpd monitoring items and click "Check now":
(10) View the latest monitoring data:
3. Monitor Tomcat through JMX:
(1) install JDK and Tomcat on node-122 node
(2) configure Tomcat to support JMX:
# vim / usr/local/tomcat/bin/catalina.sh, add the following code under the first line #! / bin/sh:
CATALINA_OPTS= "$CATALINA_OPTS
-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=192.168.0.122
-Dcom.sun.management.jmxremote.port=12345
-Dcom.sun.management.jmxremote.ssl=false
-Dcom.sun.management.jmxremote.authenticate=false "
Description:
-Dcom.sun.management.jmxremote: enable remote monitoring JVM
-IP address of Djava.rmi.server.hostname=192.168.0.122:Tomcat, not IP address of Zabbix Server
-Dcom.sun.management.jmxremote.port=12345: the JMX port number started by default
-Dcom.sun.management.jmxremote.ssl=false: do not use SSL authentication
-Dcom.sun.management.jmxremote.authenticate=false: do not use username and password authentication
The difference between CATALINA_OPTS and JAVA_OPTS:
CATALINA_OPTS: used only by Tomcat
JAVA_OPTS: used by all Java applications
# / usr/local/tomcat/bin/catalina.sh configtest
# / usr/local/tomcat/bin/startup.sh
# ss-tunlp | grep-w: 12345
(3) install Zabbix Java Gateway:# yum-y install zabbix-java-gateway on node-122 node
(4) node-122 node modifies zabbix_java_gateway.conf configuration file:
# cd / etc/zabbix
# cp zabbix_java_gateway.conf {, .bak}
# vim zabbix_java_gateway.conf
Before modification
After modification
# LISTEN_IP= "0.0.0.0"
LISTEN_IP= "192.168.0.122"
# LISTEN_PORT=10052
LISTEN_PORT=10052
# START_POLLERS=5
START_POLLERS=5
# TIMEOUT=3
TIMEOUT=10
(5) node-122 node starts Zabbix Java Gateway:
# systemctl start zabbix-java-gateway
# systemctl status zabbix-java-gateway
# ss-tunlp | grep-w: 10052
# systemctl enable zabbix-java-gateway
(6) zabbix-server node modifies zabbix_server.conf configuration file:
# vim / etc/zabbix/zabbix_server.conf
Before modification
After modification
# JavaGateway=
JavaGateway=192.168.0.122
# JavaGatewayPort=10052
JavaGatewayPort=10052
# StartJavaPollers=0
StartJavaPollers=5
# systemctl restart zabbix-server
Note: the value of StartJavaPollers should be less than or equal to the value of START_POLLERS
(7) Zabbix Web adds the JMX monitoring API of the node-122 node:
Description: IP is the IP of the server deployed by Zabbix Java Gateway, and the port is the JMX remote port configured in Tomcat
(8) node-122 node links Tomcat monitoring template:
(9) View the latest monitoring data:
4. Monitor php-fpm:
(1) install php-fpm on node-122 node
(2) modify the www.conf configuration file:
# cd / etc/php-fpm.d
# cp www.conf {, .bak}
# vim www.conf
Before modification
After modification
User = apache
User = nginx
Group = apache
Group = nginx
; pm.status_path = / status
Pm.status_path = / php-fpm_status
(3) Open the php-fpm status page:
# vim / etc/nginx/nginx.conf, add the following code to the server configuration section:
Location / {
Root html
Index index.php index.html index.htm
}
Location = / php-fpm_status {
Fastcgi_pass 127.0.0.1:9000
Fastcgi_index index.php
Fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name
Include fastcgi_params
}
# nginx-t
# systemctl restart nginx php-fpm
# ss-tunlp | grep-w: 80
# ss-tunlp | grep-w 9000
(4) browser access status page: http://192.168.0.122/php-fpm_status
(5) upload the php-fpm_monitor.sh script file to the / scripts directory and grant execution permission:
# chmod + x / scripts/php-fpm_monitor.sh
(6) upload the php-fpm_status.conf configuration file to the / etc/zabbix/zabbix_agentd.d directory and restart Zabbix Agent:
# systemctl restart zabbix-agent
(7) zabbix-server nodes use zabbix-get for value testing:
# zabbix_get-s 192.168.0.122-k php-fpm_status ["active processes", http://192.168.0.122/php-fpm_status]
# zabbix_get-s 192.168.0.122-k php-fpm_status ["total processes", http://192.168.0.122/php-fpm_status]
# zabbix_get-s 192.168.0.122-k php-fpm_status ["max active processes", http://192.168.0.122/php-fpm_status]
(8) Zabbix Web imports php-fpm monitoring template zbx_php-fpm_templates.xml:
(9) node-122 node links php-fpm monitoring template:
Check all php-fpm monitoring items and click "Check now":
(10) View the latest monitoring data:
5. Monitor Redis:
(1) install Redis on node-122 node
(2) View Redis status information:
# redis-cli info
(3) upload the redis_monitor.sh script file to the / scripts directory and grant execution permission: # chmod + x / scripts/redis_monitor.sh
(4) upload the redis_status.conf configuration file to the / etc/zabbix/zabbix_agentd.d directory and restart Zabbix Agent:
# systemctl restart zabbix-agent
(5) zabbix-server nodes use zabbix-get for value testing:
# zabbix_get-s 192.168.0.122-k redis [127.0.0.1 rejective connectionsnone]
(6) Zabbix Web imports Redis monitoring template zbx_redis_templates.xml:
(7) node-122 node links Redis monitoring template:
Check all Redis monitoring items and click "Check now":
(8) View the latest monitoring data:
6. Use the Percona plug-in to monitor MySQL:
(1) install php, php-mysql and MySQL on node-122 node
Note: since the monitoring plug-in of Percona is written by php, php and php-mysql need to be installed on the monitored side.
(2) download and install plug-ins on node-122 node: https://www.percona.com/downloads/percona-monitoring-plugins/LATEST/
# rpm-ivh https://www.percona.com/downloads/percona-monitoring-plugins/percona-monitoring-plugins-1.1.8/binary/redhat/7/x86_64/percona-zabbix-templates-1.1.8-1.noarch.rpm
# rpm-ql percona-zabbix-templates
Note:
Script file: / var/lib/zabbix/percona/scripts/get_mysql_stats_wrapper.sh
Php file: / var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
Configuration file: / var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf
Template file: / var/lib/zabbix/percona/templates/zabbix_agent_template_percona_mysql_server_ht_2.0.9-sver1.1.8.xml. The Zabbix version of the built-in template match is 2.0, which cannot be used in version 4.0. The zbx_percona_mysql_templates.xml can be downloaded separately from the Internet.
(3) copy the userparameter_percona_mysql.conf configuration file to the / etc/zabbix/zabbix_agentd.d directory:
# cp / var/lib/zabbix/percona/templates/userparameter_percona_mysql.conf / etc/zabbix/zabbix_agentd.d/
(4) restart Zabbix Agent:# systemctl restart zabbix-agent
(5) modify the database connection information in ss_get_mysql_stats.php file:
# vim / var/lib/zabbix/percona/scripts/ss_get_mysql_stats.php
$mysql_user = 'root'
$mysql_pass = '123456'
(6) zabbix-server nodes use zabbix-get for value testing:
# zabbix_get-s 192.168.0.122-k MySQL.Open-files
# zabbix_get-s 192.168.0.122-k MySQL.Com-select
# zabbix_get-s 192.168.0.122-k MySQL.slave-running
(7) Zabbix Web imports Percona MySQL monitoring template zbx_percona_mysql_templates.xml:
Remarks: a total of 191 monitoring items
(8) node-122 node links Percona MySQL monitoring template:
Check all Percona MySQL monitoring items and click "Check now":
One of the monitoring items related to master-slave replication, prompts:
Solution, modify the MySQL configuration file on the node-122 node:
# vim / etc/my.cnf, with the following code added at the end:
[client]
User=root
Password=123456
Node-122 node restarts MySQL:# systemctl restart mysqld
The zabbix-server node reloads the Zabbix Server configuration cache (similar to restarting Zabbix Server):
# zabbix_server-R config_cache_reload
(9) View the latest monitoring data:
Note: Zabbix also comes with a template named "Template DB MySQL" for monitoring MySQL, which can also be used as described above.
7. Monitor the access speed and response speed of the web page:
(1) node-122 nodes build LNMP environment and deploy WordPress
(2) Zabbix Web creates a node-122 node Web scene:
Configuration-- > Hosts-- > Web-- > Create web scenario-- > Add
Description: source of User agent string
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36
Remarks: source of Required string
Remarks: source of Raw post
WordPress default login page: http://192.168.0.122/wordpress/wp-login.php
Press Chrome browser F12, enter an incorrect password, and click Login:
Log=root&pwd=root@123&wp-submit=%E7%99%BB%E5%BD%95&redirect_to=http%3A%2F%2F192.168.0.122%2Fwordpress%2Fwp-admin%2F&testcookie=1
Replace the wrong password with the correct password
(3) View the latest monitoring data:
Monitoring-- > Web-- > WordPress
(4) create a trigger:
Web is a special monitoring item. Add triggers directly.
Configuration-- > Hosts-- > Triggers-- > Create trigger-- > Add
(5) the zabbix-server node uses the ab command to simulate access to WordPress on the node-122 node:
# yum provides ab
# yum-y install httpd-tools
# ab-n 10000-c 20 http://192.168.0.122/wordpress/wp-login.php
Common options:
-c: the number of requests executed concurrently. Default is one request at a time.
-n: total number of requests executed