nagios部署监控多台client

添加client节点node

####添加一台client:新加入的是一台开启了防火墙的阿里云服务器linux

首先搭建client环境ios

#监控Linux、Unix主机,安装客户端git

添加nagios用户github

useradd -m nagios -s /sbin/nologinweb

#安装插件nagios-plugins
vim

cd /home/huang/tools/服务器

wget http://www.nagios-plugins.org/download/nagios-plugins-2.1.1.tar.gzssh

tar xfz nagios-plugins-2.1.1.tar.gztcp

cd nagios-plugins-2.1.1

./configure --with-nagios-user=nagios --with-nagios-group=nagios --prefix=/usr/local/nagios

make

make install

chown -R nagios.nagios /usr/local/nagios/

#安装NRPE

cd /home/huang/tools/

wget https://github.com/NagiosEnterprises/nrpe/archive/3.0.tar.gz

tar xf 3.0.tar.gz

cd nrpe-3.0/

./configure

make all

make install

make install-plugin

make install-daemon

make install-config

#修改配置文件,添加nagios主机

sed -i 's#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,192.168.1.155#g' /usr/local/nagios/etc/nrpe.cfg


##编辑hosts.cfg配置文件,添加阿里云服务器的信息

vim ../objects/hosts.cfg

一、define host{

        use                     linux-server          

        host_name               client01

        alias                   client01

        address                 120.26.68.152

        }

二、加入组

define hostgroup{

        hostgroup_name  linux-servers 

        alias           Linux Servers 

        members         nagios_server,client01(client01新加入的)   

        }

三、定义主动模式(不须要nrpe服务)   此时是主动拉取数据,因此并无用到nrpe,也就是不使用check_nrpe,也不须要在客户端开启nrpe服务

cd /usr/local/nagios/etc/

mkdir services

chown -R nagios.nagios services

cd services

vim port-client.cfg(nagios服务的services目录下)

define service{

        use     generic-service

        host_name       client01

        service_description     ntp_port

        check_period 24x7

        check_interval 5

        retry_interval 1

        max_check_attempts 3

        check_command      check_http!-p 123

        notification_period 24x7

        notification_interval 30

        notification_options  w,u,c,r

        contact_groups admins

}

三、手动测试数据是否有收集

[root@RS1 services]# /usr/local/nagios/libexec/check_tcp -H 120.26.68.152 -p 123

CRITICAL - Socket timeout after 10 seconds

报错如上

解决办法:防火墙的123端口没有向外开放(因为不想开放这个端口,因此不理会这个报错,从新监控其余端口)

这里选择监控sshd服务的端口22389

当监控sshd的端口22389

[root@RS1 services]# /usr/local/nagios/libexec/check_tcp -H 120.26.68.152 -p 22389

TCP OK - 0.092 second response time on 120.26.68.152 port 22389|time=0.092055s;;;0.000000;10.000000

修改配置文件的123端口为22389

重启检测语法以及重启服务,在web页面观察到以下错误:

check_tcp: Port must be a positive integer

手动可以收集数据,可是nagios的web界面报错:check_tcp: Port must be a positive integer


解决办法:修改service配置文件:

check_command      check_tcp!22389(不须要加-p了)


#####主动模式小结

通常客户端对外开启的服务,用主动模式监控,例如:port,uri

主动模式的监控配置过程:

一、在服务端的命令行把要监控的命令先调试好

二、在commands.cfg里定义好命令,同时调用命令行的插件,先手动收集一下数据

三、在服务的配置文件里定义要监控的服务,调用commands.cfg里定义的监控命令


建立第二台client服务器,ip为192.168.1.11

首先仍是搭建nrpe环境,这里省略

此次选择客户端被动模式收集数据

在client02上操做

[root@node2 ~]# /usr/local/nagios/libexec/check_tcp -H 192.168.1.11 -p 80

TCP OK - 0.001 second response time on 192.168.1.11 port 80|time=0.000810s;;;0.000000;10.000000

手动抓取数据正常,因而配置服务器端:

define service{

        use                     generic-service

        host_name               client02   ----》已经定义了hosts文件(192.168.1.11为client02)

        service_description     web_port

        check_command           check_nrpe!check_tcp 

}

而后重启服务,出现以下错误:

NRPE: Command 'check_tcp' not defined 


解决办法:这是由于客户端配置文件nrpe.cfg并无定义check_tcp这个命令,编辑配置文件,添加下面一行:

command[check_tcp]=/usr/local/nagios/libexec/check_tcp -H 192.168.1.11 -p 80


而后在服务端进行手动测试抓取数据:

[root@RS1 etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.11 -c check_tcp

TCP OK - 0.001 second response time on 192.168.1.11 port 80|time=0.000670s;;;0.000000;10.000000

成功解决

而后被动模式成功

wKiom1e-54OSs625AACuhXzo46g138.jpg


#########对每一个服务进行分组(好几台服务器监控的服务都是load负载)

新建:vim /usr/local/nagios/etc/services/servicegroup.cfg

define servicegroup{

        servicegroup_name  load    ----》这里对应service配置文件的service_description

        alias           Linux Servers 

        members         nagios_server,load,client01,load,client02,load 

        }

将三个主机(nagios_server、client0一、client02)的监控的load服务定义到一个服务组中,

修改server.cfg中的description以下:

vim ../objects/services.cfg

define service{

        use                     generic-service

        host_name               nagios_server    因为这里只定义了一个主机,因此仍是显示了一个

        service_description     load      -----》这里改为和服务组定义的名称一致

        check_command           check_nrpe!check_load

}

wKioL1e-50OSqPt2AABUJqHJxAg678.jpg


#####模板选择与修改

编辑的services.cfg

define service{

        use     generic-service      ----》这里使用的是generic-service这个模板,在配置文件templates.cfg中有定义,本身能够在模板中定义一个别的service模板,而后这里修改就行

        host_name       client01

        service_description     ntp_port

        check_period 24x7

        check_interval 5

        retry_interval 1

        max_check_attempts 3

        check_command      check_http!22389

        notification_period 24x7

        notification_interval 30

        notification_options  w,u,c,r

        contact_groups admins

}    ----》后面这些和模板中相同的参数配置均可以省略掉,由于和模板配置文件同样,恰好就调用了模板文件

模板定义:vim templates.cfg

define service{

        name                            generic-service        这个名词能够修改的

        active_checks_enabled           1                       

        passive_checks_enabled          1                       

        parallelize_check               1                       

        obsess_over_service             1                       

        check_freshness                 0                       

        notifications_enabled           1                       

        event_handler_enabled           1                       

        flap_detection_enabled          1                       

        process_perf_data               1                       

        retain_status_information       1                       

        retain_nonstatus_information    1                       

        is_volatile                     0                       

        check_period                    24x7                    

        max_check_attempts              3                       

        normal_check_interval           10          这个能够稍微改小一点              

        retry_check_interval            2                       

        contact_groups                  admins                 

        notification_options            w,u,c,r        warning unknown critical recovery            

        notification_interval           60                      

        notification_period             24x7                    

         register                        0                     

        }


########定义分组报警

vim contacts.cfg

如下是默认联系人

define contact{

        contact_name                    nagiosadmin            

        use                             generic-contact         

        alias                           Nagios Admin           

        email                           nagios@localhost       

        }


自定义联系人:

define contact{

        contact_name                    huang            

        use                             generic-contact         

        alias                           Nagios Admin           

        email                           123456@qq.com       

        }

define contact{        ---》联系中能够加入手机登设参数

        contact_name                    huangsir            

        use                             generic-contact      ---》这里使用的模板就是模板文件中的contact定义      

        alias                           Nagios Admin           

        email                           123456@139.com       

        }

将定义好的联系加到联系组中:

define contactgroup{   -----------》默认联系组

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }


新增联系组:

define contactgroup{

        contactgroup_name       sas

        alias                   Nagios Administrators

        members                 huang,huangsir

        }

而后修改模板中service的定义,将

contact_groups                  admins改成

contact_groups                  admins,sas  

提示:根据不一样的监控内容将报警设置分配不一样,这时候模板就能够删掉这个参数,依次在监控的内容中定义须要报警的组便可,以下:

define service{

        use                     generic-service

        host_name               nagios_server    

        service_description     load      

        check_command           check_nrpe!check_load

        contact_groups          admins,sas    ---》单独报警一个组也行,根据报警的重要性来分配

}


#######联系人的模板

vim templates.cfg

# Generic contact definition template - This is NOT a real contact, just a template!


define contact{

        name                            generic-contact         

        service_notification_period     24x7                    

        host_notification_period        24x7                    

        service_notification_options    w,u,c,r,f,s             

        host_notification_options       d,u,r,f,s               

        service_notification_commands   notify-service-by-email     这个命令在commands.cfg配置文件中有定义

        host_notification_commands      notify-host-by-email    

        register                        0                       

        }


vim  commands.cfg

定义了notify-service-by-email、notify-host-by-email这两个命令,若是要使用短信报警

这里就须要在后面用逗号隔开,再者是在commands配置文件中定义命令

新建菜鸟学习交流群:584498750

相关文章
相关标签/搜索