Zabbix monitor nginx
Zabbix client
Configure nginx's yum source
Edit yum warehouse:
vi /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl = http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
Install nginx: yum install -y nginx
Configure nginx status information, add a section of configuration
vi /etc/nginx/conf.d/default.conf
location /nginx_status
{
stub_status on;
access_log off;
allow 127.0.0.1;
deny all;
}
Start nginx service: systemctl start nginx; ps aux | grep nginx
Client test:
[root@localhost ~]# curl http://127.0.0.1/nginx_status
Active connections: 1
server accepts handled requests
1 1 1
Reading: 0 Writing: 1 Waiting: 0
Parameter meaning description:
Active Connections: The number of current active connections, which also includes connections in the waiting state
Accepts: The number of connections received
Handled: The number of connections that have been processed. This number is generally the same as accepts. If it is inconsistent, it means that Nginx has made an error
Requests: The total number of requests processed, a connection can have multiple requests, so the value is larger than accpets
Reading: The number of connections that are reading request header information
Writing: The number of connections that are sending response messages
Waiting: The number of connections that are in an idle state, waiting for the client to send a request
Script on the client machine
vi /usr/local/sbin/ngx_status.sh
#Content is as follows
#!/bin/bash
url="http://127.0.0.1/nginx_status"
curl=/usr/bin/curl
# Detect whether the nginx process exists
function ping {
/sbin/pidof nginx | wc -l
}
# Detect nginx performance
function active {
$curl $url 2>/dev/null| grep 'Active' | awk '{print $NF}'
}
function reading {
$curl $url 2>/dev/null| grep 'Reading' | awk '{print $2}'
}
function writing {
$curl $url 2>/dev/null| grep 'Writing' | awk '{print $4}'
}
function waiting {
$curl $url 2>/dev/null| grep 'Waiting' | awk '{print $6}'
}
function accepts {
$curl $url 2>/dev/null| awk NR==3 | awk '{print $1}'
}
function handled {
$curl $url 2>/dev/null| awk NR==3 | awk '{print $2}'
}
function requests {
$curl $url 2>/dev/null| awk NR==3 | awk '{print $3}'
}
$1
Set permissions for the script:
chmod 755 /usr/local/sbin/ngx_status.sh
Edit the client zabbix_agent.conf configuration, add a line
vi /etc/zabbix/zabbix_agentd.conf
# UserParameter=
UserParameter=nginx.status[*],/usr/local/sbin/ngx_status.sh $1
Restart the service:
systemctl restart zabbix-agent
zabbix_get monitoring script test:
Execute
zabbix_get -s 192.168.19.128 -k'nginx.status[accepts]' on the server zabbix_server
Zabbix_server web UI interface operation:
Configuration---Host---Import---Import file (need to download nginx template)
Download nginx template
yum install -y git
git clone https://github.com/aminglinux/linux2019.git
sz /linux2019/zabbix_nginx_template/zbx_export_templates.xml
Use the sz command to download the template in the directory to the pc. Then use import on zabbixweb UI.
Link the nginx host to be monitored to the template.
Configuration--Host--Click the selected host name---template--link indicator--select--select group--select template---add--update---view monitoring items (more nginx item)
Zabbix monitor tomcat
Monitoring process:
Install zabbix_java_gateway,
configure zabbix_java_gateway configuration file and zabbix_server configuration file, specify the listening port, start the number of processes,
edit the Tomcat configuration file, and enable JMX
The following operations
add host to the zabbix WEB UI interface , and specify the JMX interface
link TOMCAT template
Zabbix-server server:
Install zabbix_java_gateway
yum install -y zabbix-java-gateway
Modify the configuration file
vi /etc/zabbix/zabbix_java_gateway.conf
# LISTEN_IP="0.0.0.0" 改成 LISTEN_IP="0.0.0.0"
# LISTEN_PORT=10052 changed to LISTEN_PORT=10052
# START_POLLERS=5 changed to START_POLLERS=5
vi /etc/zabbix/zabbix_server.conf
defines JavaGateway and JavaGatewayPort and StartJavaPollers
JavaGateway=127.0.0.1 //java gateway address
JavaGatewayPort=10052 //Java gateway default port
StartJavaPollers=5 //The number of start process polls
Start zabbix-java-gateway service:
systemctl start zabbix-java-gateway
restart zabbix-server service:
systemctl restart zabbix-server
Open ** JMX (install tomcat ** first ):
Edit the Tomcat configuration file and enable JMX
vi /usr/local/tomcat/bin/catalina.sh
#!/bin/sh
export CATALINA_OPTS="$CATALINA_OPTS -Dcom.sun.management.jmxremote //Enable remote monitoring jvm
-Djava.rmi.server.hostname=192.168.111.136 //The ip address of the tomcat host
-Dcom.sun.management.jmxremote.port=9999 //jmx starts the remote port, zabbix must be the same when added
-Dcom.sun.management.jmxremote.ssl=false //Ssl encrypted transmission is not enabled
-Dcom.sun.management.jmxremote.authenticate=false" //Do not open username and password authentication
Note: After the above content is added to the configuration file, make a line, do not wrap, it may
The tomcat can't get up due to the error.
Restart the tomcat service:
/usr/local/tomcat/bin/shutdown.sh
/usr/local/tomcat/bin/startup.sh
Link TOMCAT template add Host link template
Configuration - host --- create host --- agent agent interface (remove) --- JMX interface (add) --- the host to be monitored by the IP address --- port (9999)
Template--link indicator---add---group---add--update
Zabbix monitors mysql/mariadb
Authorize a monitoring user
mysql -uroot -padmin123
\> grant usage, process, replication client on . to 'mon'@'localhost' identified by 'x2ay9xodTvyM';
View Edit Create Configuration File
vi /etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf
HOME=/var/lib/zabbix
mkdir /var/lib/zabbix
vim /var/lib/zabbix/.my.cnf
[mysql]
host=localhost
user=mon
password='x2ay9xodTvyM'
socket=/tmp/mysql.sock
[mysqladmin]
host=localhost
user=mon
password='x2ay9xodTvyM'
socket=/tmp/mysql.sock
Restart zabbix-agent service
systemctl restart zabbix-agent
test
zabbix_get -s 127.0.0.1 -p 10050 -k mysql.ping
If prompted: sh: mysqladmin: command not found
需要: ln -s /usr/local/mysql/bin/mysqladmin /usr/bin/
ln -s /usr/local/mysql/bin/mysql /usr/bin/mysql
zabbix_get -s 127.0.0.1 -p 10050 -k mysql.version
zabbix_get -s 127.0.0.1 -p 10050 -k mysql.size