Zabbix monitors MySQL master-slave Replication

Source: Internet
Author: User
Recently, a zabbix monitoring system has been set up in the company. Now we need to use zabbix to monitor the master-slave synchronization of mysql.

Recently, a zabbix monitoring system has been set up in the company. Now we need to use zabbix to monitor the master-slave synchronization of mysql.

Recently, a zabbix monitoring system has been set up in the company. Now we need to use zabbix to monitor the master-slave synchronization of mysql.

Now let's take a look at the detailed configuration steps:

1. First assign a monitoring account to mysql:

Mysql> grant replication client on *. * to 'zabbix' @ 'localhost ';

2. Write a script

Run a command first.

Mysql-u zabbix-e 'show slave status \ G'

In the output information, select

Slave_IO_Running: Yes

Slave_ SQL _Running: Yes

These two items to monitor

I tested it. When an exception occurs in the operation data, Slave_ SQL _Running will become No.

When slave stop is executed, both of them will become No

The script content is as follows:

#! /Bin/bash
/Usr/local/mysql/bin/mysql-uzabbix-e 'show slave status \ G' | grep-E "Slave_IO_Running | Slave_ SQL _Running" | awk '{print $2}' | grep-c Yes

I only wrote one command to explain it.

First use the zabbix user to obtain all slave statuses, then grep out of these two statuses, and then output the second column. Finally, check that there are several Yes statuses.

Normally there are two Yes states,

In fact, you will find that there is only one command, but I write it into a script. Here I will talk about it, because if you write the command into the configuration file, each modification is complete, you have to restart the agent, so writing it into the script is more convenient for debugging and modification. This should be a good habit.

3. Add monitoring items to the agent

Add the following line at the end of the file

UserParameter = mysql. replication,/home/zabbix/mysql-replication.sh

In the string after the equal sign, the comma is followed by the Key, followed by the executed script (the script should not forget the execution permission)

After the agent is added, restart the agent program.

4. Add monitoring metrics to the server

Go to the zabbix installation directory. my options are/usr/local/zabbix/bin.

Run./zabbix_get-s 192.168.177.185-k "mysql. replication"

192.168.177.185 is the IP address of my agent.

If the master-slave replication is normal, 2 is returned (indicating that both statuses are "Yes)

Now, the server can obtain the status from the agent.

Add the following metric items on the Management page:

System Configuration-host-select the monitoring metrics of the host to be monitored

In the upper-right corner, select create item

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.