CentOS under Nagios monitoring MySQL master-slave Configuration example

Source: Internet
Author: User
Tags chmod extend snmp

Method One

First, MySQL from the server settings

1, MySQL from the Server users add

The code is as follows Copy Code

Add users by executing the following statement:
Mysql> GRANT REPLICATION CLIENT on *.* to Monitor@localhost identified by ' PassWord ';
2. Download check-mysql-slave.pl Script
cd/usr/local/bin/
wget http://www.centos.bz/wp-content/uploads/2012/10/check-mysql-slave.pl
chmod +x check-mysql-slave.pl
3, in MySQL from the server configuration extend Mysql-slave
Add the following code at the end of the/etc/snmp/snmpd.conf file:
Extend mysql-slave/usr/local/bin/check-mysql-slave.pl--user monitor--pass PassWord--sock/var/lib/mysql/mysql.sock
Note that the relevant parameters are modified for their own.
Overload SNMP After:
Service SNMPD Reload

Second, monitor server settings

1. Download check_snmp_extend.sh Script

The code is as follows Copy Code
Mkdir/usr/local/nagios/libexec.local
Cd/usr/local/nagios/libexec.local
wget http://www.centos.bz/wp-content/uploads/2012/10/check_snmp_extend.sh
chmod +x check_snmp_extend.sh
2. Define USER10 variables
Add the following variables to the file/usr/local/nagios/etc/resource.cfg:
$USER 10$=/usr/local/nagios/libexec.local
3. Define Check_snmp_extend command
Add in/usr/local/nagios/etc/objects/commands.cfg:
Define Command{
Command_name Check_snmp_extend
Command_line $USER 10$/check_snmp_extend.sh $HOSTADDRESS $ $ARG 1$
}

4, the definition of monitoring MySQL master service

Add the following service in the host configuration file, such as/usr/local/nagios/etc/objects/www.centos.bz.cfg (Note that This www.cnetos.bz.cfg file is already included in the Nagios.cfg configuration file.

The code is as follows Copy Code
Define Host{
Use Linux-server
HOST_NAME www.centos.bz
Alias Www.centos.bz
Address 142.4.33.74
}
......
......
Define Service{
# # This is an example service configured as
# # Extend Servicename/path/to/service-check.sh
# # on Remote.server in/etc/snmp/snmpd.conf
Use Generic-service
HOST_NAME www.centos.bz
service_description MySQL slave status
Check_command Check_snmp_extend!mysql-slave
}

Method Two


The following is a monitoring MySQL copy of the output from the server:

The code is as follows Copy Code
Mysql> Show Slave STATUSG
1. row***************************
Slave_io_state:waiting for Master to send event
master_host:192.168.93.16
Master_user:rep1
master_port:3306
Connect_retry:60
master_log_file:mysql-bin.000004
read_master_log_pos:1752541
relay_log_file:hy-mysql3-relay-bin.000088
relay_log_pos:2339
relay_master_log_file:mysql-bin.000004
Slave_io_running:yes
Slave_sql_running:yes
replicate_do_db:

This output, the most critical point is "Slave_io_running:yes" and "Slave_sql_running:yes", the two values are all "yes" indicates that the master-slave copy is normal, otherwise there is a problem.
Operation Steps:
1, in the main database server to add a user, to give a lower authority, the exercise as

The code is as follows Copy Code
MySQL > Grantreplication client on *.* to ' nagios ' @ '% ' identified by ' Nagios ';
mysql> flush Privileges;

2, login from the server verification, to see whether it is normal. Action for # MYSQL-UNAGIOS-PNAGIOS-E "show slavestutasg"   NOTE: This operation is operated under the shell!!
3, install Nrpe from the server, and then add a line of "Command[check_mysql_slave]=/usr/local/nrpe/libexec/chech_mysql_slave".
4, Scripting/usr/local/nrpe/libexec/check_mysql_slave (this is the core of monitoring its role), and its contents are as follows:

The code is as follows Copy Code
#!/bin/sh
Declare-a slave_is
Slave_is= ($ (/usr/local/mysql/bin/mysql-unagios-pnagios-e "show slave statusg" |grep Running|awk ' {print $} '))
If [' ${slave_is[0]} ' = ' yes '-a ' ${slave_is[1]} ' = ' yes ']
Then
echo "Ok-slave isrunning"
Exit 0
Else
echo "Critical-slave IsError"
Exit 2
Fi

5, run this script manually, observe the output.
6, perform check_nrpe-h ip-c Check_mysql_slave observe its output.
7, modify Nagios, and test.
8, functional testing (slightly)


Method Three


First define the host:

The code is as follows Copy Code
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
Notification_interval 10
Notification_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
Notification_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 $ARG 1$
}

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 at the end
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 $} '/tmp/123 '
Slave= ' mysql-e ' show slave status ' &>/tmp/234 | awk =f: ' {if ($1~/exec/) print $} '/tmp/234 '
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, I test ok~~~

Related Article

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.