1, deploy a MySQL from the database, need to constantly monitor this slave state from the database. Principle is obtained by performing show slave status from the Zabbix on MySQL
Slave_io_running| Whether the slave_sql_running state is yes to determine whether the master-slave is normal.
MySQL synchronization function by 3 threads (master on 1, slave on 2) to achieve, simply say: Master send log one, slave receive log one, slave run log one.
First, let's explain some of the important parameters in show slave status:
Whether the SLAVE_IO_RUNNING:I/O thread was started and successfully connected to the primary server.
Whether the Slave_sql_running:sql thread is started.
Seconds_behind_master: This field is an indication of how much "backward" the subordinate server is. When a dependent SQL thread is running (processing an update), this field begins with the time stamp of the most recent event executed by this thread on the primary server, and the number of seconds elapsed. This field is zero when this thread is caught by a subordinate server I/O thread and goes into an idle state, waiting for more events from the I/O thread. In summary, this field measures the time gap between the subordinate server SQL thread and the subordinate server I/O thread, in seconds.
So how do you monitor whether the server is running properly?
2, we can use a command to obtain the master-slave synchronization information:
Mysql-uzabbix-p-e ' show slave status\g ' |grep-e "slave_io_running| Slave_sql_running "|awk ' {print $} ' |grep-c Yes
The main thing to get is the following two values
Slave_io_running:yes
Slave_sql_running:yes
3, create a MySQL configuration file, in the Zabbix_agent installation directory,
To add the last line in the userparameter_mysql.conf file, the advantage is that there will be no prompt to use the password on the command line when obtaining the master-slave synchronization information.
Userparameter=mysql.replication,home=/etc/zabbix/etc/usr/local/mysql/bin/mysql-e ' show slave status\G ' |grep-e ' Slave_io_running| Slave_sql_running "|awk ' {print $} ' |grep-c Yes
Restart Agent Client
Check whether the master/slave synchronization information can be obtained on the zabbix_server side.
There's a hint in scripting,
Will cause an error in Zabbix.
4. Create template templates on Zabbix server
New template templates App MySQL Replication
configuration| Templates|create Templates, just fill in the template name, select the next group to
Create applications on the new template App MySQL replication
Create Items,key manual Fill Mysql.replication
Create a triggers trigger,
Click Add, which is the expression for the triggers trigger. When the obtained key value is not 2 o'clock alarm
Add graphs
To Monitoring--graphs view the monitoring chart
Zabbix monitoring MySQL master-slave synchronization