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

How to realize the Monitoring of Mysql, Apache and Nginx by Zabbix

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

Share

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

The following mainly brings you how Zabbix realizes the monitoring of Mysql, Apache and Nginx. I hope these contents can bring you practical use. This is also the main purpose of this article that I edit Zabbix how to achieve the monitoring of Mysql, Apache and Nginx. All right, don't talk too much nonsense, let's just read the following.

1) install mysql on zabbix agent side

As mysql installation is too time-consuming, I provide one-click installation mysql script, as follows:

[root@agent] # ls mysql*mysql-5.7.22-linux-glibc2.12-x86_64.tar.gz mysql.sh [root@agent ~] # sh mysql.sh Starting MySQL. SUCCESS! Mysql: [Warning] Using a password on the command line interface can be insecure.// this message indicates that the installation is successful! The root password for [root@agent ~] # mysql-u root-p123 / / script is 123mysql > grant all on *. * to zabbix@'192.168.1.%' identified by 'zabbix' / / create test user 2) write a custom monitoring mysql script [root@agent ~] # mkdir / etc/zabbix/shell [root@agent ~] # vim / etc/zabbix/shell/check_mysql.sh #! / bin/bashMYSQL_HOST='192.168.1.8' # specify the IP address of the mysql host MYSQL_PORT='3306' # specify the listening address of the mysql host MYSQL_CONN= "/ usr/local/bin / mysqladmin-h$ {MYSQL_HOST}-P$ {MYSQL_PORT} "# specifies the tool if to use for the connection [$#-ne" 1] Then echo "arg error!" fi# get data case $1 in Uptime) result= `${MYSQL_CONN} status | cut-f2-d ":" | cut-F1-d "T" `echo $result;; Com_update) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_update" | cut-d "|"-f3` echo $result Slow_queries) result= `$ {MYSQL_CONN} status | cut-f5-d ":" | cut-F1-d "O" `echo $result;; Com_select) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_select" | cut-d "|"-f3` echo $result " Com_rollback) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_rollback" | cut-d "|"-f3` echo $result;; Questions) result= `$ {MYSQL_CONN} status | cut-f4-d ":" | cut-F1-d "S" `echo $result Com_insert) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_insert" | cut-d "|"-f3` echo $result;; Com_delete) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_delete" | cut-d "|"-f3` echo $result " Com_commit) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_commit" | cut-d "|"-f3` echo $result;; Bytes_sent) result= `$ {MYSQL_CONN} extended-status | grep-w "Bytes_sent" | cut-d "|"-f3` echo $result " Bytes_received) result= `$ {MYSQL_CONN} extended-status | grep-w "Bytes_received" | cut-d "|"-f3` echo $result;; Com_begin) result= `$ {MYSQL_CONN} extended-status | grep-w "Com_begin" | cut-d "|"-f3` echo $result " *) echo "Usage:$0 (Uptime | Com_update | Slow_queries | Com_select | Com_rollback | Questions | Com_insert | Com_delete | Com_commit | Bytes_sent | Bytes_received | Com_begin)" Esac is not safe because it is not safe to write user name and password information into scripts. So put the user name, Write password information to / etc/my.cnf file [root@agent ~] # vim / etc/my.cnf [mysqladmin] user=zabbixpassword=zabbix [root@agent ~] # chmod + x / etc/zabbix/shell/check_mysql.sh [root@agent ~] # chown zabbix.zabbix / etc/zabbix/shell/check_mysql.sh [root@agent ~] # sh / etc/zabbix/shell/check_mysql.sh Uptime5260//agent side test script can be used 3) modify configuration on zabbix agent side [ Root@agent ~] # vim / etc/zabbix/zabbix_agentd.d/userparameter_mysql.conf// annotates all the original UserParameter Add the following content UserParameter=mysql.status [*], / etc/zabbix/shell/check_mysql.sh $1UserParameterial mysql.pingMagne homemade etc / usr/local/bin/mysqladmin ping | grep-c aliveUserParameter=mysql.version,/usr/local/bin/mysql-V [root@agent ~] # systemctl restart zabbix-agent [uptime] # zabbix_get-s 192.168.1.8-p 10050-k "mysql.status [Uptime]" 5372//zabbix server side test whether the data can be obtained 4) zabbix web interface introduction template

Zabbix comes with a template for mysql monitoring, so just link the template to the corresponding host! As follows:

What you need to focus on here is the configuration of the "key value" column corresponding to the name of each monitoring item. The key value here must be consistent with the monitoring key value customized by the agent side. In addition, you can see that the monitor item "mysql status" has a trigger to check the running status of the mysql. Finally, note that the monitoring type of these monitoring items is "zabbix client", and all monitoring items are stored in the "MYSQL" application set.

The above settings are complete, and the host for monitoring mysql has been added!

5) View monitoring status data

As shown in the figure:

You can see from the picture that the data has been obtained!

Configuration mysql monitoring completed!

II. Practical practice of zabbix monitoring apache application

The monitoring of apache by zabbix is a little more complicated, but the basic process is still two steps: the first is to write a monitoring script to monitor apache; the second is to create an apache monitoring template. The following operations are implemented on the zabbix agent side, and the specific steps are as follows:

1) zabbix agent opens the apache status page

To monitor the running status of apache, you need to open an apache status page in the configuration of apache, and then write a script to obtain the data of this status page to achieve the purpose of monitoring apache!

[root@agent ~] # yum-y install httpd [root@agent ~] # vim / etc/httpd/conf/httpd.conf / / add the following at the end: EnableSendfile onSetHandler server-statusRequire ip 127.0.0.1 192.168.1.10 [root@agent ~] # systemctl start httpd

The configuration item is explained as follows:

1) EnableSendfile on: enables the extended status information, but it will reduce the running efficiency of the CVM.

2) / server-status: it means that it can be accessed through "http://ip/server-status"", and it can also be accessed dynamically through "http://ip/server-status?refresh=N"". N means it is automatically refreshed every N seconds.

3) Require ip 127.0.0.1 192.168.1.10: this is a new special effect added to apache 2.4. That is, the IP address that needs to be accessed

The common uses of Require are as follows:

1) Require all granted: allow all hosts to access

2) Require all denied: deny access to all hosts

3) Require ip IP address: allow an IP to access

4) Require not ip IP address: disable access to a certain IP

5) Require host hostname: allow a host to access

6) Require not host hostname: access to a host is prohibited

Restart the apache service after the modification takes effect!

2) zabbix agent acquires the status detection script and zabbix template of apache

After the configuration of the apache status page is complete, you need to write a script to obtain the status data. There are many script codes, which you can download in the following ways!

[root@agent ~] # wget https://www.ixdba.net/zabbix/zabbix-apache.zip[root@agent ~] # unzip zabbix-apache.zip [root@agent ~] # ll zapache*-rw-r--r-- 1 root root 5792 January 31 23:00 zapache-rw-r--r-- 1 root root 52024 April 22 2016 zapache-template.xml//zapache: the script required to monitor apache; / / zapache-template.xml: the template required to monitor apache [root@agent ~] # mv zapache / etc/zabbix/shell/ [root@agent ~] # chmod 755 / etc/zabbix/shell/zapache [root@agent ~] # chown zabbix.zabbix / etc/zabbix/shell/zapache [root@agent ~] # vim / etc/zabbix/zabbix_agentd.d/userparameter_zapache.conf// write apache template file Monitoring script UserParameter=zapache for calling apache [*], / etc/zabbix/shell/zapache $1 [root@agent ~] # systemctl restart zabbix-agent [root@zabbix ~] # zabbix_get-s 192.168.1.8-p 10050-k "Zapache [BusyWorkers]" 1//zabbix server test whether data can be obtained 3) zabbix web page import template

As shown in the figure:

4) View apache status data

As shown in the figure:

You can see from the picture that the data has been obtained!

Configuration apache monitoring completed!

III. Practice of zabbix monitoring Nginx applications

Zabbix monitors Nginx in exactly the same way as apache. The basic process consists of two steps: the first is to write a script for Nginx; the second is to create a Nginx monitoring template. The following operations are implemented on the zabbix agent side, and the specific steps are as follows:

1) zabbix agent opens the Nginx status page [root@agent ~] # yum-y install pcre-devel zlib-devel openssl-devel [root@agent ~] # wget http://nginx.org/download/nginx-1.14.2.tar.gz[root@agent ~] # tar zxf nginx-1.14.2.tar.gz-C / usr/src [root@agent ~] # cd / usr/src/nginx-1.14.2/ [root@agent nginx-1.14.2] # . / configure-- with-http_stub_status_module & & make & & make install [root@agent ~] # ln-s / usr/local/nginx/sbin/nginx / usr/local/sbin/ [root@agent ~] # vim / usr/local/nginx/conf/nginx.conf// add loaction rule location / nginx-status {stub_status on / / enable the status monitoring module access_log off; / / close the access log allow 127.0.0.1; allow 192.168.1.10; / / allow access to the IP address deny all / / reject all IP addresses} [root@agent ~] # nginx- t [root@agent ~] # nginx [root@agent ~] # curl 127.0.0.1/nginx-statusActive connections: 1 server accepts handled requests 1 1 1 Reading: 0 Writing: 1 Waiting: 0

The output information describes:

1) Active connections: the number of active links initiated to the backend

2) how many connections have been handled by accepts:nginx

3) handled:nginx successfully created several handshakes

4) how many requests have been processed by requests:nginx

5) number of header of Reading:nginx read client

6) the number of header returned by Writing:nginx to the client

7) Waiting:nginx request processing completed, waiting for the connection of the next request instruction

2) zabbix agent obtains the status detection script and zabbix template for apache [root@agent ~] # wget https://www.ixdba.net/zabbix/zabbix-nginx.zip[root@agent ~] # unzip zabbix-nginx.zip [root@agent ~] # ll nginx_status.sh zbx*-rw-r--r-- 1 root root 1106 November 1 2018 nginx_status.sh-rw-r--r-- 1 root root 20703 November 1 2018 zbx_nginx_templates.xml/ / nginx_status.sh: required script / / zbx_nginx_templates.xml: required template [root@agent ~] # mv nginx_status.sh / etc/zabbix/shell/ [root@agent ~] # chmod ointx / etc/zabbix/shell/nginx_status.sh [root@agent ~] # chown zabbix.zabbix / etc/zabbix/shell/nginx_status.sh [root@agent ~] # vim / etc/zabbix/zabbix_agentd.d/userparameter_nginx.conf// write the template file for nginx Monitoring script UserParameter=nginx.status for fetching nginx [*], / etc/zabbix/shell/nginx_status.sh $1 [root@agent ~] # systemctl restart zabbix-agent [root@zabbix ~] # zabbix_get-s 192.168.1.8-p 10050-k "nginx.status [active]" 1//zabbix server test whether data can be obtained 3) zabbix web page import template

As shown in the figure:

4) View nginx status data

As shown in the figure:

You can see from the picture that the data has been obtained!

Configuration nginx monitoring completed!

For the above about how Zabbix to achieve the monitoring of Mysql, Apache, Nginx, we do not find it very helpful. If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

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