当前位置:  首页  >  服务器技术  >  Linux/unix  >  Linux教程

用nagios监控mysqlreplication主备间的同步情况

#cdetcnagioscommand#wgethttp:www.james.rcpt.tosvntrunknagioscheck_mysql_replicationcheck_mysql_replication.pl#chmod755check_mysql_replication.pl看看用法:#.check_mysql_replication.pl-hcheck_mysql_replicati

# cd /etc/nagios/command

# wget http://www.james.rcpt.to/svn/trunk/nagios/check_mysql_replication/check_mysql_replication.pl

# chmod 755 check_mysql_replication.pl

看看用法:

# ./check_mysql_replication.pl -h
check_mysql_replication.pl: check replication between MySQL database instances

 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 ]
 [ --schema ]

 --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
 --schema           - The database schema to use
 --help                 - This help page
 --version              - Script version information

By default, you should use your configured replication user, as you will 
then only need to specify the user and password once, and this script will 
find the master from the slave's running configuration.

Critical and warning values are now measured as amount of a complete master 
sized binlog. If your master has the default 1GB binlog size, then specifying 
a warning value of 0.1 means that your will let the slave get 100MB out of 
sync before warning; you may want to set warning to 0.01, and critical at 0.1.

MySQL 3: GRANT File, Process on *.* TO repl@192.168.0.% IDENTIFIED BY
MySQL 4: GRANT Super, Replication client on *.* TO repl@192.168.0.% IDE...

If you want to use the check-random-database option, then the user needs 
SELECT privileges on all replicated tables on the master and the slave.

Note: Any mysqldump tables (for backups) may lock large tables for a long 
time. If you dump from your slave for this, then your master will gallop 
away from your slave, and the difference will become large. The trick is to 
set 'crit' above this differnce and 'warn' below.

If you are using the host name "localhost" to connect to port forwards, you'll 
probably hit the issue where MySQL uses the named pipe (socket) on the file 
system instead of there TCP loopback address. Use host name "127.0.0.1".

(c) 2010 James Bromberger, james@rcpt.to, www.james.rcpt.to

先在命令行运行测试:

# /etc/nagios/command/check_mysql_replication.pl --slave 192.168.1.132 --slave-user user --slave-pass passwd --master 192.168.1.131 --master-user user --master-pass passwd
OK: 0.000 diff, 0 secs, 192.168.1.131:3306 (5.0.77-log) -> 192.168.1.132:3306 (5.0.77-log)

运行成功,我们配置到nagios上去。

# vim objects/commands.cfg

加上一段:

define command {
        command_name    check_mysql_replication
        command_line    /etc/nagios/command/check_mysql_replication.pl --slave $HOSTADDRESS$ --slave-user $ARG1$ --slave-pass $ARG2$ --
master $ARG3$ --master-user $ARG4$ --master-pass $ARG5$
        }

# vim objects/hosts.cfg

加上一段:

define service{
        use                             generic-service         ; Name of service template to use
        host_name                       mysql_slave
        service_description             mysql replication
        check_command                   check_mysql_replication!user!passwd!192.168.1.131!user!passwd

吐了个 "CAO" !
扫码关注 PHP1 官方微信号
PHP1.CN | 中国最专业的PHP中文社区 | PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | PHP问答
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有