nagios

本文涉及的产品
云数据库 RDS MySQL Serverless,0.5-2RCU 50GB
简介:

一、简介

Nagios是一款开源的免费网络监视工具,能有效监控Windows、Linux和Unix的主机状态,交换机路由器等网络设置,打印机等。在系统或服务状态异常时发出邮件或短信报警第一时间通知网站运维人员,在状态恢复后发出正常的邮件或短信通知。


二、组成(插件模式)

1、主程序nagios,core,提供平台,不做任何监测工作,具体监测工作由插件完成。

2、主插件nagios-plugins

3、四个可选的插件NRPE、NSCA、NSCLIENT++、NDOUTILS,snmp

NSCLIENT++(snmp):用来监控windows主机,需要安装在windows主机上。

NDOUtils++:用来将nagios的配置信息和event产生的数据存入数据库,并实现数据检索。

NRPE:监控linux/unix主机,客户端同样需要安装nagios-plugins插件,而服务器端则需要安装nrpe。

NSCA:用来让被监控的主机(linux)主动的发送监控信息到nagios上。(复杂没讲解)

285666.tmp

661492.tmp

状态信号:ok、warning、critical、unknown

依据不同的数值区间定义报警信号,并简便的显示监测结果。


三、监控对象

1、主机、主机组

2、服务、资源、服务组

3、联系人

4、时段

5、命令(模板-》应用到某个被监控对象上,实现具体的监控)


模板:将多个需要使用相同监控定义的对象,制成一个可以自由使用的框架。


四、nagios监控依赖关系


监控依赖关系是什么?

其实就是被监控设备之间存在着某种联系,比如交换机和下联的主机、文件服务器和终端等等。在对存在依赖关系的设置进行同时监控的时候,可能会由于其中一个设备故障造成另一个设备无法访问、无法提供服务的情况。就是依赖关系。


如何处理依赖关系的设备呢?

    对于存在依赖关系的设备,建议在主设备(被依赖设备)出现问题时,关闭受其有影响的依赖设备监控。


监控通知:

    通常情况下,监控对象在一种状态变化到另一种状态需要经过一个时间周期,或者频次周期才到达发送阈值,同样对于flapping状态(状态间的反复)也是有触发阈值的。


五、nagios安装

通常安装服务器端很简单,主要安装nagios主程序及nagios plugins即可。

如果要监控使用namp协议的设备(路由交换设备、打印)不需要再额外安装插件。

如果是监控linux设备,服务器端、客户端需要安装NRPE、nagios plugins插件。

如果监控windows设备,客户端安装nsclient++插件即可。

如果是linux设备使用send-nsca功能,需要服务器端开启nsca功能。


1、安装依赖的软件包(安装过程中的很多参数不可以修改,比如组,账户)

yum install httpd php php-devel php-mysql mysql mysql-devel mysql-server

2、创建工作组和用户(用户要在/bin/bash环境)

[root@localhost ~]# groupadd nagcmd

[root@localhost ~]# useradd -G nagcmd nagios

useradd: user 'nagios' already exists

[root@localhost ~]# usermod -G nagcmd nagios

[root@localhost ~]# id nagios

uid=501(nagios) gid=501(nagios) 组=501(nagios),502(nagcmd)


将apache的用户也加入到nagcmd组,以便于在通过web interface操作nagios时有足够的权限。

[root@node6.dtedu.com /var/www/html/cacti]# usermod -a -G nagcmd apache


3、下载编译nagios和nagios plugins

官网下载地址:https://www.nagios.org,此次使用的版本是nagios-xi-5.4.6(此版本收费)和nagios-plugins-2.2.1

安装xi.5.4.6,解压缩源码并进入安装目录。

[root@node7.dtedu.com /nagiossxi-5.4.6]# ./fullinstall

以下是教程安装老版本:

编译nagios-core-4.3.2:

./configure  --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker

make all

make install

make install-init

make install-commandmode

make install-config


解释:--enable-event-broker是为NDOUtiles++做准备。

4、为email指定接收告警信息的邮件地址


5、在http的配置文件目录(conf.d)中创建nagios的web程序配置文件

[root@localhost nagios]# make install-webconf

/usr/bin/install -c -m 644 sample-config/httpd.conf /etc/httpd/conf.d/nagios.conf


*** Nagios/Apache conf file installed ***




6、创建用户登录web程序的账户信息。

[root@localhost nagios]# htpasswd -c /etc/htpasswd.users nagiosadmin

New password: 

Re-type new password: 

Adding password for user nagiosadmin


7、设置开机启动服务

[root@localhost nagios]# chkconfig --add nagios

[root@localhost nagios]# chkconfig --level 35 nagios on

[root@localhost nagios]# chkconfig --list nagios

nagios          0:关闭 1:关闭 2:关闭 3:启用 4:启用 5:启用 6:关闭


8、安装nagios-plugins-2.2.1插件,如果要监控mysql,需要加载—with-mysql选项。

[root@localhost nagios-plugins-2.1.1]# ./configure --with-nagios-user=nagios --with-nagios-group=nagios

[root@localhost nagios-plugins-2.1.1]# make && make install


9、默认情况下selinux是拒绝nags web cgi程序的。需要关闭或者关闭拒绝。

方法一、编辑/etc/sysconfig/selinux,将force改为disable即可。

方法二、放行nagios服务

[root@localhost nagios-plugins-2.1.1]# chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin          

[root@localhost nagios-plugins-2.1.1]# chcon -R -t httpd_sys_content_t /usr/local/nagios/share


问题分析:

通过htpasswd创建完登录认证文件,但是登录时总是提示错误,信息如下:

590912.tmp

问题原因:检查httpd服务关于nagios.cfg的配置文件信息。位置通常在/etc/httpd/conf.d/nagios.cfg。修改授权认证文件位置。

<Directory "/usr/local/nagios/sbin">

#  SSLRequireSSL

   Options ExecCGI

   AllowOverride None

   <IfVersion >= 2.3>

      <RequireAll>

         Require all granted

#        Require host 127.0.0.1


         AuthName "Nagios Access"

         AuthType Basic

         AuthUserFile /etc/htpasswd.users //检查此路径和htpasswd设置的路径是否一致。

         Require valid-user

      </RequireAll>

   </IfVersion>

   <IfVersion < 2.3>

      Order allow,deny

      Allow from all

#     Order deny,allow

#     Deny from all

#     Allow from 127.0.0.1


      AuthName "Nagios Access"

      AuthType Basic

      AuthUserFile /etc/htpasswd.users

      Require valid-user

   </IfVersion>

</Directory>



六、定义监控对象


监控对象配置文件在安装目录下的object文件夹中:

[root@localhost ~]# cd /etc/nagios/

[root@localhost nagios]# ls

cgi.cfg  htpasswd.users  nagios.cfg  objects  resource.cfg

[root@localhost nagios]# cd objects/

[root@localhost objects]# ll

总用量 48

-rw-rw-r--. 1 nagios nagios  7716 6月   7 10:24 commands.cfg

-rw-rw-r--. 1 nagios nagios  2166 6月   7 10:24 contacts.cfg

-rw-rw-r--. 1 nagios nagios  5403 6月   7 10:24 localhost.cfg

-rw-rw-r--. 1 nagios nagios  3124 6月   7 10:24 printer.cfg

-rw-rw-r--. 1 nagios nagios  3293 6月   7 10:24 switch.cfg

-rw-rw-r--. 1 nagios nagios 10812 6月   7 10:24 templates.cfg

-rw-rw-r--. 1 nagios nagios  3208 6月   7 10:24 timeperiods.cfg

-rw-rw-r--. 1 nagios nagios  4019 6月   7 10:24 windows.cfg


主配置文件:nagios.cfg

监控对象通过主配置文件来调用objects文件夹下的内容,或者可以自定义调用位置。

# You can specify individual object config files as shown below:

cfg_file=/etc/nagios/objects/commands.cfg


没有注释掉的内容表示可以被调用到并进行监控。也可以通过cfg_dir=的方式指定监控对象配置文件的位置。

#cfg_dir=/etc/nagios/servers

#cfg_dir=/etc/nagios/printers

#cfg_dir=/etc/nagios/switches

#cfg_dir=/etc/nagios/routers


resource_file指定的是nagios插件的位置,resource定义的是一个宏USER,实际上就是一个变量

resource_file=/etc/nagios/resource.cfg

resource.cfg定义的变量,这个user1不要随意更改,可以创建其他变量最大32个。

# Sets $USER1$ to be the path to the plugins

$USER1$=/usr/local/nagios/libexec



监控对象配置文件:objects文件夹下

1、command.cfg

define command{

command_name process-host-perfdata       ##自定义命令名称

command_line /usr/bin/printf "%b”         ##定义实际命令操作 "$LASTHOSTCHECK$\t$HOSTNAME$\t$HOSTSTATE$\t$HOSTATTEMPT$\t$HOSTSTATETYPE$\t$HOSTEXECUTIONTIME$\t$HOSTOUTPUT$\t$HOSTPERFDATA$\n" >> /usr/local/nagios/var/host-perfdata.out

}


2、contacts.cfg

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

3、.localhost.cfg

define service{

        use                             local-service         ; Name of service template to use

        host_name                       localhost //唯一

        service_description             HTTP //全机唯一

check_command check_http

notifications_enabled 0

        }



4、templates.cfg

define service{

name local-service  ; The name of this service template

use generic-service ; Inherit default values from the generic-service definition

        max_check_attempts              4 ; Re-check the service up to 4 times in order to determine its final (hard) state

        normal_check_interval           5 ; Check the service every 5 minutes under normal conditions

        retry_check_interval            1 ; Re-check the service every minute until a hard state can be determined

        register                        0        ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL SERVICE, JUST A TEMPLATE!

}


5、timeperiod .cfg

define timeperiod{

name us-holidays //名称唯一

        timeperiod_name         us-holidays

        alias                   U.S. Holidays


        january 1               00:00-00:00     ; New Years

        monday -1 may           00:00-00:00     ; Memorial Day (last Monday in May)

        july 4                  00:00-00:00     ; Independence Day

        monday 1 september      00:00-00:00     ; Labor Day (first Monday in September)

        thursday 4 november     00:00-00:00     ; Thanksgiving (4th Thursday in November)

        december 25             00:00-00:00     ; Christmas

        }



# This defines a modified "24x7" timeperiod that covers every day of the

# year, except for U.S. holidays (defined in the timeperiod above).

define timeperiod{

        timeperiod_name 24x7_sans_holidays

        alias           24x7 Sans Holidays


use us-holidays ; Get holiday exceptions from other timeperiod


        sunday          00:00-24:00

        monday          00:00-24:00

        tuesday         00:00-24:00

        wednesday       00:00-24:00

        thursday        00:00-24:00

        friday          00:00-24:00

        saturday        00:00-24:00

        }


这里简单说一下各个配置文件直接的关系,不同的配置文件依据文件名而有各自的功能,在配置文件内创建各个变量,类似一个个积木块,并且各个配置文件之间也会调用其他配置文件中的变量块来实现监控功能。


马哥培训nagios:http://edu.51cto.com/lesson/id-11467.html

七、配置

  实现nagios监控windows主机


监测方式可以基于nsclient++、nrpe、nsca、等方式进行监控,不同的协议服务器端使用的命令或插件也不同。

服务器端                     客户端

check_nt   ---------------nsclient++

check_nrpe--------------nsclient++ nrpe(nagios-plugins)

nsca deamon------------nsca

210186.tmp

1、check_nt通信模式:

1、安装nsclient++

503440.png

2、通过检查端口查看服务是否开启

12489对应客户端的nsclient++服务和服务器端的check_nt进行通信

5666是nsclient++同服务器端nrpe协议通信对应的端口


3、服务器端通过check_nt命令可以进行监控了(命令在/usr/local/nagios/libexec/目录下)!!!!!

[root@localhost libexec]# ./check_nt -H 10.40.0.208 -p 12489 -v UPTIME -s 123123

System Uptime - 0 day(s) 7 hour(s) 38 minute(s) |uptime=458


[root@node6.dtedu.com /usr/local/nagios/libexec]# ./check_nt -H 10.40.0.226 -p 12489 -v USERDDISKSPACE -w 80 -c 90 -l C


4、实现通过web访问界面查看监控对象信息的方法。

a、配置command.cfg文件,将监控中使用的命令写进去

define command {

        command_name check_nt

        command_line    $USER1$/check_nt -H $HOSTNAME$ -p 12489 -s 123123 -v $ARG1$ $ARG2$ 

}

b、配置windows.cfg文件,将监控对象的信息录入到host_name位置,同时录入相关的“服务”信息

define host{

use windows-server ; Inherit default values from a template

host_name dtedu ; The name we're giving to this host

alias My Windows Server ; A longer name associated with the host

address 10.40.0.225 ; IP address of the host

}

define hostgroup{

hostgroup_name windows-servers ; The name of the hostgroup

alias Windows Servers ; Long name of the group

}


c、编辑主配置文件nagios.cfg,并启用windows.cfg文件

# Definitions for monitoring a Windows machine

cfg_file=/etc/nagios/objects/windows.cfg



5、检查配置文件语法错误

[root@localhost libexec]# /usr/local/nagios/bin/nagios -v /etc/nagios//nagios.cfg 


Nagios Core 3.4.3

Copyright (c) 2009-2011 Nagios Core Development Team and Community Contributors

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 11-30-2012

License: GPL


Website: http://www.nagios.org

Reading configuration data...

   Read main config file okay...

Processing object config file '/etc/nagios/objects/commands.cfg'...

Processing object config file '/etc/nagios/objects/contacts.cfg'...

Processing object config file '/etc/nagios/objects/timeperiods.cfg'...

Processing object config file '/etc/nagios/objects/templates.cfg'...

Processing object config file '/etc/nagios/objects/localhost.cfg'...

   Read object config files okay...


Running pre-flight check on configuration data...


Checking services...

Checked 8 services.

Checking hosts...

Checked 1 hosts.

Checking host groups...

Checked 1 host groups.

Checking service groups...

Checked 0 service groups.

Checking contacts...

Checked 1 contacts.

Checking contact groups...

Checked 1 contact groups.

Checking service escalations...

Checked 0 service escalations.

Checking service dependencies...

Checked 0 service dependencies.

Checking host escalations...

Checked 0 host escalations.

Checking host dependencies...

Checked 0 host dependencies.

Checking commands...

Checked 24 commands.

Checking time periods...

Checked 5 time periods.

Checking for circular paths between hosts...

Checking for circular host and service dependencies...

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...


Total Warnings: 0

Total Errors:   0


2、check_nrpe通信模式(linux系统)

要求:服务器端安装nrpe插件、客户端安装nagios-plugins、nsclient++、nrpe插件。


NRPE是用于在远端服务器上运行检测命令的守护进程,他用于让nagios监控端基于安装的方式触发远端主机上的检测命令。并将结果输出到监控端,而其执行的开销远低于ssh的检测方式,而且检测过程并不需要远程主机上的账户信息。



1、安装并配置被监控端

a、确保开发包组已经安装,“development tools” “development libraries”

b、创建nagios用户。

BingGongtekiMacBook-Pro:~ binggong$ useradd -s /sbin/nologin nagios


c、安装nagios-plugins。

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nagios-user=nagios --with-nagios-group=nagios

BingGongtekiMacBook-Pro:~ binggong$ make  all && make install


d、安装nrpe插件 https://sourceforge.net/projects/nagios/files/

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl && make all && make install-plugin && make install-daemon && make install-daemon-config —sysconfdir=/etc


e、编辑配置文件,位置通常在/usr/local/nagios/etc/nrpe.cfg,我测试的版本nrpe-2.15需要将server_address=127.0.0.1注释掉并重启。

f、nagios-3.4.3.tar.gznagios-plugins-2.1.1.tar.gznagios-4.1.1.tar.gznrpe-2.15.tar.gz


g、设置开机启动和service启动方式配置启动方案,可以通过创建/etc/init.d/目录下的配置文件完成一个独立的守护进程的方式,也可以通过基于xinetd的非独立守护进程方式。

手动方式(以守护进程方式启动):

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



非独立(在xinetd目录下创建nrpe文件,使其成为一个基于非独立守护进程的服务,此情况启动服务需要重启xinetd服务):


[root@localhost bin]# vi /etc/xinetd.d/nrpe 


service nrpe

{

        flags = reuse

        socket_type = stream

        vait = no

        user = nagios

        group = nagios

        server = /opt/nagios/nrpe.cfg -l

        log_on_failure += USERID

        disable = no

}


独立方式(在init.d目录下创建启动脚本实现独立启动一个单独的服务进程):

[root@localhost bin]# chkconfig --add nrpe

[root@localhost bin]# chkconfig --level 35 nrpe on

[root@localhost bin]# chkconfig --list nrpe

nrpe            0:关闭 1:关闭 2:启用 3:启用 4:启用 5:启用 6:关闭


#!/bin/bash

#chkconfig: 2345 88 12

#description:nrpe daemon


NRPE=/usr/local/nagios/bin/nrpe

NRPECONF=/usr/local/nagios/etc/nrpe.cfg


case "$1" in

        start)

                echo -n "Starting NREP daemon"

                $NRPE -c $NRPECONF -d

                echo "done"

                ;;

        stop)

                echo -n "stopping NRPE DAEMON"

                pkill -u nagios nrpe

                echo "done"

                ;;

        restart)

                $0 stop

                sleep 2

                $0 start

                ;;

exit 0



3、check_nrpe通信模式(windows系统)

同样需要安装nsclients++插件,并且需要配置c:/program file/nsclients++/nsclient-full.ini。

讲解:http://edu.51cto.com/lesson/id-11472.html


2、服务器端设置

a、安装nrpe,配置同客户端。

BingGongtekiMacBook-Pro:~ binggong$ ./configure --with-nrpe-user=nagios --with-nrpe-group=nagios --with-nagios-user=nagios --with-nagios-group=nagios --enable-command-args --enable-ssl && make all && make install-plugin 


b、

c、安装完毕后默认在/usr/local/nagios/libexec/目录下生成check_nrpe命令。

d、检测客户端连通性

[root@5 libexec]# ./check_nrpe -H 10.40.0.57

NRPE v2.15


e、配置文件视频http://edu.51cto.com/lesson/id-11471.html

在comand.cfg中添加一条check_nrpe命令

define command{

        command_name check_nrpe

        command_line $USER1$/check_nrpe -H $HOSTNAME$ -c $ARG1$

        }


创建一个新的主机配置文件10.40.0.226.cfg

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_users

        check_command           check_nrpe!check_users

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     load

        check_command           check_nrpe!check_load

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_hda

        check_command           check_nrpe!check_hda1

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_zombie——procs

        check_command           check_nrpe!check_zombie_procs

        }

define service{

        use                     generic-service

        host_name               linux001

        service_description     CHECK_total-procs

        check_command           check_nrpe!check_total_procs

        }

其中的check_users要同客户端的配置对于。

command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10

command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20

command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1

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 150 -c 200 


将主机配置文件添加到nagios.cfg文件中(服务器端)

# You can specify individual object config files as shown below:

cfg_file=/etc/nagios/objects/commands.cfg

cfg_file=/etc/nagios/objects/contacts.cfg

cfg_file=/etc/nagios/objects/timeperiods.cfg

cfg_file=/etc/nagios/objects/templates.cfg

cfg_file=/etc/nagios/objects/10.40.0.226.cfg


# Definitions for monitoring the local (Linux) host

cfg_file=/etc/nagios/objects/localhost.cfg


监控http服务启动状态。check_http

监控mysql服务启动状态,check_mysql -u $arg1$ -p $arg2$

错误总结:

[root@node6.dtedu.com ~]#  /usr/local/nagios/libexec/check_mysql -H 10.40.0.227 -u root -p root

/usr/local/nagios/libexec/check_mysql: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory


安装libmysqlclient.so.18文件。(未成功)

下载位置:https://altlinux.pkgs.org/sisyphus/classic-i586/libmysqlclient18-10.1.23-alt1.S1.i586.rpm.html

4、NSCA方式被动监测:

1、需要在服务器端的“服务”脚本中添加以下选项:

define host{

active_check_enabled 0

passive_checks_enabled 1

}

define service{

active_check_enabled 0

passive_checks_enabled 1

}

2、服务器端的需要启动nsca的服务

3、需要设置“模板”脚本

相关网页:http://os.51cto.com/art/201409/452605.htm

nagios插件下载地址:http://exchange.nagios.org/

nagios在线中文帮助文档:http://nagios-cn.sourceforge.net/nagios-cn/


八、告警通知机制

nagios告警通知的配置涉及到模板、服务、contact脚本,总的来说,他们之间是由关联的而关联的最终结果是在contact.cfg文件上。contact.cfg文件中定义的admins,最终会在服务、模板脚本中使用,所以,只要在contact中定义通知邮箱或飞信即可完成通知功能。


define contact{

        contact_name                    nagiosadmin             ; Short name of user

        use                             generic-contact         ; Inherit default values from generic-contact template (defined above)

        alias                           Nagios Admin            ; Full name of user


        email                           nagios@localhost        ; <<***** CHANGE THIS TO YOUR EMAIL ADDRESS ******

        }

define contactgroup{

        contactgroup_name       admins

        alias                   Nagios Administrators

        members                 nagiosadmin

        }

~                  


define contact{

        name                            generic-contact         ; The name of this contact template

        service_notification_period     24x7                    ; service notifications can be sent anytime

        host_notification_period        24x7                    ; host notifications can be sent anytime

        service_notification_options    w,u,c,r,f,s             ; send notifications for all service states, flapping events, and scheduled downtime events

        host_notification_options       d,u,r,f,s               ; send notifications for all host states, flapping events, and scheduled downtime events

        service_notification_commands   notify-service-by-email ; send service notifications via email

        host_notification_commands      notify-host-by-email    ; send host notifications via email

        register                        0                       ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL CONTACT, JUST A TEMPLATE!

        }

define host{

        name                            linux-server    ; The name of this host template

        use                             generic-host    ; This template inherits other values from the generic-host template

        check_period                    24x7            ; By default, Linux hosts are checked round the clock

        check_interval                  5               ; Actively check the host every 5 minutes

        retry_interval                  1               ; Schedule host check retries at 1 minute intervals

        max_check_attempts              10              ; Check each Linux host 10 times (max)

        check_command                   check-host-alive ; Default command to check Linux hosts

        notification_period             workhours       ; Linux admins hate to be woken up, so we only notify during the day

                                                        ; Note that the notification_period variable is being overridden from

                                                        ; the value that is inherited from the generic-host template!

        notification_interval           120             ; Resend notifications every 2 hours

        notification_options            d,u,r           ; Only send notifications for specific host states

        contact_groups                  admins          ; Notifications get sent to the admins by default

        register                        0               ; DONT REGISTER THIS DEFINITION - ITS NOT A REAL HOST, JUST A TEMPLATE!


        }


define command{

        command_name    notify-host-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\nHost: $HOSTNAME$\nState: $HOSTSTATE$\nAddress: $HOSTADDRESS$\nInfo: $HOSTOUTPUT$\n\nDate/Time: $LONGDATETIME$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Host Alert: $HOSTNAME$ is $HOSTSTATE$ **" $CONTACTEMAIL$

        }


# 'notify-service-by-email' command definition

define command{

        command_name    notify-service-by-email

        command_line    /usr/bin/printf "%b" "***** Nagios *****\n\nNotification Type: $NOTIFICATIONTYPE$\n\nService: $SERVICEDESC$\nHost: $HOSTALIAS$\nAddress: $HOSTADDRESS$\nState: $SERVICESTATE$\n\nDate/Time: $LONGDATETIME$\n\nAdditional Info:\n\n$SERVICEOUTPUT$\n" | /bin/mail -s "** $NOTIFICATIONTYPE$ Service Alert: $HOSTALIAS$/$SERVICEDESC$ is $SERVICESTATE$ **" $CONTACTEMAIL$

        }

飞信通知方式可以下载飞信机器人,这里就不再讲解了。


九、常见问题:


1、服务器连接不上被监控端,比如telnet 10.40.0.37 5666 被拒绝。

处理办法:查看netstat -tunlp 发现5666端口的ip地址对应的是本机127.0.0.1。

tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      2946/nrpe           

所以只允许本地监控、访问。解决方法

    就是把nrpe.cfg里面的

server_address=127.0.0.1
注释掉,重启就可以


2、nagios基本流程是什么

创建主机的配置文件,一个主机一个配置文件,然后将主机配置文件路径添加到nagios.cfg文件中。

通过命令配置文件修改对应主机配置文件中的service模块。




本文转自 blackstome 51CTO博客,原文链接:http://blog.51cto.com/137783/1968809,如需转载请自行联系原作者

相关实践学习
基于CentOS快速搭建LAMP环境
本教程介绍如何搭建LAMP环境,其中LAMP分别代表Linux、Apache、MySQL和PHP。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
相关文章
|
Web App开发 开发工具 机器学习/深度学习
|
JavaScript 前端开发
|
监控 Windows
|
监控 Apache
|
监控 Linux Apache
|
监控 网络协议 测试技术
|
监控 Linux 调度