Welcome 微信登录

首页 / 数据库 / MySQL / Nagios监控MySQL主从状态的简单脚本

使用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~~~Oracle for Linux 双机 控制文件报错问题insert into select 批量加载出错解决方案相关资讯      Nagios监控MySQL  MySQL主从监控  Nagios监控脚本 
  • Nagios 里面监控MySQL 监控事务夯  (12/31/2014 13:53:57)
  • Nagios监控MySQL报错:NRPE:   (07/16/2014 10:28:14)
  • 自己编写Nagios 监控MySQL插件  (02/20/2014 20:15:53)
  • MySQL服务器部署Nagios监控  (10/10/2014 06:58:03)
  • 将Nagios监控信息存入MySQL  (04/25/2014 20:03:20)
本文评论 查看全部评论 (0)
表情: 姓名: 字数

版权所有©石家庄振强科技有限公司2024 冀ICP备08103738号-5 网站地图