In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-15 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "Zabbix to achieve automatic discovery and monitoring of MySQL", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Zabbix to achieve automatic discovery and monitoring of MySQL" bar!
I. requirements and ideas of the scheme
Because there are many servers running MySQL service, and each server may run databases with multiple different ports, it will be too troublesome and time-consuming to manually modify the agent.conf,web and add monitoring. There are two options at this time: one is to deploy an auto-discovery script on each server running mysql, modify the agent.conf and customize the KEY;, and the other is to have a single server to monitor all mysql services running on all servers. It seems that plan two is easier.
The second way of thinking is:
Suppose there are five servers A, B, C, D, E with mysql running on them, and each server has 2 + mysql. Here, assume that server A monitors the status of mysql on all servers. At this point, you need to record the IP of the five servers and the port occupied by the mysql service on them, and write them into one file: eg:
192.168.12.14 3306 192.168.12.14 3307 192.168.12.15 3308 192.168.12.15 3380.
Put the file in a directory under the zabbix directory, and grant permissions, and then write a json script to call the file, and you need to IP the value and output all the port on the IP when executing the script file.
Add a custom key. You need to define an automatically discovered key, and then define a key that queries the mysql status of all ports on this server based on IP. Restart zabbix_agentd and get the parameters through zabbix_get to see if it is normal.
Configure the web interface. In the web configuration interface, create a host whose ip points to the IP of server A, cut the server's [HOST.NAME] to point to the IP of the mysql you want to monitor ([HOST.NAME] generally refers to "Visable name"), point all the servers monitoring mysql to a group, and then call the automatic discovery mysql template. Then create the remaining servers.
This solution is not a very good solution, but it is relatively good. If there is a new mysql server in the future, you only need to modify the list file with IP and PORT, and there is no need to restart agent.
2. Configure Agent:
1. Edit the mysqld file
# cat / usr/local/zabbix/bin/mysqld 172.16.8.250 3306 172.16.8.250 3309 172.16.8.252 3306 172.16.8.252 3307
Note: this paper realizes the monitoring of the database on 8.250 and the database of local 250.
2. Mysql is authorized.
Each of the four databases is assigned to the 172.16.8.250 host with user zabbix, password 111and show global status permissions.
3. Edit discovery_mysql.sh
# cat / usr/local/zabbix/bin/discovery_mysql.sh #! / bin/bash # mysql low-level discovery # Script_name discovery_mysql.sh res= `cat / usr/local/zabbix/bin/mysqld | grep $1 | grep-v "^ #" | awk'{print $2} '`port= ($res) printf' {\ n' printf'\ t "data": [\ n' for key in ${! port [@]} do if [["${# port [@]}"-gt 1 & & " ${key} "- ne" $((${# port [@]}-1)) "]] Then printf'\ t {\ n' printf "\ t\ t\" {# MYSQLPORT}\ ":\" ${port [${key}]}\ "} \ n "else [[" ${key} "- eq" ((${# port [@]}-1)) "]] printf'\ t {\ n' printf"\ t\ t\ "{# MYSQLPORT}\":\ "${port [${key}]}\"\ n "fi done printf'\ t]\ n`printf'}\ n'
Grant executive authority:
# chmod + x / usr/local/zabbix/bin/discovery_mysql.sh
Test execution effect:
# sh / usr/local/zabbix/bin/discovery_mysql.sh 172.16.8.250 {"data": [{"{# MYSQLPORT}": "3306"}, {"{# MYSQLPORT}": "3309"}]}
Paste the above results into the json testing website to see if the results are correct http://jsonlint.com/
4. Modify agentd.conf
Turn on the include option
Include=/usr/local/zabbix/etc/zabbix_agentd/
Add mysql auto-discovery rules and customize key
# cat / usr/local/zabbix/etc/zabbix_agentd/mysql_discovery.conf # $1 = = IP $2 = = PORT $3==COMMAND UserParameter=zabbix_low_discovery [*], / bin/bash / usr/local/zabbix/bin/discovery.sh $1 UserParameter=mysql_stats [*], mysql-uzabbix-p111-usr/local/zabbix/bin/discovery.sh 2-hourly 1-e "show global status" | grep "\" | cut-f2 UserParameter=mysql.alive [*], mysqladmin-uzabbix-p111-hog1-Prun2 ping | grep-c alive
5. Test:
Restart zabbix_agentd and test whether the zabbix mysql auto-discovery rule is correct through zabbix_get in zabbix server.
Note: 172.16.8.250 is the zabbix server,agent address of 127.0.0.1, please modify the following command according to your own situation.
# zabbix_get-s 127.0.0.1-k zabbix_log_ discovery [172.16.8.250] {"data": [{"{# MYSQLPORT}": "3306"}, {"{# MYSQLPORT}": "3309"}]} # zabbix_get-s 127.0.0.1-k mysql_stats [172.16.8.250 3306 uptime]
If you can get the data correctly, it is right.
Please indicate the source of the original text when reproduced: http://www.minunix.com/2014/04/zabbix_low_discovery_mysql_01/
3. Add a host to Zabbix WEB
1. Import template discovery_mysql.xml
2. Add a host:
Link template:
Note: since the update time defined by the template is 3600s, if you want to see the effect quickly, you can first modify the "Interval" update time of the template custom rules to 60, and then you can see the data in "last data".
To monitor 172.16.8.252, just create a host and change the value of visable name from 172.16.8.250 to 172.16.8.252.
Thank you for reading, the above is the content of "Zabbix realizes automatic discovery and monitoring of MySQL". After the study of this article, I believe you have a deeper understanding of the problem of automatic discovery and monitoring of MySQL by Zabbix, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.