Zabbix monitoring MySQL master-slave replication
. Monitor the replication of MySQL
Principle: Get values for slave_io_running and slave_sql_running using Run show slave status on Slave
1. Create a new monitoring user on MySQL
Grant replication Client on * * to ' zabbix ' @ ' localhost ' identified by ' Zabbix ';
Flush privileges;
2. Create a new mysql_slave_status.sh script under/data/zabbix/sbin
MySQL enters the password directly in the terminal, there will be a warning message output,
First add the MySQL user's password in the/ETC/MY.CNF
Vim/etc/my.cnf
[Client]
user = Zabbix
Password = Zabbix
vim/data/zabbix/sbin/mysql_slave_status.sh
#!/bin/bash
Mysql-uzabbix-e "show slave Status\g" |grep-e "slave_io_running| Slave_sql_running "|awk ' {print $} ' |grep-c Yes
....
chmod +x/data/zabbix/sbin/mysql_slave_status.sh
3. Modify the/data/zabbix/conf/zabbix_agentd.conf file
Unsafeuserparameters=1
userparameter=mysql.slave-status,/data/zabbix/sbin/mysql_slave_status.sh
4. Restart the ZABBIX_AGEMTD service
Service Zabbix_agentd Restart
Configuring the Zabbix service side
Test Client Script
Zabbix_get Command Common parameters
-S--host: Specifies the client host name or IP
-P--port: Client port, default 10050
-I--source-address: Specify the source IP, write the IP address of the Zabbix server, and generally leave it blank, if the server has multiple IPs, you specify one.
-K--key: You want to get the key
Zabbix_get-s 221.195.1.101-k "Mysql.slave-status"
If the above return is 2, then it is normal (1.mysql copy normal 2.ZABBIX_AGENTD is configured properly),
On behalf of Slave_io_running and slave_sql_running two states are yes, here 221.195.1.101 is my slave IP address
If the test is okay, sign in to the Web page
1. Create a template first
--Configuration--templates--Create templates
Fill in the template name: Mysql.slave-status
Visualization Name: Mysql.slave-status
Group.....
Describe.....
After saving
Create a monitoring item
Enter the created template Mysql.slave-status
Name: Mysql.slave-status
Type: Zabbix Client Side
Key value: Mysql.slave-status
Type of information: number (no plus or minus)
Data and new time (in seconds): 30 You can change the data according to your own situation with the new time, I changed to 5 seconds
Other values are good by default
Create a Trigger
Name: Mysql.slave-status
Severity: Warning
Problem form: Add--Select Monitoring Item Mysql.slave-status function: Latest T-value <n N:2
After adding the expression is this: {mysql.slave-status:mysql.slave-status.last ()}<2
Restore expression: Add-Select Monitoring Item Mysql.slave-status function: Latest T-value =n N:2
......
The configuration of the Web page is finished,
The configuration of the Zabbix 2.* version and the Zabbix 3.* version are different in some places, but they are quite similar.
-------------------------
Whether the test configuration can trigger an alarm
Stop slave in MySQL environment;
We'll get an email in a few minutes.
Rigger:mysql.slave-status
Trigger Status:problem
Trigger severity:warning
Trigger URL:
Item values:
1. Mysql.slave-status (221.195.1.101:mysql.slave-status): 0
Original Event id:3106
-------------------------------
Start slave in MySQL environment;
Trigger:mysql.slave-status
Trigger Status:ok
Trigger severity:warning
Trigger URL:
Item values:
1. Mysql.slave-status (221.195.1.101:mysql.slave-status): 2
Original Event id:3106
---------------------------------
Zabbix monitoring MySQL master-slave replication