nagios主动方式监控tcp服务web/syncd/mysql及url





cd /usr/local/nagios/libexec/

[root@node4 libexec]# ./check_tcp -H 192.168.8.40 -p 80

TCP OK - 0.010 second response time on port 80|time=0.010334s;;;0.000000;10.000000

[root@node4 libexec]# ./check_tcp -H 192.168.8.198 -p 8888

TCP OK - 0.002 second response time on port 8888|time=0.001964s;;;0.000000;10.000000





# ./check_tcp -H 192.168.8.198 -p 22  

TCP OK - 0.002 second response time on port 22|time=0.001633s;;;0.000000;10.000000





1.添加关于url链接的监控

①添加自定义的servies目录

cd /usr/local/nagios/etc/objects/

# mkdir services

[root@node4 objects]# chown -R nagios.nagios services

编辑/usr/local/nagios/etc/nagios.cfg文件

添加配置

cfg_dir=/usr/local/nagios/etc/objects/services

注:

作为别用增加一个services目录,优点很多,在目录下只要符合*.cfg就可以被nagios加载,使用脚本批量部署时非常方便的随机命名配置文件





②在services目录下添加:blog.cfg文件

文件内容可以参考/usr/local/nagios/etc/objects/templates.cfg文件的service部分





# cat services/blog.cfg 





define service{

        use                             generic-service

        host_name                       centossz008

        service_description             blog_url

        check_command                   check_weburl!-I 192.168.8.40

        check_period                    24x7                 

        max_check_attempts              3                      

        normal_check_interval           2                     

        retry_check_interval            1                     

        contact_groups                  admins 

        notification_period             24x7 

        notification_options            w,u,c,r                

        notification_interval           30                 

        }





③在commands.cfg添加关于checkweburl的命令

# 'check_weburl" command definition

define command{

        command_name    check_weburl

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

        }



检测语法service nagios checkconfig,重载nagios配置service nagios reload





2.对特殊url地址的监控

添加对blog.chinasoft.com的解析

/etc/hosts

192.168.8.40 blog.chinasoft.com





# curl -I http://blog.chinasoft.com

HTTP/1.1 200 OK

Date: Fri, 22 Jul 2016 01:55:44 GMT

Server: Apache/2.4.9 (Unix)

X-Powered-By: PHP/5.4.26

Content-Type: text/html





注意:类似/pma/index.php的这种uri需要添加双引号

define service{

        use                             generic-service

        host_name                       centossz008

        service_description             phpadmin_url

        check_command                   check_weburl!-H blog.chinasoft.com -u "/pma/index.php"

        check_period                    24x7

        max_check_attempts              3

        normal_check_interval           2

        retry_check_interval            1

        contact_groups                  admins

        notification_period             24x7

        notification_options            w,u,c,r

        notification_interval           30

        }





在客户机上执行破坏性操作,会提示错误

/web/a.com/htdocs/pma

# mv index.php index.php.bak





phpadmin_url

WARNING 07-22-2016 10:27:160d 0h 22m 2s3/3HTTP WARNING: HTTP/1.1 404 Not Found - 217 bytes in 0.006 second response
time 





3.对tcp服务的监控,可以通过监控端口实现





①对rsyncd服务监控

在客户端node3.chinasoft.com执行:

# touch /etc/rsyncd.conf

[root@node3 ~]# rsync --daemon

[root@node3 ~]# lsof -i :873

COMMAND   PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME

rsync   59285 root    4u  IPv4 237676      0t0  TCP *:rsync (LISTEN)

rsync   59285 root    5u  IPv6 237677      0t0  TCP *:rsync (LISTEN)





vim /usr/local/nagios/etc/objects/services/blog.cfg 





define service{

        use                             generic-service

        host_name                       node3.chinasoft.com

        service_description             sync_port

        check_command                   check_tcp!837

        check_period                    24x7

        max_check_attempts              3

        normal_check_interval           2

        retry_check_interval            1

        contact_groups                  admins

        notification_period             24x7

        notification_options            w,u,c,r

        notification_interval           30

        }





# ../../libexec/check_tcp -H 192.168.8.41 -p 873

TCP OK - 0.001 second response time on port 873|time=0.001093s;;;0.000000;10.000000





发现是定义的端口错误应该是873不是837:

check_command                   check_tcp!873





②对mysql的3306端口监控

vim /usr/local/nagios/etc/objects/services/blog.cfg 





define service{

        use                             generic-service

        host_name                       centossz008

        service_description             mysql_port

        check_command                   check_tcp!3306

        check_period                    24x7

        max_check_attempts              3

        normal_check_interval           2

        retry_check_interval            1

        contact_groups                  admins

        notification_period             24x7

        notification_options            w,u,c,r

        notification_interval           30

        }





4.被动方式监控web的80端口

在被监控端即192.168.8.40的nrpe.cfg中添加命令定义:

command[check_port_80]=/usr/local/nagios/libexec/check_tcp -H 192.168.8.40 -p 80 -w 6 -c 10

编辑主服务器的文件

vim /usr/local/nagios/etc/objects/services/blog.cfg





define service{

        use                             generic-service

        host_name                       centossz008

        service_description             blog_port_80_beidong

        check_command                   check_nrpe!80

        check_period                    24x7

        max_check_attempts              3

        normal_check_interval           2

        retry_check_interval            1

        contact_groups                  admins

        notification_period             24x7

        notification_options            w,u,c,r

        notification_interval           30

        }

发现报错:

排错:

服务端执行

# /usr/local/nagios/libexec/check_tcp -H 192.168.8.40 -p 80 -w 6 -c 10

TCP OK - 0.002 second response time on port 80|time=0.001845s;6.000000;10.000000;0.000000;10.000000

# /usr/local/nagios/libexec/check_nrpe -H 192.168.8.40 -c check_port_80

NRPE: Command 'check_port_80' not defined

原来是定义反了,需要在客户端的nrpe.cfg文件中定义check_port_80命令才OK

5.定义监控组,如监控所有机器的交换分区swap状态

cat /usr/local/nagios/etc/objects/services/servergroup.cfg





define servicegroup{

        servicegroup_name Swap Useage

        alias   Linux Servers

        members node3.chinasoft.com,Swap Useage,node4.chinasoft.com,Swap Useage,centossz008,Swap Useage

}





报错:

Error: Could not find a service matching host name 'node3.chinasoft.com' and description 'Swap Useage' (config file '/usr/local/nagios/etc/objects/services/servergroup.cfg', starting on line 1)





/usr/local/nagios/etc/objects/servie.cfg中没有定义check_swap或者描述description 'Swap Useage'不一致,如下图:

备注:

可以通过# tail /usr/local/nagios/var/nagios.log来定位错误

nagios系列(四)之nagios主动方式监控tcp常用的80/3306等端口监控web/syncd/mysql及url服务的更多相关文章

  1. nagios系列(八)之nagios通过nsclient监控windows主机

    nagios通过nsclient监控windows主机 1.下载NSClient -0.3.8-Win32.rar安装在需要被监控的windows主机中 可以设置密码,此处密码留空 2.通过在nagi ...

  2. nagios系列(三)之nagios被动监控模式之添加系统负载load、swap、磁盘iostat及memory内存监控详解

    环境: nagios server:192.168.8.42 host_name:node4.chinasoft.com nagios client:192.168.8.41 host_name:no ...

  3. nagios系列(五)之nagios图形显示的配置及自定义插件检测密码是否修改详解

    nagios图形显示的配置 在服务端安装相关软件 #1.图形显示管理的依赖库 yum install cairo pango zlib zlib-devel freetype freetype-dev ...

  4. 分布式监控系统Zabbix-完整安装记录 -添加端口监控

    对于进程和端口的监控,可以使用zabbix自带的key进行监控,只需要在server端维护就可以了,相比于nagios使用插件去监控的方式更为简单.下面简单介绍配置:监控端口zabbix监控端口使用如 ...

  5. nagios系列(六)之nagios实现对服务器cpu温度的监控

    1.安装硬件传感器监控软件sensors yum install -y lm_sensors* 2.运行sensors-detect进行传感器检测 ##一路回车即可 Do you want to ov ...

  6. nagios系列(二)之nagios客户端的安装及配置

    1.添加nagios用户 echo "------ step 1: add nagios user------" #create user group /usr/sbin/user ...

  7. docker系列四之docker镜像与容器的常用命令

    docker镜像与容器的常用命令 一.概述   docker的镜像于容器是docker中两个至关重要的概念,首先给各位读者解释一下笔者对于这两个概念的理解.镜像,我们从字面意思上看,镜子里成像,我们人 ...

  8. CEIWEI CommMonitor 串口监控精灵v11.0 串口过滤 串口监控

    CEIWEI CommMonitor   串行端口监控精灵是用于 RS232 / RS422 / RS485 端口监控的专业 强大的系统实用程序软件.CEIWEI  CommMonitor 监控显示, ...

  9. Zabbix设置自定义监控项之——监控tcp连接状态

    目录 一.用户自定义参数 二.配置 监控 TCP 连接状态 在实际监控中,除了官方自带的一些监控项,我们很多时候有一些定制化监控,比如特定的服务.TCP 连接状态等等,这时候就需要自定义监控项.自定义 ...

随机推荐

  1. 洛谷P1044 栈

    之前看这题还是一头雾水,现在看:啊啊啊lydnb! 思考了一段时间,发现可以用DP. 令f[i]表示有i辆车时的方案数. 我一开始考虑的是在后面加车,可是这样搞不出状态转移方程来. 然后我考虑从前面加 ...

  2. gradle下载的依赖包位置 及 修改

    gradle下载的依赖包位置 2018年08月01日 00:37:06 LuckyJiang-2019 阅读数:3569   Mac系统默认下载到: /Users/(用户名)/.gradle/cach ...

  3. python2.x到python3.x函数变化

    首先,python 3.x中urllib库和urilib2库合并成了urllib库. 其中urllib2.urlopen()变成了urllib.request.urlopen() urllib2.Re ...

  4. PowerDesigner使用(设置继承,实现)

    1.File—New Mode 2添加4个class,1个接口(基本的添加工具都在这里面) 3.class1的设置名字,设置方法 3.设置继承,实现 4.编辑class2,class3继承父类的属性. ...

  5. 学习windows编程 day1

    #include <windows.h> #include <strsafe.h> /* 任务:去掉标题栏和边框 */ //#define LineHeight 15 这是自己 ...

  6. HDU - 4370 0 or 1

    0 or 1 Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Subm ...

  7. cdqz2017-test10-rehearsal(CDQ分治&可持久化线段树&单调栈)

    题意: 给出n个三元组 e[i]=(si,ti,wi) 第i个三元组的价值为 Σ w[j] ,j 满足以下4个条件: 1.j<i 2.tj<ti 3.sj<si 4.不存在j< ...

  8. 基于802.11Fuzz技术的研究

    转自安全客 关于无线的Fuzz最开始接触了解时,国内基本毛线都搜不到.经过几个月的资料搜集和学习,将大约全网的fuzz资料整理翻译分析并读懂写下,就为填补国内空白,也希望无线爱好者能多多交流. 在各个 ...

  9. C++函数返回局部变量

    函数不能返回指向栈内存的指针 原因:返回值是拷贝值,局部变量的作用域为函数内部,函数执行结束,栈上的局部变量会销毁,内存释放. 可返回的局部变量: 1. 返回局部变量本身 int sum(int a, ...

  10. Pytorch中的squeeze()和unsqueeze()函数

    在numpy库中,经常会出现“秩为1的一维数组”(come from 吴恩达的深度学习,目前还没有搞清楚numpy中如此设计的意图).比如: 注意这里的a的shape是[3] ,既不是 [1,3] 也 ...