资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

nagios监控配置介绍(三)-创新互联

1.主动监控模式

创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站设计、成都网站制作、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的清江浦网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

监控客户端LNMP 网站服务

服务器端:

[root@nagios]#cd /usr/local/nagios/etc/objects

[root@nagios objects]# vi commands.cfg

#在最下面增加:

# 'check_weburl' command definition

define command{

    command_name   check_weburl

    command_line   $USER1$/check_http $ARG1$ -w 10 -c 30

    }

保存退出

[root@nagios objects]#cd /usr/local/nagios/etc/services

创建主动模式监控配置文件webzd.cfg

[root@nagios objects]#vi webzd.cfg

define service {

    use        generic-service

    host_name      1.34-web

    service_description   blog_ip

    check_command     check_weburl! -I 10.89.1.34

    max_check_attempts   3

    normal_check_interval  2

    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

}

define service {

    use        generic-service

    host_name      1.34-web

    service_description   blog_url

    check_command     check_http! -H bolg.etiantian.org

    max_check_attempts   3

    normal_check_interval  2

    retry_check_interval   1

    check_period     24x7

    notification_interval  30

    notification_period   24x7

    notification_options   w,u,c,r

    contact_groups     admins

}

define service {

    use        generic-service

    host_name      1.34-web

    service_description   blog_port_80

    check_command     check_tcp!80

    max_check_attempts   3

    normal_check_interval  2

    retry_check_interval   1

    check_period     24x7

    notification_interval  30

    notification_period   24x7

    notification_options  w,u,c,r

    contact_groups    admins

}

define service {

    use        generic-service

    host_name      1.34-web

    service_description   ssh_port

    check_command     check_tcp! 22

    max_check_attempts   3

    normal_check_interval  2

    retry_check_interval   1

    check_period     24x7

    notification_interval  30

    notification_period   24x7

    notification_options   w,u,c,r

    contact_groups     admins

}

define service {

    use        generic-service

    host_name      1.34-web

    service_description   mysql_port

    check_command     check_tcp!3306

    max_check_attempts   3

    normal_check_interval  2

    retry_check_interval   1

    check_period     24x7

    notification_interval  30

    notification_period   24x7

    notification_options   w,u,c,r

    contact_groups     admins

}

define service {

    use        generic-service

    host_name      1.34-web

    service_description   rsync

    check_command     check_tcp!873

    max_check_attempts   3

    normal_check_interval  2

    retry_check_interval  1

    check_period     24x7

    notification_interval  30

    notification_period   24x7

    notification_options   w,u,c,r

    contact_groups     admins

}

保存并退出

检查语法

[root@@nagios objects]# /etc/init.d/nagios checkconfig

没有错误的情况下:

[root@@nagios objects]# /etc/init.d/nagios reload

------------------------------------------------------------------

自定义插件:监控密码文件是否改变

客户端测试:

将/etc/passwd生成md5值

[root@weblnmp ~]# md5sum /etc/passwd

5e2ebd59c3ebb7bd3c4b09b0674ca746  /etc/passwd

保存到/etc/alvin.md5 (文件名随便取,存放的位置任意)

[root@weblnmp ~]# md5sum /etc/passwd >/etc/alvin.md5

分析md5值是否变化,没有变化显示"OK"

[root@weblnmp ~]# md5sum -c /etc/alvin.md5

/etc/passwd: OK

实战:

1.在客户端添加自定义脚本

cd /usr/local/nagios/libexec

cat check_passwd

#!/bin/bash

char=`md5sum -c /etc/alvin.md5 2>/dev/null|grep "OK"|wc -l`

if [ $char -eq 1 ];

then

  echo "passwd is ok"

  exit 0

else

  echo "passwd is changed"

  exit 2

fi

#添加执行的权限

[root@weblnmp libexec~]# chmod +x check_passwd

[root@weblnmp libexec~]# ll check_passwd

-rwxr-xr-x 1 root root 166 Jul 22 21:33 check_passwd

2.在客户端增加命令,并重启nrpe服务使之生效

[root@weblnmp libexec~]#vim /usr/local/nagios/etc/nrpe.cfg

添加check_passwd定义命令

command[check_passwd]=/usr/local/nagios/libexec/check_passwd

[root@weblnmp libexec~]#pkill nrpe

 #重新启动nrpe

[root@weblnmp libexec~]#/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

#查看是否启动了

[root@weblnmp libexec~]ps -ef|grep nrpe

nagios   64672    1  0 Dec22 ?     00:00:21 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

root    72255  72099  0 11:48 pts/0   00:00:00 grep nrpe

3.在服务端测试

[root@nagios services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd

passwd is ok

添加服务脚本

[root@nagios ~]#cd /usr/local/nagios/etc/objects/

[root@nagios objects]# vi services.cfg

#在后面添加

define service{

    use        generic-service

    host_name      1.34-web-lnmp

    service_description   check_passwd

    check_command     check_nrpe!check_passwd

}

检测语法并重新加载/etc/init.d/nagios checkconfig

没有错误的情况下:

[root@nagios objects]# /etc/init.d/nagios reload

4.改变性测试在客户端执行添加用户命令

[root@weblnmp ~]#useradd jack

服务端执行

[root@nagios services]# /usr/local/nagios/libexec/check_nrpe -H 10.89.1.34 -c check_passwd

passwd is changed

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


新闻名称:nagios监控配置介绍(三)-创新互联
分享链接:http://cdkjz.cn/article/cspieh.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220