您的位置:首页 > 数据库 > MySQL

nagios监控web/mysql多角度实战分享(三)

2012-12-14 12:15 288 查看
nagios监控web/mysql多角度深度实战部署过程分享(三)

#########################################################

#《老男孩linux运维高薪就业培训中心》

#nagios监控课程课上上机考试:

#date:2011-07-17

#作者:老男孩---《老男孩linux就业培训中心 》

#QQ:31333741 MAIL:oldboy521@hotmail.com

#linux运维技术交流群:45039636

#blog: http://oldboy.blog.51cto.com

#psite: http://oldboy.cc(即将开放)

#pblog:http://blog.etiantian.org

##########################################################

《老男孩linux运维高薪就业培训中心》-nagios监控课程课上上机考试:

问题3:监控mysql主从同步及延迟等。

##############################################################

██使用check_mysql插件 检查mysql主从同步 (3307为从库)[主动方式]

#############################################################

1.调试check_mysql主从同步的命令

mysql> grant super,replication slave on *.* to monitor@'10.0.0.%' identified by 'oldboy123';

Query OK, 0 rows affected (0.00 sec)

[root@nagios-server libexec]# ./check_mysql -umonitor -p oldboy123 -s /data/3307/mysql.sock -P3307 -H 10.0.0.148 -S

Slave IO: No Slave SQL: Yes Seconds Behind Master: (null)

2.编辑commands.cfg

# 'check_mysql_slave' command definition

define command{

command_name check_mysql_slave

command_line $USER1$/check_mysql -umonitor -p oldboy123 -s /data/3307/mysql.sock -P3307 -H 10.0.0.148 -S

}

3.添加检查mysql同步的服务配置

define service {

use generic-service

host_name 015-etiantian-1-2

service_description check_mysql_slave

check_command check_mysql_slave

max_check_attempts 2

normal_check_interval 4

retry_check_interval 4

check_period 24x7

notification_interval 1440

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}

4.检查语法并重起nagios

/etc/init.d/nagios checkconfig

/etc/init.d/nagios reload

5.进入界面查看变化

不同步状态时的内容,界面服务那一行为红色

check_mysql_slave CRITICAL 04-24-2011 17:20:11 0d 0h 0m 21s 1/2

Slave IO: No Slave SQL: Yes Seconds Behind Master: (null)

同步状态时的内容,界面服务那一行为绿色

check_mysql_slave OK 04-24-2011 17:28:11 0d 0h 2m 35s 1/2 Uptime: 182 Threads: 1 Questions: 7 Slow queries: 0 Opens: 11 Flush tables: 1 Open tables: 6 Queries per second avg: 0.038

Slave IO: Yes Slave SQL: Yes Seconds Behind Master: 0

提示:我们也可以自己写插件来实现检查mysql主从同步。

######################################################################

##############################################################

██使用check_mysql插件 检查mysql主从同步 (3307为从库)[被动方式]

#############################################################

就不重复写了,参考下 分享一,及分享二 有详细描述。

##########################################

██ 人工手写mysql插件实现监控mysql主从同步

##########################################

1、开发MYSQL主从同步监控脚本如下

[root@nagios-server libexec]# cat check_mysql_replicationv1.0

#!/bin/sh

############################################

# this script function is : #

# check_mysql and mysql repl #

# Create by oldboy 2010-11-03 #

# mail:oldboy521@gmail.com #

############################################

PROGNAME=`basename $0`

PROGPATH=`echo $0 | sed -e 's,[\\/][^\\/][^\\/]*$,,'`

. $PROGPATH/utils.sh

print_usage() {

echo "Usage:"

echo "/bin/sh $PROGNAME ip"

exit 1

}

#$1 ip

if [ $# -ne 1 ];then

print_usage

fi

#check mysql slave

declare -a slave_is

slave_is=($(mysql -umonitor -p'123' -h $1 -P3307 -e "show slave status\G"|egrep "Slave_IO_Running|Slave_SQL_Running"|awk '{print $2}'))

if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ]

then

echo "OK-Slave_IO_Running=${slave_is[0]}; Slave_SQL_Running=${slave_is[1]}"

exit $STATE_OK

else

echo "Critical -mysql or mysql slave is error"

exit $STATE_CRITICA

fi

提示:我们手写的以上插件脚本 实际上就相当于 手写了一个nagios自带的插件check_mysql

部署方法也可以是主动或被动模式 部署方法 和上面一样,这里就不细说了。看我的实际部署演示。

2.将脚本传到服务端/usr/local/nagios/libexec下调试

[root@nagios-server libexec]# dos2unix check_mysql_replicationv1.0

dos2unix: converting file check_mysql_replicationv1.0 to UNIX format ...

[root@nagios-server libexec]# chmod 755 check_mysql_replicationv1.0

[root@nagios-server libexec]# ./check_mysql_replicationv1.0

Usage:

/bin/sh check_mysql_replicationv1.0 ip

[root@nagios-server libexec]# ./check_mysql_replicationv1.0 10.0.0.148

OK-Slave_IO_Running=Yes; Slave_SQL_Running=Yes

3.编辑commands.cfg

# 'check_mysql_replication_script' command definition

define command{

command_name check_mysql_slave_from_script

command_line $USER1$/check_mysql_replicationv1.0 10.0.0.148

}

4.增加监控服务

[root@nagios-server oldboy]# cat mysql_replication_from_script.cfg

define service {

use generic-service

host_name 015-etiantian-1-2

service_description check_mysql_rep01

check_command check_mysql_slave_from_script

max_check_attempts 1

normal_check_interval 1

retry_check_interval 1

check_period 24x7

notification_interval 30

notification_period 24x7

notification_options w,u,c,r

contact_groups admins

process_perf_data 1

}

4.检查语法并重起nagios

/etc/init.d/nagios checkconfig

/etc/init.d/nagios reload

5.进入界面查看变化

check_mysql_rep01 OK 04-24-2011 18:39:40 0d 0h 3m 40s 1/1

OK-Slave_IO_Running=Yes: Slave_SQL_Running=Yes

提示:时间有点紧 本篇细节还不够,有不明白的,给我留言吧。谢谢大家浏览啊。
本文出自 “老男孩的linux博客” 博客,请务必保留此出处http://oldboy.blog.51cto.com/2561410/619293
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: