Detailed explanation of how Zabbix monitors the master-slave status of MySQL

Detailed explanation of how Zabbix monitors the master-slave status of MySQL

After setting up the MySQL master-slave, you often don't know whether the slave status is OK, and sometimes you can't know in time when an exception occurs. Here, you can use shell scripts combined with zabbix to achieve monitoring and alarm

Generally, the running status of the slave in MySQL is checked by checking whether the Slave_IO_Running thread and the Slave_SQL_Running thread are ok. You can check it by using the command "show slave status\G;". So here we make a judgment based on these two values.

Agent-side script writing and configuration

Note: I put all zabbix-related scripts in the /etc/zabbix/script/ directory. The following are all operated on the monitored end of zabbix, and the above database belongs to the slave of MySQL master-slave

1) Scripting

[root@srt-xt ~]# cd /etc/zabbix/script/
[root@srt-xt /etc/zabbix/script]# cat mysql_slvae_status.sh 
#!/bin/bash
#Desc: Used to obtain master-slave synchronization information, determine whether the master-slave is abnormal, and then submit it to zabbix
#Date: 2019-06-06
#by:Lee-YJ
USER="root"
PASSWD="nae3eabo9naeli1Oov1a"
NAME=$1
function IO {
  Slave_IO_Running=`mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_IO_Running |awk '{print $2}'`
  if [ $Slave_IO_Running == "Yes" ]; then
    echo 0 
  else
    echo 1 
  fi
}
function SQL {
  Slave_SQL_Running=`mysql -u $USER -p$PASSWD -e "show slave status\G;" 2> /dev/null |grep Slave_SQL_Running: |awk '{print $2}'`
  if [ $Slave_SQL_Running == "Yes" ]; then
    echo 0 
  else
    echo 1 
  fi
}
case $NAME in
  io)
    IO
  ;;
  sql)
    SQL
  ;;
  *)
    echo -e "Usage: $0 [io | sql]"
esac

2) Modify the configuration file and write a self-configuration file that specifies the path of the script written above

[root@srt-xt ~]# cd /etc/zabbix/zabbix_agentd.d/ 

[root@srt-xt /etc/zabbix/zabbix_agentd.d]# cat userparameter_mysql_slave.conf 
# Get MySQL slave status UserParameter=mysql.slave[*],/etc/zabbix/script/mysql_slvae_status.sh $1

3) Restart zabbix-agent

[root@srt-xt /etc/zabbix/zabbix_agentd.d]# /etc/init.d/zabbix-agent restart

4) Test on the zabbix-server to see if the value can be successfully obtained. According to the above script, 0 here means normal, and 1 means abnormal.

[root@xxxxx ~]# zabbix_get -s 218.75.249.55 -k mysql.slave[sql]
0
[root@xxxxx ~]# zabbix_get -s 218.75.249.55 -k mysql.slave[io]
0

Server-side web configuration

1) Configure the Slave_IO_Running thread monitoring item

2) Configure the Slave_SQL_Running thread monitoring item

3) Configure the trigger of the Slave_IO_Running thread

4) Configure the trigger of the Slave_SQL_Running thread

5) Configure trigger actions

Configure the actions to be performed (send a message to the administrator)

Configuration status recovery operation (also sends a message to the administrator)

Finally view the monitoring items

At this point, the status monitoring of the MySQL master-slave slave is completed.

Summarize

The above is a detailed explanation of the method of Zabbix monitoring the master-slave status of MySQL introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!
If you find this article helpful, please feel free to reprint it and please indicate the source. Thank you!

You may also be interested in:
  • How to monitor mysql using zabbix
  • Zabbix implements monitoring of multiple mysql processes
  • Detailed tutorial on how to monitor Nginx/Tomcat/MySQL using Zabbix
  • How to monitor mysql using percona plugin in zabbix
  • Zabbix 2.4.5 comes with MySQL monitoring configuration tutorial
  • Basic tutorial on installing and configuring Zabbix to monitor MySQL
  • Zabbix monitors mysql instance method

<<:  In-depth explanation of slots and filters in Vue

>>:  Explore the truth behind the reload process in Nginx

Recommend

NestJs uses Mongoose to operate MongoDB

I recently started learning the NestJs framework....

Beginners understand MySQL deadlock problem from source code

After many difficult single-step debugging late a...

Solution to 404 Problem of Tomcat Installation in Docker

Find the containerID of tomcat and enter the toma...

Linux kernel device driver Linux kernel basic notes summary

1. Linux kernel driver module mechanism Static lo...

Solution to the garbled code problem in MySQL 5.x

MySQL is a commonly used open source database sof...

Recommended 20 best free English handwriting fonts

Jellyka BeesAntique Handwriting [ank]* Jellyka Cut...

12 Javascript table controls (DataGrid) are sorted out

When the DataSource property of a DataGrid control...

MYSQL unlock and lock table introduction

MySQL Lock Overview Compared with other databases...

Quickly solve the problem of slow Tomcat startup, super simple

Today I helped a classmate solve a problem - Tomc...

Detailed explanation of Linux system directories sys, tmp, usr, var!

The growth path from a Linux novice to a Linux ma...

MySQL database master-slave replication and read-write separation

Table of contents 1. Master-slave replication Mas...

Use neat HTML markup to build your pages

The Internet is an organism that is constantly ev...

How to use a game controller in CocosCreator

Table of contents 1. Scene layout 2. Add a handle...

Analysis of Mysql transaction characteristics and level principles

1. What is a transaction? A database transaction ...

MySQL chooses the right storage engine

When it comes to databases, one of the most frequ...