手机版
你好,游客 登录 注册 搜索
背景:
阅读新闻

Nagios监控MySQL主从状态的简单脚本

[日期:2012-12-11] 来源:51cto  作者:jokerlishuo [字体:大 中 小]
使用nagios监控MySQL主从,在监控主机上需要安装nrpe软件包以及nagios软件包,安装步骤就不多说了,下面进入正题
 
在监控主机上:
 
首先定义主机:
 
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 {
        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
 }
 
定义command:
 
define command {
        command_name    check_nrpe
        command_line    /usr/local/nagios/libexec/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
 }
 
在被监控主机上:
 
安装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
 
在最后添加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/123`
 slave=`mysql -e 'show slave status' &> /tmp/234 | awk =F: '{if($1~/Exec/)print $2}' /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
 
最后进行测试,本人亲测OK~~~linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款