利用check_mysql_replication.pl监控mysql主从热备
安装插件
# wget http://www.james.rcpt.to/svn/trunk/nagios/check_mysql_replication/check_mysql_replication.pl
# mv check_mysql_replication.pl /usr/local/nagios/libexec/check_mysql_replication
# chmod 755 /usr/local/nagios/libexec/check_mysql_replication
# yum -y install perl-DBD*
check_mysql_replication命令资料
Usage: check_mysql [-d database] [-H host] [-P port] [-s socket] [-u user] [-p password] [-S]
Options:
-h, –help Print detailed help screen
-V, –version Print version information
-H, –hostname=ADDRESS Host name, IP Address, or unix socket (must be an absolute path)
-P, –port=INTEGER Port number (default: 3306)
-s, –socket=STRING Use the specified socket (has no effect if -H is used)
-d, –database=STRING Check database with indicated name
-u, –username=STRING Connect using the indicated username
-p, –password=STRING Use the indicated password to authenticate the connection
==> IMPORTANT: THIS FORM OF AUTHENTICATION IS NOT SECURE!!! <==
Your clear-text password could be visible as a process table entry
-S, –check-slave Check if the slave thread is running properly.
-w, –warning Exit with WARNING status if slave server is more than INTEGER seconds behind master
-c, –critical Exit with CRITICAL status if slave server is more then INTEGER seconds behind master
There are no required arguments. By default, the local database is checked using the default unix socket. You can force TCP on localhost by using an IP address or FQDN (’localhost’ will use the socket as well).
Send email to nagios-users@lists.sourceforge.net if you have questions regarding use of this software. To submit patches or suggest improvements,send email to nagiosplug-devel@lists.sourceforge.net
check_mysql_replication命令资料
check_replication.pl [ --slave ] [ --slave-pass][ --slave-port ] [ --slave-user ] [ --master ]
[ --master-pass] [ --master-port] [ --master-user ][ --crit] [ --warn] [ --check-random-database ]
[ --table-rows-diff-absolute-crit ][ --table-rows-diff-absolute-warn ]
–slave - MySQL instance running as a slave server
–slave-port - port for the slave
–slave-user - Username with File/Process/Super privs
–slave-pass
- Password for above user
–master - MySQL instance running as server (override)
–master-port - port for the master (override)
–master-user - Username for master (override)
–master-pass
- Password for master
–crit
- Number of complete master binlogs for critical state
–warn
- Number of complete master binlog for warning state
–check-random-database - Select a random DB from the slave’s list of databases and compare to the master’s information for these (need SELECT priv)
–table-rows-diff-absolute-crit - If we do the check-random-database,then ensure that the change in row count between master and slave is below this threshold, and go critical if not
–table-rows-diff-absolute-warn - If we do the check-random-database,then ensure that the change in row count between master and slave is below this threshold, and go warning if not
建立nagios监控用户
nagios监控mysql repl 创建nagios监控用户
master
mysql> mysql> grant replication client,replication slave,super,select on *.* to 'nagios'@'192.168.1.6' identified by 'nagios';
slave
mysql> grant file,process,super,select on *.* to 'nagios'@'192.168.1.6' identified by 'nagios';
测试
[root@localhost libexec]# ./check_mysql_replication.pl -slave 192.168.1.7 -slave-user nagios -slave-pass nagios -master 192.168.1.2 -master-user nagios -master-pass nagios
[root@localhost nagios]# vi /usr/local/nagios/etc/hosts.cfg
define host{
host_name slave_mysql_192.168.1.7
address 192.168.1.7
check_command check-host-alive
contact_groups mail
max_check_attempts 3
notification_interval 10
notification_period 24x7
notification_options d,u,r
}
[root@localhost nagios]# vi /usr/local/nagios/etc/hostgroups.cfg
define hostgroup{
hostgroup_name slave-mysql
members slave_mysql_192.168.1.7
}
[root@localhost nagios]# vi /usr/local/nagios/etc/services.cfg
define service{
hostgroup_name slave-mysql
service_description mysql_replication
check_command check_mysql_repl
contact_groups mail
check_period service
max_check_attempts 4
normal_check_interval 10
retry_check_interval 60
notifications_enabled 1
notification_options c,r
}
[root@localhost nagios]# vi /usr/local/nagios/etc/objects/commands.cfg
define command{
command_name check_mysql_repl
command_line $USER1$/check_mysql_replication.pl -slave 192.168.1.7 -slave-user nagios -slave-pass nagios -master 192.168.1.2 -master-user nagios -master-pass nagios
}
(注:请根据现有条件设置,也可以不加如hostgroup,自行设置!)
登录测试即可!
231

被折叠的 条评论
为什么被折叠?



