Simple script for monitoring MySQL Master/Slave status using Nagios

Source: Internet
Author: User
If you use nagios to monitor mysql master and slave databases, you need to install the nrpe software package and the nagios software package on the monitoring host. The installation steps are not described.

If you use nagios to monitor mysql master and slave databases, you need to install the nrpe software package and the nagios software package on the monitoring host. The installation steps are not described.

If you use nagios to monitor mysql master and slave databases, you need to install the nrpe and nagios software packages on the monitoring host. The installation steps are not detailed.

On the monitoring host:

First, define the Host:

Vim/usr/local/nagios/etc/objects/localhost. cfg
Define host {
Host_name joker
Alias test
Address 192.168.xx.xx
Check_command check-host-alive
Notification_options d, u, r
Check_interval 1
Max_check_attempts 2
Contact_groups admins
Icationication_interval 10
Icationication_period 24x7
}

Define service:

Define service {
Host_name joker
Service_description nrpe
Check_period 24x7
Normal_check_interval 2
Retry_check_interval 1
Max_check_attempts 5
Icationication_period 24x7
Notification_options w, u, c, r
Check_command check_nrpe! Check_mysql
}

Define command:

Define command {
Command_name check_nrpe
Command_line/usr/local/nagios/libexec/check_nrpe-H $ HOSTADDRESS $-c $ ARG1 $
}

On the monitored Host:

Install nrpe
Tar fvxz nrpe * .tar.gz
./Configure -- prefix =/usr/local/nagios
Useradd nagios
Make all
Make install
Make install-daemon
Make install-daemon-config
Make install-xinetd

Scp/usr/local/nagios/libexec/check_nrpe root@192.168.18.105:/usr/local/nagios/libexec

Vim/etc/xinetd. d/nrpe
Service nrpe
{
Flags = REUSE
Socket_type = stream
Port = 5666
Wait = no
User = nagios
Group = nagios
Server =/usr/local/nagios/bin/nrpe
Server_args =-c/usr/local/nagios/etc/nrpe. cfg -- inetd
Log_on_failure + = USERID
Disable = no
Only_from = 192.168.18.105
}
Vim/etc/services

Add nrpe 5666/tcp
Service xinetd restart

Vim/usri/local/nagios/etc/nrpe. cfg
Command [check_mysql] =/usr/local/nagios/libexec/check_mysql

Vim/usr/local/nagios/libexec/check_mysql
#! /Bin/bash
Master = 'mysql-h 192.168.18.165-u hello-p123-e 'show master status' &>/tmp/123 | awk 'nr = 2 {print $2} '/tmp /100'
Slave = 'mysql-e' show slave status' &>/tmp/234 | awk = F: '{if ($1 ~ /Exec/) print $2} '/tmp/100'
If [$ master-eq $ slave]; then
Echo "OK"
Rm-fr/tmp/123
Rm-fr/tmp/234
Exit 0
Else
Echo "error"
Mv/tmp/123/tmp/err1
Mv/tmp/234/tmp/err2
Exit 2

Finally, perform the test. I personally tested OK ~~~

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.