Nagios监控lvs服务

1在lvs 服务器上安装nrpe客户端:

1.1,rpm方式安装nrpe客户端

下载地址:http://download.csdn.net/detail/mchdba/7493875

[[email protected] nagios]# ll

总计 768
-rw-r--r-- 1 root root 713389 12-16 12:08 nagios-plugins-1.4.11-1.x86_64.rpm
-rw-r--r-- 1 root root  32706 12-16 12:09 nrpe-2.12-1.x86_64.rpm
-rw-r--r-- 1 root root  18997 12-16 12:08 nrpe-plugin-2.12-1.x86_64.rpm
[[email protected] nagios]# rpm -ivh *.rpm --nodeps  --force

1.2 在配置文件最末尾,添加配置信息以及监控主机服务器ip地址

[[email protected] localhost nagios]# vim /etc/nagios/nrpe.cfg
# add by tim on 2014-06-11
command[check_users]=/usr/local/nagios/libexec/check_users -w 8 -c 15
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/sda
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
#command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 50 -c 80
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 750 -c 800
command[check-host-alive]=/usr/local/nagios/libexec/check_ping -H localhost -w 3000.0,80% -c 5000.0,100% -p 5
allowed_hosts = 127.0.0.1, 10.2xx.3.xx

check下命令是否生效:

[[email protected] nrpe-2.15]# /usr/local/nagios/libexec/check_users -w 8 -c 15
USERS OK - 2 users currently logged in |users=2;8;15;0
[[email protected] nrpe-2.15]#

看到已经USERS OK -….命令已经生效。

1.3 启动nrpe报错如下:

[[email protected] ~]# service nrpe restart
Shutting down nrpe:                                        [失败]
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
                                                           [失败]
[[email protected] ~]#
[[email protected] nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libssl.so.6: cannot open shared object file: No such file or directory
                                                           [失败]
[[email protected] nagios_client]#

建立连接

[[email protected] nagios_client]# ln -s /usr/lib64/libssl.so /usr/lib64/libssl.so.6
 (如果没有libssl.so,就采用别的libssl.so.10来做软连接,ln -s /usr/lib64/libssl.so.10 /usr/lib64/libssl.so.6)
[[email protected] nagios_client]#

再重新启动如下:

[[email protected] nagios_client]# service nrpe start
Starting nrpe: /usr/sbin/nrpe: error while loading shared libraries: libcrypto.so.6: cannot open shared object file: No such file or directory
                                                           [失败]
[[email protected] ~]# ll /usr/lib64/libcrypto.so
lrwxrwxrwx. 1 root root 18 10月 13 2013 /usr/lib64/libcrypto.so -> libcrypto.so.1.0.0
[[email protected] nagios_client]#

再建链接:

[[email protected] nagios_client]# ln -s /usr/lib64/libcrypto.so /usr/lib64/libcrypto.so.6
(或者如果没有libcrypto.so,就采用libcrypto.so.10做软连接, ln -s /usr/lib64/libcrypto.so.10 /usr/lib64/libcrypto.so.6)
[[email protected] nagios_client]# service nrpe start
Starting nrpe:                                             [确定]
[[email protected] nagios_client]#

1.4 检测下nrpe是否正常运行:

去nagios服务器端check下

[[email protected] ~]#  /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx
NRPE v2.12
[[email protected] ~]#

[[email protected] ~]#  /usr/local/nagios/libexec/check_nrpe -H xx.xx3.xx

NRPE v2.12

[[email protected] ~]#

看到返回NRPE v2.15表示已经连接成功。

2 编写shell脚本实现lvs监控

2.1 监控脚本
Nagios里面没有现成的监控lvs的状态脚本,所以需要去网上找一个简单的监控脚本check_lvs.sh,copy到/usr/lib/nagios/plugins/目录,赋予nagios权限,脚本内容如下:

#!/bin/bash
# http://www.ohlinux.com/archives/632/
# add by tim on 20140613
USAGE_Method=\"$(basename $0)[-h|--hostname] <Free ip or hostname> [-w|--warning] <Free integer> [-c|--critical] <Free integer>\"
USAGE_Value=\"warning value must be small than critical value: `basename $0` $*\"
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

if [ $# -lt 4 ];then
    echo
    echo \"Usage: $USAGE_Method\"
    echo
    exit 0
fi
while [ $# -gt 0 ];
do
    case \"$1\" in
    -w|--warning)
    shift
    warning=$1
    ;;
    -c|--critical)
    shift
    critical=$1
    ;;
    esac
    shift
done

if [[ $warning == $critical || $warning -gt $critical ]]
then
    #echo $warning
    #echo $critical
    echo \"$USAGE_Value\"
    echo \"Usage: $USAGE_Method\"
    exit 0
fi

ACT_COUNT=0
Inactive_count=0
stat1=`sudo ipvsadm | grep http | grep Route|wc -l`
if [ $stat1 -ne 0 ];then
    for NUM in `sudo ipvsadm | grep http | grep Route | awk \‘{print $5}\‘`
    do
         ACT_COUNT=$(($ACT_COUNT+ $NUM))
    done
    for NUM in `sudo ipvsadm | grep http | grep Route | awk \‘{print $6}\‘`
    do
        Inactive_count=$(($Inactive_count+ $NUM))
    done
else
    echo \" stat1:$stat1, lvs critical,lvs is down now.\"
    exit 3
fi

if [[ \"$ACT_COUNT\" -gt \"$critical\" ]]
then
    echo \"critical - lvs connetion is : $ACT_COUNT active\"
    exit 2
fi
if [[ \"$ACT_COUNT\" -gt \"$warning\" && \"$ACT_COUNT\" -lt \"$critical\" ]]
then
    echo \"warning - lvs connetions is : $ACT_COUNT active\"
    exit 1
fi
if [[ \"$ACT_COUNT\" -lt \"$warning\" || $ACT_COUNT == 0 ]]
then
    echo \"LVS OK - LVS is running (conn: $ACT_COUNT active, $Inactive_count inactive)|active=$ACT_COUNT;69999;99999;0; inactive=$Inactive_count;69999;99999;0;\"
    exit 0
fi

2.2 nrpe.cfg里面配置如下

Vim /etc/nagios/nrpe.cfg,在里面添加一行check_lvs命令:

command[check_lvs]=/usr/lib/nagios/plugins/check_lvs -w 300 -c 600 

之后重启nrpe

[[email protected]/root/nagios/check_lvs ~]# service nrpe restart;
Shutting down nrpe:                                        [确定]
Starting nrpe:                                             [确定]
[[email protected]/root/nagios/check_lvs ~]#service nrpe restart;

2.3 去nagios服务端check一下


[[email protected] ~]#  /usr/local/nagios/libexec/check_nrpe -H 1x.xx4.x.x5 -c check_lvs
 lvs critical,lvs is down now.
[[email protected] ~]#

看到check出来lvs服务已经处于down模式。

说明:由于check_lvs是要调用ipvsadm命令来获取LVS状态的,而ipvsadm命令是只能以root用户来运行的, 所以需要将nagios用户设置成可以无需密码直接su成root,这样就能以nagios用户运行命令sudo /usr/lib/nagios/plugins/check_lvs 。在centos系统中,无法直接调用sudo命令,需要修改/etc/sudoers, 找到 #Defaults requiretty 并取消注释,另外新增一行。表示nagios用户不需要登陆终端就可以调用命令,如下所示:

Defaults    requiretty
Defaults:nagios    !requiretty
#添加nagios 请求sudo,允许特定指令时(可跟参数),不需要密码(如)。
nagios ALL=(ALL) NOPASSWD: ALL

再去naigos服务器上面check下,已经生效,如下所示:

[[email protected] etc]# /usr/local/nagios/libexec/check_nrpe -H 10.xx.xx.xx -c check_lvs
LVS OK - LVS is running (conn: 16 active, 77 inactive)|active=16;69999;99999;0; inactive=77;69999;99999;0;
[[email protected] etc]#

2.4 在nagios服务器上添加配置

vim services.cfg
define service{
        host_name               lvs-lan
        service_description     Check lvs
        check_command           check_nrpe!check_lvs
        max_check_attempts      5
        normal_check_interval   3
        retry_check_interval    2
        check_period            24x7
        notification_interval   10
        notification_period     24x7
        notification_options    w,c,r
        contact_groups          opsweb
        }
vim objects/commands.cfg
define command{
        command_name    check_lvs
        command_line    $USER1$/check_lvs -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$
        }

之后重新加载nagios既完成了对lvs的监控服务。

[[email protected] etc]# service nagios reload
Running configuration check...
Reloading nagios configuration...
done
[[email protected] etc]#

至此,nagios下面对lvs服务的监控已经完成。

参考资料:http://c20031776.blog.163.com/blog/static/684716252013627506890/

Nagios监控lvs服务

时间: 2024-07-31 11:37:07

Nagios监控lvs服务的相关文章

Nagios监控Memcached服务

说到Memcached服务,其实作为运维人员用的还是很多的: 1.在做LB的时候,为了保证同一台机器的请求的session信息防止丢失,我们用Memcached对session做分布式存储. 2.做mysql缓存的时候,我们常常吧mysql查询的结果缓存到Memcached中,这样能够较少php程序与mysql的交互,也能大大减轻数据库的压力. 从以上来看,Memcached其实也是蛮重要的,那么我们更有必要对其进行时刻的监控,接下来引入正题 Nagios监控Memcached服务是否正常运行.

Nagios监控nginx服务详细过程

1在nginx 服务器上安装nrpe客户端: Nginx的服务需要监控起来,不然万一down了而不及时修复,会影响web应用,如下web应用上面启动的nginx后台进程[[email protected] ~]# ps aux|grep nginxnobody   15294  0.0  0.0  22432  3464 ?        S    Jul03   0:05 nginx: worker process      nobody   15295  0.0  0.0  22432  3

Nagios监控nginx服务具体过程

1在nginx 服务器上安装nrpe客户端: Nginx的服务须要监控起来.不然万一down了而不及时修复,会影响web应用.例如以下web应用上面启动的nginx后台进程[[email protected] ~]# ps aux|grep nginxnobody   15294  0.0  0.0  22432  3464 ?        S    Jul03   0:05 nginx: worker process      nobody   15295  0.0  0.0  22432

Nagios 监控 http 服务

[[email protected] ~]# vim /usr/local/nagios/etc/objects/services.cfg# 在末尾添加 define service { use generic-service host_name web01 service_description HTTP URL check_command check_http } [[email protected] ~]# echo "192.168.123.102 www.abc.com" &

nagios监控服务

   nagios监控系统 1: ngios工作原理 1.Nagios的功能是监控服务和主机,但是他自身并不包括这部分功能,所有的监控.检测功能都是通过各种插件来完成的. 启动Nagios后,它会周期性的自动调用插件去检测服务器状态,同时Nagios会维持一个队列,所有插件返回来的状态信息都进入队列,Nagios每次都从队首开始读取信息,并进行处理后,把状态结果通过web显示出来. Nagios提供了许多插件,利用这些插件可以方便的监控很多服务状态.安装完成后,在nagios主目录下的/libe

python根据nagios配置文件将监控的服务联系人等信息导出到excel表格

前阵子,遇到需要把nagios监控的服务统计到表格的需求,想着如果每一次改动,都要去维护表格的话,难免会有疏漏或者问题,于是观察了nagios的host.cfg,services.cfg等配置文件写了一个脚本,包含对多个主机关联到同一个服务的处理等,脚本也有局限性,就是需要把每个主机,都归类到某个组,比如Linux主机归类到Linux组,实际环境,一般也是有这样做归类的,脚本运行过程中会有文件产生,但都很小,以下是相应模块安装和脚本文件,建议在测试机上面跑完再到实际环境跑. 一,安装xlsxwr

Nagios监控服务的搭建

Nagios是一款开源的电脑系统和网络监视工具,能有效监控Windows.Linux和Unix的主机状态,交换机路由器等网络设置,打印机等. 主要功能 网络服务监控(SMTP.POP3.HTTP.NNTP.ICMP.SNMP.FTP.SSH) 主机资源监控(CPU load.disk usage.system logs),也包括Windows主机(使用NSClient++ plugin) 可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度.警告--) 可以通过配置Nagios远程

Nagios监控系统主机与服务配置

配置环境: 监控服务器 :192.168.189.132 被监控客户端:192.168.189.131(linux) 192.168.1.152(windows) Nagios相关配置文件概述: # cd /usr/local/nagios/etc/   相关文件用途如下表: 文件名或目录名 用途 cgi.cfg 控制CGI访问的配置文件 nagios.cfg Nagios 主配置文件 resource.cfg 变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USE

Nagios监控mongodb分片集群服务实战

1,监控插件下载 Mongodb插件下载地址为:git clone git://github.com/mzupan/nagios-plugin-mongodb.git,刚开始本人这里没有安装gitpub环境,找网友草根帮忙下载的,之后上传到了csdn资源页面,新的下载地址为:http://download.csdn.net/detail/mchdba/8019077 2,添加新的mongodb监控命令 因为mongodb服务是和mysql从库公用一台物理机,之前已经做了基础nagios以及mys