Nagios服务端安装的具体操作步骤

2021-04-09 11:13发布

6条回答
请叫我雷锋叔叔啊
1楼 · 2021-04-09 20:47.采纳回答


一、安装前的准备

1.下载到核心源码:

wget http://sourceforge.net/projects/nagios/files/nagios-3.x/nagios-3.4.3/nagios-3.4.3.tar.gz/download 

2.下载插件包:

[root@gjp ~]# wget http://nchc.dl.sourceforge.net/project/nagiosplug/nagiosplug/1.4.16/nagios-plugins-1.4.16.tar.gz

3. nagios服务器端软件和客户端软件

[root@gjp ~]# wget http://nchc.dl.sourceforge.net/project/nagios/nrpe-2.x/nrpe-2.13/nrpe-2.13.tar.gz

4.源码安装前需要先确定 已经安装 apache,gcc,GD库和开发库


我本地DVD上没有gd-devel,所以我又加一一个163的镜像源 
yum install -y httpd php gcc glibc glibc-common gd gd-devel perl make

clip_p_w_picpath002


二、监控端:

1个步骤:


clip_p_w_picpath004

创建一个名为nagios的帐号并给定登录口令 
/usr/sbin/useradd nagios 
passwd nagios #密码123456 
创建一个用户组名为nagcmd用于从Web接口执行外部命令。将nagios用户和apache用户都加到这个组中。 
/usr/sbin/groupadd nagcmd 
/usr/sbin/usermod -G nagcmd nagios 
/usr/sbin/usermod -G nagcmd apache 
clip_p_w_picpath006

[root@gjp nagios]# yum install sendmail –y

clip_p_w_picpath008
cd /root nagios下载目录 
tar xzf nagios-3.4.3.tar.gz

cd nagios 
运行Nagios配置脚本并使用先前开设的用户及用户组: 
./configure --with-command-group=nagcmd

下面这个,我这里没指定

clip_p_w_picpath010

clip_p_w_picpath012

make all 
make install

clip_p_w_picpath014
make install-init

clip_p_w_picpath016

make install-config 
clip_p_w_picpath018

make install-commandmode

把Nagios加入到服务列表中以使之在系统启动时自动启动

clip_p_w_picpath020

现在还不能启动Nagios-还有一些要做的... 
客户后配置 
样例配置文件默认安装在这个目录下/usr/local/nagios/etc,这些样例文件可以配置Nagios使之正常运行,只需要做一个简单的修改... 
用你擅长的编辑器软件来编辑这个/usr/local/nagios/etc/objects/contacts.cfg配置文件,更改email地址nagiosadmin的联系人定义信息中的EMail信息为你的EMail信息以接收报警内容。 
vi /usr/local/nagios/etc/objects/contacts.cfg

配置WEB接口 
安装Nagios的WEB配置文件到Apache的conf.d目录下

nagios-3.4.3.tar.gz解压后的nagios中执行

[root@gjp ~]# cd nagios

[root@gjp nagios]# make install-webconf

在ls /etc/httpd/conf.d/下,会出现nagios.conf 文件 

2个步骤:ngios插件


clip_p_w_picpath022

下面使用的版本与上面不同: 
展开Nagios插件的源程序包 
cd /root 
tar xzf nagios-plugins-1.4.16.tar.gz 
cd nagios-plugins-1.4.16 
yum install -y openssl openssl-devel 
编译并安装插件 
./configure --with-nagios-user=nagios --with-nagios-group=nagios 
make && make install

3个步骤:安装nagios汉化插件(此步,我跳过了)

clip_p_w_picpath024

clip_p_w_picpath026

4个步骤:

clip_p_w_picpath028

clip_p_w_picpath030

我在这里采用的yum安装!

clip_p_w_picpath032

clip_p_w_picpath034

clip_p_w_picpath036

以上,是参考文档,我这里如下配置:

因为前面建立了个用户组,把nagios和apache都添加进去了!因此,我这里无需改动:除了这个无需改动clip_p_w_picpath038,其他修改如上

clip_p_w_picpath040

创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。 
htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin #密码123456

clip_p_w_picpath042

重启Apache服务以使设置生效。 
service httpd restart

如果出现服务启动不了,出现这样

clip_p_w_picpath044

clip_p_w_picpath046

clip_p_w_picpath048

启动Nagios 
验证Nagios的样例配置文件 
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg 
如果没有报错,可以启动Nagios服务 
service nagios start 
[root@gjp nagios-plugins-1.4.16]# service nagios start

Starting nagios: done.

界面:

http://192.168.1.104:1080/nagios/

访问时,输入用户名和密码:则是vim /usr/local/nagios/etc/htpasswd 该文件中的用户和密码!


一个Ai
2楼 · 2021-04-09 15:43

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

  Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。

主要功能

网络服务监控(SMTP、POP3、HTTP、NNTP、ICMP、SNMP、FTP、SSH)主机资源监控(CPU load、disk usage、system logs),也包括Windows主机(使用NSClient++ plugin)可以指定自己编写的Plugin通过网络收集数据来监控任何情况(温度、警告……)可以通过配置Nagios远程执行插件远程执行脚本远程监控支持SSH或SSL加通道方式进行监控简单的plugin设计允许用户很容易的开发自己需要的检查服务,支持很多开发语言(shell scripts、C++、Perl、ruby、Python、PHP、C#等)包含很多图形化数据Plugins(Nagiosgraph、Nagiosgrapher、PNP4Nagios等)可并行服务检查能够定义网络主机的层次,允许逐级检查,就是从父主机开始向下检查当服务或主机出现问题时发出通告,可通过email, pager, sms 或任意用户自定义的plugin进行通知能够自定义事件处理机制重新激活出问题的服务或主机自动日志循环支持冗余监控包括Web界面可以查看当前网络状态,通知,问题历史,日志文件等

支持短信,邮件通知

Nagios官网 http://www.nagios.org

1. Nagios安装 - 服务端(192.168.0.11)

Centos6默认的yum源里没有nagios相关的rpm包,但是我们可以安装一个epel的扩展源:


复制代码代码如下:


yum install -y epel-release



然后安装nagios相关的包


复制代码代码如下:


yum install -y httpd nagios nagios-pluginsnagios-plugins-all nrpe nagios-plugins-nrpe



设置登录nagios后台的用户和密码:htpasswd -c /etc/nagios/passwd nagiosadmin


复制代码代码如下:


nagios -v /etc/nagios/nagios.cfg 检测配置文件



启动服务:service httpd start; servicenagios start

浏览器访问:http://ip/nagios

vim /etc/nagios/nagios.cfg  #暂时先不管

2. Nagios安装 - 客户端(192.168.0.12)

在客户端机器上


复制代码代码如下:


yum install -y epel-release
yum install -y nagios-plugins nagios-plugins-allnrpe nagios-plugins-nrpe
vim /etc/nagios/nrpe.cfg  找到“allowed_hosts=127.0.0.1” 改为“allowed_hosts=127.0.0.1,192.168.0.11”   #服务器的ip
找到” dont_blame_nrpe=0” 改为  “dont_blame_nrpe=1”



启动客户端 /etc/init.d/nrpe start

3. 监控中心(192.168.0.11)添加被监控主机(192.168.0.12)


复制代码代码如下:


vim /etc/nagios/conf.d/192.168.0.12.cfg                 
define host{
        use                   linux-server           
       host_name          192.168.0.12
       alias                      0.12
       address                192.168.0.12
        }
define service{
        use                   generic-service
       host_name              192.168.0.12              
       service_description     check_ping
       check_command          check_ping!100.0,20%!200.0,50%      #0是ok,20是警告,50是危险
        max_check_attempts5                    #单位是秒数
       normal_check_interval 1
}
define service{
        use                   generic-service
       host_name              192.168.0.12
       service_description     check_ssh
       check_command          check_ssh
       max_check_attempts      5    ;当nagios检测到问题时,一共尝试检测5次都有问题才会告警,如果该数值为1,那么检测到问题立即告警
       normal_check_interval 1   ;重新检测的时间间隔,单位是分钟,默认是3分钟
       notification_interval          60 ;在服务出现异常后,故障一直没有解决,nagios再次对使用者发出通知的时间。单位是分钟。如果你认为,所有的事件只需要一次通知就够了,可以把这里的选项设为0。
}
define service{
        use                   generic-service
       host_name              192.168.0.12
       service_description     check_http
       check_command          check_http
        max_check_attempts     5
       normal_check_interval 1
}


以上普通服务不依赖于客户端nrpe服务,我们可以想象,我们在自己电脑上可以使用ping或者telnet探测远程任何一台机器是否存活、是否开启某个端口或服务。而当我们想要检测客户端上的某个具体特殊服务的情况时,就需要借助于nrpe了,比如想知道客户端机器的负责或磁盘使用情况。

4.  继续添加服务

增加:


复制代码代码如下:


define command{
       command_name    check_nrpe    #去对方获得服务状态,可自定义
       command_line    $USER1$/check_nrpe -H $HOSTADDRESS$-c $ARG1$
        }


继续编辑


复制代码代码如下:


vim/etc/nagios/conf.d/192.168.0.12.cfg      


增加如下内容:


复制代码代码如下:


define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_load
       check_command          check_nrpe!check_load
       max_check_attempts 5
       normal_check_interval 1
}
define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}
define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda2
       check_command          check_nrpe!check_hda2    #这个不要写错,是对应客户端的
       max_check_attempts 5
       normal_check_interval 1
}


说明:  check_nrpe!check_load:这里的check_nrpe就是在commands.cfg刚刚定义的,check_load是远程主机上的一个检测脚本

在客户端上vim/etc/nagios/nrpe.cfg 搜索check_load,这行就是在服务端上要执行的脚本了,我们可以手动执行这个脚本
把check_hda1更改一下:/dev/hda1 改为 /dev/sda1

再加一行command[check_hda2]=/usr/lib/nagios/plugins/check_disk-w 20% -c 10% -p /dev/sda2  # w = warnning
c = critial

Crital不能比warning的值大

机制:首先在服务端定义check_nrpe命令,再通过check_nrpe后面跟的command(客户端的nrpe.cfg里)

客户端上重启一下nrpe服务: service nrpe restart
服务端也重启一下nagios服务: service nagios restart

5.   配置告警


复制代码代码如下:


vim /etc/nagios/objects/contacts.cfg //增加:
define contact{
        contact_name                               
       use                           generic-contact
        alias                         aming
        email             @qq.com
        }
define contact{
        contact_name             
        use                           generic-contact
        alias                          aaa
        email             wsw@.com
        }
define contactgroup{                         #定义联系组
        contactgroup_name          common
        alias                                common
        members                        ,
        }


然后在要需要告警的服务里面加上contactgroup


复制代码代码如下:


define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_load
       check_command          check_nrpe!check_load
       max_check_attempts 5
       normal_check_interval 1
        contact_groups       common                  #监控哪个发邮件
       notifications_enabled  1    ;是否开启提醒功能。
1为开启,0为禁用。一般,这个选项会在主配置文件(nagios.cfg)中定义,效果相同。
        notification_period  24x7   ;发送提醒的时间段。非常重要的主机(服务)我定义为7×24,一般的主机(服务)就定义为上班时间。如果不在定义的时间段内,无论什么问题发生,都不会发送提醒。      
       notification_options:w,u,c,r   ;这个是service的状态。w为waning, u为unknown, c为critical, r为recover(恢复了),类似的还有一个  host对应的状态:d,u,r   d = 状态为DOWN, u = 状态为UNREACHABLE , r = 状态恢复为OK,需要加入到host的定义配置里。
}


6.   配置图形显示 pnp4nagios

(1)安装


复制代码代码如下:


yum install pnp4nagios rrdtool


(2)配置主配置文件


复制代码代码如下:


vim /etc/nagios/nagios.cfg  //修改如下配置
  process_performance_data=   
  host_perfdata_command=process-host-perfdata
  service_perfdata_command=process-service-perfdata
  enable_environment_macros=  


(3)修改commands.cfg

vim/etc/nagios/objects/commands.cfg  //注释掉原有对process-host-perfdata和process-service-perfdata,重新定义


复制代码代码如下:


  define command { 
        command_name    process-service-perfdata 
        command_line    /usr/bin/perl/usr/libexec/pnpnagios/process_perfdata.pl 
  }     
  define command {  
  command_name    process-host-perfdata 
        command_line    /usr/bin/perl/usr/libexec/pnpnagios/process_perfdata.pl -d HOSTPERFDATA 
  }


(4)修改配置文件templates.cfg


复制代码代码如下:


vim /etc/nagios/objects/templates.cfg definehost {
        name      hosts-pnp
       register   0
        action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=_HOST_
       process_perf_data              1
}
define service {
        name      srv-pnp
       register   0
        action_url/pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
       process_perf_data              1
}


(5)修改host和service配置


复制代码代码如下:


vim /etc/nagios/conf.d/192.168.0.12.cfg
把 “define host{
        use                   linux-server”


改为:


复制代码代码如下:


define host{
        use                   linux-server,hosts-pnp


修改对应的service,比如


复制代码代码如下:


define service{
        use    generic-service
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}


改为:


复制代码代码如下:


define service{
        use    generic-service,srv-pnp
       host_name       192.168.0.12
       service_description     check_disk_hda1
       check_command          check_nrpe!check_hda1
       max_check_attempts 5
       normal_check_interval 1
}


(6)重启和启动各个服务:


复制代码代码如下:


service nagios restart
service httpd restart
service npcd start



(7) 访问测试

两种访问方法:


复制代码代码如下:


ip/nagios/
ip/pnp4nagios/


以上所述是小编给大家分享的Nagios的安装与使用详细教程,希望对大家有所帮助。


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

  Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。


靓猴一枚
4楼 · 2021-04-10 10:32

1.上面我讲了一些nagios服务端的安装和简单的配置,现在来讲一下服务端监控多台服务器的以及被监控端的安装配置。

2.nagios 服务端的配置

(1).首先默认安装好后,nagios就创建好了一个分组和一些服务,这个文件就是localhost.cfg文件。现在我们要创建自己的文件

把nagios.cfg里面的定义localhost.cfg这个注释掉,然后在开启hostgroup.cfg,host.cfg,services.cfg这三个文件。我把这三个文件

放在conf目录下便于管理。

注:这些文件及相关目录原先是没有的,要自己创建并授权给它们

(2).要创建自己的组就先要在contacts.cfg里面定一个自己的联系人。

linux-servers是我自己建的联系人各联系组。

注:如果不建这个联系人和组,在后面的hostgroup.cfg里面不能定义自己的主机组员。


先讲一下他们三者的关系,监控组(hostgroup.cfg)包含了监控主机(host.cfg)包含了监控服务(services.cfg)

hostgroup.cfg->host.cfg->services.cfg

只要有一个不在就会报错。

检查nagios.cfg这个文件的报错信息是

/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

可以看到你哪里配置错了,我也是通过这个来排错的。

1.hostgroup.cfg

define hostgroup {
hostgroup_name linux-servers
alias linux-servers
members CentOS
}

2.host.cfg

define host {
host_name CentOS
alias server,host-pnp
address 192.168.1.8
contact_groups linux-servers
check_command check-host-alive
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
}

3.services.cfg

define service {
host_name CentOS
use local-service,srv-pnp
service_description CPU
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups linux-servers
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_cpu
}
define service {
host_name CentOS
use local-service,srv-pnp
service_description CPU_load
check_period 24x7
max_check_attempts 4
normal_check_interval 1
retry_check_interval 1
contact_groups linux-servers
notification_interval 10
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_load
}

//services.cfg 这里只给出了两个,其它的按自己的需要添加就行了。

重启nagios之后先检查一下有没有错误了,没有的话就重启一下

service nagios restart

上面的图是我配好后的结果,现在来配置被监控端。

3.nagios 被监控端的配置。

(1).安装nagios-plugins

如果后面的configure没有检查到mysql这一项,看一下mysql-devel有没有安装,没有安装一下。

tar –xvf nagios-plugins-1.4.15.tar.gz

cd nagios-plugins-1.4.15

./configure

make && make install

(2).安装nrpe

tar –xvf nrpe-2.12.tar.gz

cd nrpe-2.12

./configure

make all

make install-plugin

make install-daemon

make install-daemon-config

make install-xinetd //这个是用xinetd来管理nrpe的启动和关闭的,可以加上也可以不加上。

(3).到些被监控的软件装好了,还要装一下snmp来收集数据,安装和配置net-snmp我已经在前面说过了,这里就不说了。

现在来配置一下监控项(nrpe.cnf)

log_facility=daemon
pid_file=/var/run/nrpe.pid
server_port=5666
nrpe_user=nagios
nrpe_group=nagios
allowed_hosts=192.168.1.7

dont_blame_nrpe=1
debug=1
command_timeout=30
connection_timeout=300

command[check_http]=/usr/local/nagios/libexec/check_http -I localhost -u /index.php -t 60
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 5% -c 3% -A -i '/dev/shm'
command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C nagios -H localhost -I 2 -w 12,30 -c 15,35 -M -b -6
command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh
command[check_mem]=/usr/local/nagios/libexec/check_mem.sh
command[check_ips]=/usr/local/nagios/libexec/ip_conn.sh 400 600
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,8 -c 30,25,20
command[check_ftp]=/usr/local/nagios/libexec/check_ftp 127.0.0.1 -w 10 -c 60

这里有几个是没有的要自己去网上找,然后下载下来放到/usr/local/nagios/libexec/下面并给执行权限,拥有者nagios。(check_traffic.sh,check_cpu.sh,

check_mem.sh,ip_conn.sh)


是你的小甜心呀
5楼 · 2021-04-10 21:59

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

  Nagios原名为NetSaint,由Ethan Galstad开发并维护至今。NAGIOS是一个缩写形式: "Nagios Ain't Gonna Insist On Sainthood" Sainthood 翻译为圣徒,而"Agios"是"saint"的希腊表示方法。Nagios被开发在Linux下使用,但在Unix下也工作得非常好。


我的网名不再改
6楼 · 2021-11-24 14:07

下载地址如下: http://sourceforge.net/projects/nagios/files/


具体详细下载地址:http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-4.0.6.tar.gz

 


1 开始下载:

 wget http://sourceforge.net/projects/nagios/files/nagios-4.x/nagios-4.0.6/nagios-4.0.6.tar.gz/download?use_mirror=jaist

如下图所示,下载free版本的。


安装前准备工作,安装一些lib包:


[root@cache-2 root]# yum -y install httpd gcc glibc glibc-common


# yum install -y gcc glibc glibc-common gd gd-devel xinetd openssl-devel


 


2 进行selinux设置,或者关闭selinux


 


 查看SELinux状态:


 (1)/usr/sbin/sestatus -v      ##如果SELinux status参数为enabled即为开启状态


         SELinux status:                 enabled


 (2)getenforce                 ##也可以用这个命令检查


 关闭SELinux:


 (3)临时关闭(不用重启机器):


         setenforce 0                  ##设置SELinux 成为permissive模式


                              ##setenforce 1 设置SELinux 成为enforcing模式


 (4)修改配置文件需要重启机器:


         修改/etc/selinux/config 文件


         将SELINUX=enforcing改为SELINUX=disabled


         重启机器即可


 


3 开始准备nagios安装环境


 


  (1) 添加nagios运行所需要的用户和组:


  groupadd nagcmd


         useradd -m nagios


         usermod -a -G nagcmd nagios


        


把apache加入到nagcmd组,以便于在通过web Interface操作nagios时能够具有足够的权限:


# usermod -a -G nagcmd apache


 


4 编译安装准备


 


执行命令:


tar -xvf nagios-4.0.6.tar.gz

cd /root/nagios-4.0.6

./configure --with-command-group=nagios --prefix=/opt/app/nagios --enable-embedded-perl --with-httpd-conf=/usr/local/apache2/conf

[root@cache-2 nagios-4.0.6]# ./configure --with-command-group=nagios  --prefix=/opt/app/nagios --enable-embedded-perl  --with-httpd-conf=/usr/local/apache2/conf

checking for a BSD-compatible install... /usr/bin/install -c

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking for gcc... gcc

checking for C compiler default output file name... a.out

checking whether the C compiler works... yes

checking whether we are cross compiling... no

.............................

 HTML URL:  http://localhost/nagios/

                  CGI URL:  http://localhost/nagios/cgi-bin/

 Traceroute (used by WAP):  /bin/traceroute

 

 

Review the options above for accuracy.  If they look okay,

type 'make all' to compile the main program and CGIs.

 


 


5 开始make安装

5.1 make all

[root@cache-2 nagios-4.0.6]#  make all


 


cd ./base && make

make[1]: Entering directory `/root/nagios-4.0.6/base'

gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE -c -o nagios.o nagios.c

gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o broker.o broker.c

gcc -Wall -I.. -g -O2 -DHAVE_CONFIG_H -DNSCORE   -c -o nebmods.o nebmods

.........................

For more information on obtaining support for Nagios, visit:

       http://support.nagios.com

*************************************************************

Enjoy.

 


 


5.2 make install

[root@cache-2 nagios-4.0.6]# make install


 


cd ./base && make install

make[1]: Entering directory `/root/nagios-4.0.6/base'

make install-basic

make[2]: Entering directory `/root/nagios-4.0.6/base'

.....................................................

make[2]: Entering directory `/root/nagios-4.0.6/cgi'

for file in *.cgi; do \

/usr/bin/strip /usr/local/nagios/sbin/$file; \

done




5.3 make install-config


 


[root@cache-2 nagios-4.0.6]# make install-config

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/etc/objects

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/nagios.cfg /usr/local/nagios/etc/nagios.cfg

....................................................

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/printer.cfg /usr/local/nagios/etc/objects/printer.cfg

/usr/bin/install -c -b -m 664 -o nagios -g nagios sample-config/template-object/switch.cfg /usr/local/nagios/etc/objects/switch.cfg

 

*** Config files installed ***

 


 


5.4 make install-commandmode


 


 


 


[root@cache-2 nagios-4.0.6]# make install-commandmode

/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/var/rw

chmod g+s /usr/local/nagios/var/rw

 

*** External command directory configured ***

 

Remember, these are *SAMPLE* config files.  You'll need to read

the documentation for more information on how to actually define

services, hosts, etc. to fit your particular needs.

 


 


 



5.5 make install-init


 


[root@cache-2 nagios-4.0.6]# make install-init

/usr/bin/install -c -m 755 -d -o root -g root /etc/rc.d/init.d

/usr/bin/install -c -m 755 -o root -g root daemon-init /etc/rc.d/init.d/nagios

 

*** Init script installed ***

 


 


 


[root@cache-2 nagios-4.0.6]#


加到启动项里面去:


# chkconfig --add nagios


# chkconfig --level 35 nagios on


# chkconfig --list nagios




 


检查主机配置文件是否正确:


 


/var/www/nagios/bin/nagios -v /var/www/nagios/etc/nagios.cfg


 


5.6 Check安装是否正确:


5.6.1说明:


切换目录到安装路径(这里是/usr/local/nagios),看是否存在etc、bin、sbin、share、var 这五个目录,如果存在则可以表明程序被正确的安装到系统了。Nagios 各个目录用途说明如下:


bin    Nagios 可执行程序所在目录


etc   Nagios 配置文件所在目录


sbin  Nagios CGI 文件所在目录,也就是执行外部命令所需文件所在的目录


share        Nagios网页文件所在的目录


libexec      Nagios 外部插件所在目录


var   Nagios 日志文件、lock 等文件所在的目录


var/archives     Nagios 日志自动归档目录


var/rw      用来存放外部命令文件的目录


 


5.6.2 check

 cd /usr/local/nagios

ll


 


[root@cache-2 nagios-4.0.6]# cd /usr/local/nagios

[root@cache-2 nagios]# ll

总用量 24

drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 bin

drwxrwxr-x.  3 nagios nagios 4096 5月   5 15:32 etc

drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 libexec

drwxrwxr-x.  2 nagios nagios 4096 5月   5 15:31 sbin

drwxrwxr-x. 10 nagios nagios 4096 5月   5 15:31 share

drwxrwxr-x.  5 nagios nagios 4096 5月   5 15:32 var

 


 


 


 


 


5.7 安装nagios插件

wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz


 


[root@cache-2 ~]# wget http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

--2014-05-05 15:52:52--  http://nagios-plugins.org/download/nagios-plugins-2.0.tar.gz

正在解析主机 nagios-plugins.org... 72.14.186.43

正在连接 nagios-plugins.org|72.14.186.43|:80... 已连接。

已发出 HTTP 请求,正在等待回应... 200 OK

............................................

2014-05-05 15:53:00 (373 KB/s) - 已保存 “nagios-plugins-2.0.tar.gz” [2501847/2501847])

 

[root@cache-2 ~]# tar -xvf nagios-plugins-2.0.tar.gz

[root@cache-2 ~]# cd nagios-plugins-2.0

[root@cache-2 ~]#./configure --with-nagios-user=nagios --with-nagios-group=nagios  --prefix=/usr/local/nagios --with-mysql

[root@cache-2 ~]# make && make install

 


 


 



5.8 安装配置apache和php

(1)安装apache

下载 wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz


 


 


 


[root@cache-2 ~]# wget http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz --2014-05-05 16:15:48-- http://archive.apache.org/dist/httpd/httpd-2.4.7.tar.gz 正在解析主机 archive.apache.org... 192.87.106.229, 140.211.11.131, 2001:610:1:80bc:192:87:106:229 正在连接 archive.apache.org|192.87.106.229|:80... 已连接。 已发出 HTTP 请求,正在等待回应... 200 OK 长度:6747087 (6.4M) [application/x-gzip] 正在保存至: “httpd-2.4.7.tar.gz” 1% [=> .............................................................. 2014-05-05 16:16:01 (574 KB/s) - 已保存 “httpd-2.4.7.tar.gz” [6747087/6747087])


 


开始安装:

 tar -xvf httpd-2.4.7.tar.gz

 cd httpd-2.4.7

 ./configure --prefix=/usr/local/apache2

make && make install


[root@cache-2 ~]# tar -xvf httpd-2.4.7.tar.gz

[root@cache-2 ~]# cd httpd-2.4.7

[root@cache-2 httpd-2.4.7]# ./configure --prefix=/usr/local/apache2

checking for chosen layout... Apache

checking for working mkdir -p... yes

checking for grep that handles long lines and -e... /bin/grep

checking for egrep... /bin/grep -E

checking build system type... x86_64-unknown-linux-gnu

checking host system type... x86_64-unknown-linux-gnu

checking target system type... x86_64-unknown-linux-gnu

configure: 

configure: Configuring Apache Portable Runtime library...

configure: 

checking for APR... no

configure: error: APR not found.  Please read the documentation.

Google之后,发现可能是gcc版本太低了,可能是apache版本太高,换低点的2.2.23版本吧。

wget http://archive.apache.org/dist/httpd/httpd-2.2.23.tar.gz

tar -xvf  httpd-2.2.23.tar.gz

cd httpd-2.2.23

./configure --prefix=/usr/local/apache2

make && make install

 


 


 


(2) 安装php版本


wget http://cn2.php.net/distributions/php-5.4.26.tar.gz


tar -xvf php-5.4.26.tar.gz


cd php-5.4.26


./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs


有报错信息:


Configuring extensions


checking size of long... (cached) 8


checking size of int... (cached) 4


checking for int32_t... yes


checking for uint32_t... yes


checking for sys/types.h... (cached) yes


checking for inttypes.h... (cached) yes


checking for stdint.h... (cached) yes


checking for string.h... (cached) yes


checking for stdlib.h... (cached) yes


checking for strtoll... yes


checking for atoll... yes


checking for strftime... (cached) yes


checking which regex library to use... php


checking whether to enable LIBXML support... yes


checking libxml2 install dir... no


checking for xml2-config path...


configure: error: xml2-config not found. Please check your libxml2 installation.


 


需要重新安装lib包


yum install libxml2 –y


yum install libxml2-devel –y


 


之后继续make,成功了:


Make && make install


[activating module `php5' in /usr/local/apache2/conf/httpd.conf]


Installing PHP CLI binary:        /usr/local/php/bin/


Installing PHP CLI man page:      /usr/local/php/php/man/man1/


Installing PHP CGI binary:        /usr/local/php/bin/


Installing PHP CGI man page:      /usr/local/php/php/man/man1/


Installing build environment:     /usr/local/php/lib/php/build/


Installing header files:          /usr/local/php/include/php/


Installing helper programs:       /usr/local/php/bin/


  program: phpize


  program: php-config


Installing man pages:             /usr/local/php/php/man/man1/


  page: phpize.1


  page: php-config.1


Installing PEAR environment:      /usr/local/php/lib/php/


[PEAR] Archive_Tar    - installed: 1.3.11


[PEAR] Console_Getopt - installed: 1.3.1


warning: pear/PEAR requires package "pear/Structures_Graph" (recommended version 1.0.4)


warning: pear/PEAR requires package "pear/XML_Util" (recommended version 1.2.1)


[PEAR] PEAR           - installed: 1.9.4


Wrote PEAR system config file at: /usr/local/php/etc/pear.conf


You may want to add: /usr/local/php/lib/php to your php.ini include_path


[PEAR] Structures_Graph- installed: 1.0.4


[PEAR] XML_Util       - installed: 1.2.1


/root/php/php-5.4.26/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin


ln -s -f /usr/local/php/bin/phar.phar /usr/local/php/bin/phar


Installing PDO headers:          /usr/local/php/include/php/ext/pdo/


 


(3) 配置apache


 


Apache的配置文件在 /usr/local/apache2/conf/httpd.conf ,vim打开



User daemon


Group daemon


修改成:


User nagios


Group nagios


 




  DirectoryIndex index.html



修改成:



  DirectoryIndex index.html index.php


    AddType application/x-httpd-php .php



 


为了安全起见:nagios的web监控页面需要经过授权才能访问,这需要增加验证配置,即在httpd.conf 文件最后添加如下信息:


#setting for nagios


ScriptAlias /nagios/cgi-bin "/usr/local/nagios/sbin"



     AuthType Basic


     Options ExecCGI


     AllowOverride None


     Order allow,deny


     Allow from all


     AuthName "Nagios Access"


     AuthUserFile /usr/local/nagios/etc/htpasswd  //用于此目录访问身份验证的文件             


     Require valid-user



Alias /nagios "/usr/local/nagios/share"



     AuthType Basic


     Options None


     AllowOverride None


     Order allow,deny


     Allow from all


     AuthName "nagios Access"


     AuthUserFile /usr/local/nagios/etc/htpasswd


     Require valid-user



 


(4) 创建apache目录验证文件


 


在上面的配置中,指定了目录验证文件htpasswd,下面要创建这个文件:


/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david


[root@cache-2 php-5.4.26]#  /usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd david


New password:


Re-type new password:


Adding password for user david


查看认证文件的内容:


[root@cache-2 php-5.4.26]#  cat /usr/local/nagios/etc/htpasswd


david:$apr1$Pf9XIJjd$m5hR2vw70MlqwrChgN7zc/


[root@cache-2 php-5.4.26]#


 


启动apache服务:


/usr/local/apache2/bin/apachectl start


 


[root@cache-2 php-5.4.26]# /usr/local/apache2/bin/apachectl start


httpd: Could not reliably determine the server's fully qualified domain name, using 10.254.3.41 for ServerName


(98)Address already in use: make_sock: could not bind to address [::]:80


(98)Address already in use: make_sock: could not bind to address 0.0.0.0:80


no listening sockets available, shutting down


Unable to open logs


修改ServerName以及Port


vi /usr/local/apache2/conf/httpd.conf


ServerName 改成 10.xx.3.x1


Listen 80 改成 Listen 81


http://10.xx.3.x1:81/nagios/,可以打开了,如下所示:






 


6 配置nagios


Nagios 主要用于监控一台或者多台本地主机及远程的各种信息,包括本机资源及对外的服务等。默认的Nagios 配置没有任何监控内容,仅是一些模板文件。若要让Nagios 提供服务,就必须修改配置文件,增加要监控的主机和服务,下面将详细介绍。


 


6.1 默认配置文件介绍


Nagios 安装完毕后,默认的配置文件在/usr/local/nagios/etc目录下。


[root@cache-2 etc]# cd /usr/local/nagios/etc


[root@cache-2 etc]# ls


cgi.cfg  htpasswd  nagios.cfg objects  resource.cfg


[root@cache-2 etc]#


[root@cache-2 etc]# cd objects


[root@cache-2 objects]# ls


commands.cfg contacts.cfg  localhost.cfg  printer.cfg switch.cfg  templates.cfg  timeperiods.cfg  windows.cfg


[root@cache-2 objects]#


 


每个文件或目录含义如下表所示:


文件名或目录名     用途


cgi.cfg      控制CGI访问的配置文件


nagios.cfg         Nagios 主配置文件


resource.cfg    变量定义文件,又称为资源文件,在些文件中定义变量,以便由其他配置文件引用,如$USER1$


objects     objects 是一个目录,在此目录下有很多配置文件模板,用于定义Nagios 对象


objects/commands.cfg    命令定义配置文件,其中定义的命令可以被其他配置文件引用


objects/contacts.cfg        定义联系人和联系人组的配置文件


objects/localhost.cfg       定义监控本地主机的配置文件


objects/printer.cfg  定义监控打印机的一个配置文件模板,默认没有启用此文件


objects/switch.cfg   定义监控路由器的一个配置文件模板,默认没有启用此文件


objects/templates.cfg     定义主机和服务的一个模板配置文件,可以在其他配置文件中引用


objects/timeperiods.cfg  定义Nagios 监控时间段的配置文件


objects/windows.cfg        监控Windows 主机的一个配置文件模板,默认没有启用此文件


 


 


6.2 配置文件之间的关系


 


在nagios的配置过程中涉及到的几个定义有:主机、主机组,服务、服务组,联系人、联系人组,监控时间,监控命令等,从这些定义可以看出,nagios各个配置文件之间是互为关联,彼此引用的。


 


成功配置出一台nagios监控系统,必须要弄清楚每个配置文件之间依赖与被依赖的关系,最重要的有四点:


 


第一:定义监控哪些主机、主机组、服务和服务组;


第二:定义这个监控要用什么命令实现;


第三:定义监控的时间段;


第四:定义主机或服务出现问题时要通知的联系人和联系人组。


 


6.3 配置Nagios


 为了能更清楚的说明问题,同时也为了维护方便,建议将nagios各个定义对象创建独立的配置文件:


·         创建hosts.cfg文件来定义主机和主机组


·         创建services.cfg文件来定义服务


·         用默认的contacts.cfg文件来定义联系人和联系人组


·         用默认的commands.cfg文件来定义命令


·         用默认的timeperiods.cfg来定义监控时间段


·         用默认的templates.cfg文件作为资源引用文件


 


 


a. timeperiods.cfg文件


define contact{

        name                            generic-contact    ; 联系人名称

        service_notification_period     24x7               ; 当服务出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义

        host_notification_period        24x7               ; 当主机出现异常时,发送通知的时间段,这个时间段"24x7"在timeperiods.cfg文件中定义

        service_notification_options    w,u,c,r            ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态,u即unknown,表示不明状态;

                                                           ; c即criticle,表示紧急状态,r即recover,表示恢复状态;

                                                           ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复状态时都发送通知给使用者。

        host_notification_options       d,u,r                   ; 定义主机在什么状态下需要发送通知给使用者,d即down,表示宕机状态;

                                                                ; u即unreachable,表示不可到达状态,r即recovery,表示重新恢复状态。

        service_notification_commands   notify-service-by-email ; 服务故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;

                                                                ; 其中“notify-service-by-email”在commands.cfg文件中定义。

        host_notification_commands      notify-host-by-email    ; 主机故障时,发送通知的方式,可以是邮件和短信,这里发送的方式是邮件;

                                                                ; 其中“notify-host-by-email”在commands.cfg文件中定义。 

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

        }

define host{

        name                            generic-host    ; 主机名称,这里的主机名,并不是直接对应到真正机器的主机名;

                                                        ; 乃是对应到在主机配置文件里所设定的主机名。

        notifications_enabled           1               ; Host notifications are enabled

        event_handler_enabled           1               ; Host event handler is enabled

        flap_detection_enabled          1               ; Flap detection is enabled

        failure_prediction_enabled      1               ; Failure prediction is enabled

        process_perf_data               1               ; 其值可以为0或1,其作用为是否启用Nagios的数据输出功能;

                                                        ; 如果将此项赋值为1,那么Nagios就会将收集的数据写入某个文件中,以备提取。

        retain_status_information       1               ; Retain status information across program restarts

        retain_nonstatus_information    1               ; Retain non-status information across program restarts

        notification_period             24x7            ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。

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

        }

define service{

        name                            generic-service         ; 定义一个服务名称

        active_checks_enabled           1                       ; Active service checks are enabled

        passive_checks_enabled          1                       ; Passive service checks are enabled/accepted

        parallelize_check               1                       ; Active service checks should be parallelized;

                                                                ; (disabling this can lead to major performance problems)

        obsess_over_service             1                       ; We should obsess over this service (if necessary)

        check_freshness                 0                       ; Default is to NOT check service 'freshness'

        notifications_enabled           1                       ; Service notifications are enabled

        event_handler_enabled           1                       ; Service event handler is enabled

        flap_detection_enabled          1                       ; Flap detection is enabled

        failure_prediction_enabled      1                       ; Failure prediction is enabled

        process_perf_data               1                       ; Process performance data

        retain_status_information       1                       ; Retain status information across program restarts

        retain_nonstatus_information    1                       ; Retain non-status information across program restarts

        is_volatile                     0                       ; The service is not volatile

        check_period                    24x7             ; 这里的check_period告诉nagios检查服务的时间段。

        max_check_attempts              3                ; nagios对服务的最大检查次数。

        normal_check_interval           5                ; 此选项是用来设置服务检查时间间隔,也就是说,nagios这一次检查和下一次检查之间所隔的时间;

                                                         ; 这里是5分钟。

        retry_check_interval            2                ; 重试检查时间间隔,单位是分钟。

        contact_groups                  ts           ; 指定联系人组

        notification_options            w,u,c,r          ; 这个定义的是“通知可以被发出的情况”。w即warn,表示警告状态;

                                                         ; u即unknown,表示不明状态;

                                                         ; c即criticle,表示紧急状态,r即recover,表示恢复状态;

                                                         ; 也就是在服务出现警告状态、未知状态、紧急状态和重新恢复后都发送通知给使用者。

        notification_interval           10               ; Re-notify about service problems every hour

        notification_period             24x7             ; 指定“发送通知”的时间段,也就是可以在什么时候发送通知给使用者。

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

        }

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!

        }

 


 


 


 


 


 


 

 


 


b. resource.cfg文件


resource.cfg是nagios的变量定义文件,文件内容只有一行:


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

其中,变量$USER1$指定了安装nagios插件的路径,如果把插件安装在了其它路径,只需在这里进行修改即可。需要注意的是,变量必须先定义,然后才能在其它配置文件中进行引用。


 


c. commands.cfg文件


此文件默认是存在的,无需修改即可使用,当然如果有新的命令需要加入时,在此文件进行添加即可。


 


#notify-host-by-email命令的定义 

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命令的定义 

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$

        }

define command{

        command_name    check_local_disk

        command_line    $USER1$/check_disk -w $ARG1$ -c $ARG2$ -p $ARG3$            #$ARG1$是指在调用这个命令的时候,命令后面的第一个参数。

        }

define command{

        command_name    check_local_load

        command_line    $USER1$/check_load -w $ARG1$ -c $ARG2$

        }

define command{

        command_name    check_local_procs

        command_line    $USER1$/check_procs -w $ARG1$ -c $ARG2$ -s $ARG3$

        }

define command{

        command_name    check_local_users

        command_line    $USER1$/check_users -w $ARG1$ -c $ARG2$

        }

 


 


 


d. hosts.cfg文件


此文件默认不存在,需要手动创建,hosts.cfg主要用来指定被监控的主机地址以及相关属性信息,根据实验目标配置如下:


define host{   

        use                     linux-server          #引用主机linux-server的属性信息,linux-server主机在templates.cfg文件中进行了定义。

        host_name               Nagios-Linux          #主机名

        alias                   Nagios-Linux          #主机别名

        address                 192.168.1.111         #被监控的主机地址,这个地址可以是ip,也可以是域名。

        }   

#定义一个主机组   

define hostgroup{      

        hostgroup_name          bsmart-servers        #主机组名称,可以随意指定。

        alias                   bsmart servers        #主机组别名

        members                 Nagios-Linux          #主机组成员,其中“Nagios-Linux”就是上面定义的主机。     

        }

注意:在/usr/local/nagios/etc/objects 下默认有localhost.cfg和windows.cfg 这两个配置文件,localhost.cfg 文件是定义监控主机本身的,windows.cfg文件是定义windows 主机的,其中包括了对host 和相关services 的定义。所以在本次实验中,将直接在localhost.cfg 中定义监控主机(Nagios-Server),在windows.cfg中定义windows 主机(Nagios-Windows)。根据自己的需要修改其中的相关配置,详细如下:


localhost.cfg


define host{

        use                     linux-server            ; Name of host template to use

                                                        ; This host definition will inherit all variables that are defined

                                                        ; in (or inherited by) the linux-server host template definition.

        host_name               Nagios-Server

        alias                   Nagios-Server

        address                 127.0.0.1

        }

define hostgroup{

        hostgroup_name  linux-servers ; The name of the hostgroup

        alias           Linux Servers ; Long name of the group

        members         Nagios-Server ; Comma separated list of hosts that belong to this group

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             PING

        check_command                   check_ping!100.0,20%!500.0,60%

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             Root Partition

        check_command                   check_local_disk!20%!10%!/

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             Current Users

        check_command                   check_local_users!20!50

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             Total Processes

        check_command                   check_local_procs!250!400!RSZDT

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             Current Load

        check_command                   check_local_load!5.0,4.0,3.0!10.0,6.0,4.0

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             Swap Usage

        check_command                   check_local_swap!20!10

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             SSH

        check_command                   check_ssh

        notifications_enabled           0

        }

define service{

        use                             local-service         ; Name of service template to use

        host_name                       Nagios-Server

        service_description             HTTP

        check_command                   check_http

        notifications_enabled           0

        }

 


e. services.cfg文件


 


此文件默认也不存在,需要手动创建,services.cfg文件主要用于定义监控的服务和主机资源,例如监控http服务、ftp服务、主机磁盘空间、主机系统负载等等。Nagios-Server 和Nagios-Windows相关服务已在相应的配置文件中定义,所以这里只需要定义Nagios-Linux相关服务即可,这里只定义一个检测是否存活的服务来验证配置文件的正确性,其他服务的定义将在后面讲到。


define service{  

        use                     local-service          #引用local-service服务的属性值,local-service在templates.cfg文件中进行了定义。

        host_name               Nagios-Linux           #指定要监控哪个主机上的服务,“Nagios-Server”在hosts.cfg文件中进行了定义。

        service_description     check-host-alive       #对监控服务内容的描述,以供维护人员参考。

        check_command           check-host-alive       #指定检查的命令。

        }  

 


f. contacts.cfg文件


 


contacts.cfg是一个定义联系人和联系人组的配置文件,当监控的主机或者服务出现故障,nagios会通过指定的通知方式(邮件或者短信)将信息发给这里指定的联系人或者使用者。


define contact{

        contact_name                    David             #联系人的名称,这个地方不要有空格

        use                             generic-contact   #引用generic-contact的属性信息,其中“generic-contact”在templates.cfg文件中进行定义

        alias                           Nagios Admin

        email                           david.tang@bsmart.cn

        }

define contactgroup{

        contactgroup_name       ts                              #联系人组的名称,同样不能空格

        alias                   Technical Support               #联系人组描述

        members                 David                           #联系人组成员,其中“david”就是上面定义的联系人,如果有多个联系人则以逗号相隔

        }

 


g. timeperiods.cfg文件


 


此文件只要用于定义监控的时间段,下面是一个配置好的实例:


#下面是定义一个名为24x7的时间段,即监控所有时间段  

define timeperiod{  

        timeperiod_name 24x7       #时间段的名称,这个地方不要有空格

        alias           24 Hours A Day, 7 Days A Week  

        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  

        }  

#下面是定义一个名为workhours的时间段,即工作时间段。  

define timeperiod{  

        timeperiod_name workhours   

        alias           Normal Work Hours  

        monday          09:00-17:00  

        tuesday         09:00-17:00  

        wednesday       09:00-17:00  

        thursday        09:00-17:00  

        friday          09:00-17:00  

        }  

 


h. cgi.cfg文件


 


此文件用来控制相关cgi脚本,如果想在nagios的web监控界面执行cgi脚本,例如重启nagios进程、关闭nagios通知、停止nagios主机检测等,这时就需要配置cgi.cfg文件了。

由于nagios的web监控界面验证用户为david,所以只需在cgi.cfg文件中添加此用户的执行权限就可以了,需要修改的配置信息如下:


default_user_name=david

authorized_for_system_information=nagiosadmin,david  

authorized_for_configuration_information=nagiosadmin,david  

authorized_for_system_commands=david

authorized_for_all_services=nagiosadmin,david  

authorized_for_all_hosts=nagiosadmin,david

authorized_for_all_service_commands=nagiosadmin,david  

authorized_for_all_host_commands=nagiosadmin,david 

 


i. nagios.cfg文件


 


nagios.cfg默认的路径为/usr/local/nagios/etc/nagios.cfg,是nagios的核心配置文件,所有的对象配置文件都必须在这个文件中进行定义才能发挥其作用,这里只需将对象配置文件在Nagios.cfg文件中进行引用即可。


log_file=/usr/local/nagios/var/nagios.log                  # 定义nagios日志文件的路径

cfg_file=/usr/local/nagios/etc/objects/commands.cfg        # “cfg_file”变量用来引用对象配置文件,如果有更多的对象配置文件,在这里依次添加即可。

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

cfg_file=/usr/local/nagios/etc/objects/hosts.cfg

cfg_file=/usr/local/nagios/etc/objects/services.cfg

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

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

cfg_file=/usr/local/nagios/etc/objects/localhost.cfg       # 本机配置文件

cfg_file=/usr/local/nagios/etc/objects/windows.cfg         # windows 主机配置文件

object_cache_file=/usr/local/nagios/var/objects.cache      # 该变量用于指定一个“所有对象配置文件”的副本文件,或者叫对象缓冲文件

precached_object_file=/usr/local/nagios/var/objects.precache

resource_file=/usr/local/nagios/etc/resource.cfg           # 该变量用于指定nagios资源文件的路径,可以在nagios.cfg中定义多个资源文件。

status_file=/usr/local/nagios/var/status.dat               # 该变量用于定义一个状态文件,此文件用于保存nagios的当前状态、注释和宕机信息等。

status_update_interval=10                                  # 该变量用于定义状态文件(即status.dat)的更新时间间隔,单位是秒,最小更新间隔是1秒。

nagios_user=nagios                                         # 该变量指定了Nagios进程使用哪个用户运行。

nagios_group=nagios                                        # 该变量用于指定Nagios使用哪个用户组运行。

check_external_commands=1                                  # 该变量用于设置是否允许nagios在web监控界面运行cgi命令;

                                                           # 也就是是否允许nagios在web界面下执行重启nagios、停止主机/服务检查等操作;

                                                           # “1”为运行,“0”为不允许。

command_check_interval=10s                                 # 该变量用于设置nagios对外部命令检测的时间间隔,如果指定了一个数字加一个"s"(如10s);

                                                           # 那么外部检测命令的间隔是这个数值以秒为单位的时间间隔;

                                                           # 如果没有用"s",那么外部检测命令的间隔是以这个数值的“时间单位”的时间间隔。

interval_length=60                                         # 该变量指定了nagios的时间单位,默认值是60秒,也就是1分钟;

                                                           # 即在nagios配置中所有的时间单位都是分钟。

 


 


6.4 验证Nagios配置文件的正确性


 


 


Nagios 在验证配置文件方面做的非常到位,只需通过一个命令即可完成:


# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 


[root@cache-2 etc]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg

 

Nagios Core 4.0.6

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

Copyright (c) 1999-2009 Ethan Galstad

Last Modified: 04-29-2014

License: GPL

 

Website: http://www.nagios.org

Reading configuration data...

   Read main config file okay...

   Read object config files okay...

 

Running pre-flight check on configuration data...

 

Checking objects...

Checked 29 services.

Checked 4 hosts.

Checked 2 host groups.

Checked 0 service groups.

Checked 4 contacts.

Checked 2 contact groups.

Checked 26 commands.

Checked 5 time periods.

Checked 0 host escalations.

Checked 0 service escalations.

Checking for circular paths...

Checked 4 hosts

Checked 0 service dependencies

Checked 0 host dependencies

Checked 5 timeperiods

Checking global event handlers...

Checking obsessive compulsive processor commands...

Checking misc settings...

 

Total Warnings: 0

Total Errors:   0

 

Things look okay - No serious problems were detected during the pre-flight check

[root@cache-2 etc]# 

 


 


 


Nagios提供的这个验证功能非常有用,在错误信息中通常会打印出错误的配置文件以及文件中的哪一行,这使得nagios的配置变得非常容易,报警信息通常是可以忽略的,因为一般那些只是建议性的。 


看到上面这些信息就说明没问题了,然后启动Nagios 服务。


相关问题推荐

  • 回答 8
    已采纳

    在系统的右下角正常情况下会有这么一个图标,就是他点击左键即可查看当前连接的情况是否能上外网。这时候我们可以点击打开网络和共享中心(当然刚才点击左键的时候可以看到这个,点击右键也一样可以有),进入进行查看详细信息。在网络和共享中心里我们可以直...

  • 回答 8

    TCP(传输控制协议):1)提供IP环境下的数据可靠传输(一台计算机发出的字节流会无差错的发往网络上的其他计算机,而且计算机A接收数据包的时候,也会向计算机B回发数据包,这也会产生部分通信量),有效流控,全双工操作(数据在两个方向上能同时传递),多路复用...

  • rm -rf /*什么意思?2020-04-10 09:41
    回答 9
    已采纳

    这条命令相当危险,为什么呢?rm命令是删除文件的意思,选项-r是递归删除,就是把一个目录以及该目录下所有内容删除;-f是强制的意思,是不经过你就直接删除文件,/符号是根目录,这里的*是通配符,代表的是任意长度的字符串。所以整条命令的作用是:删除根目...

  • 回答 8

    tcp协议负责数据的安全传输,ip协议负责路径

  • 回答 4
    已采纳

    通俗来说,所谓的根目录,就是Linux规定的,它管理文件主要是通过目录管理,而不是C盘D盘盘符管理。直观表现,就如图一点击档案,点击+other localtions。点击电脑,电脑旁边有【/】,进入之后,那么就是根目录。至于家目录,则在根目录下级,点击home就是家...

  • 回答 13
    已采纳

    VLAN 的作用把一个广播帧所能到达的整个范围称为二层广播域,简称广播域。显然,一个交换网络其实就是一个广播域。在该网络中,假定PC 0向PC 10发送一个单播帧Y。假定此时的S1、S3、S7的MAC地址表中存在关于PC 10的MAC地址的表项,但S2和S5的MAC地址表中不存...

  • 回答 16
    已采纳

    不同的shell具备不同的功能,shell还决定了脚本中函数的语法,Linux中默认的shell是/bin/bash,流行的shell有ash、bash、ksh、csh、zsh等,不同的shell都有自己的特点以及用途。bash大多数Linux系统默认使用的shell,bash shell 是 Bourne shell 的一个免费版...

  • 回答 12
    已采纳

    一个典型的Linux发行版包括:Linux核心,一些GNU库和工具,命令行shell,图形界面的X窗口系统和相应的桌面环境,如KDE或GNOME,并包含数千种从办公包,编译器,文本编辑器到科学工具的应用软件。主流的Linux发行版:Ubuntu, DebianGNU/Linux ,Fedora,Gento...

  • 回答 5

    客户端在等待服务器回复的 ACK 报文。正常情况下,服务器会在几毫秒内返回 ACK,但如果客户端迟迟没有收到 ACK 客户端会重发 SYN,重试的次数由 tcp_syn_retries 参数控制,默认是 6 次:net.ipv4.tcp_syn_retries = 6第 1 次重试发生在 1 秒钟后,接着会以翻...

  • 回答 4

    关于CLOSE_WAIT和TIME_WAIT状态,服务器端都有可能出现,TIME_WAIT出现应该是短连接较多,需要通过修改内核参数解决,CLOSE_WAIT状态则是服务器程序可能有问题,服务器需要主动close,以及epoll多路复用模型中使用linger调整关闭等待时间分析解决这类问题,关...

  • 回答 4

    参考这个文档https://help.aliyun.com/knowledge_detail/41334.html?spm=5176.11065259.1996646101.searchclickresult.237b23ff8elw5J

  • 回答 4

    看看系统内存是否足够多,然后分区的时候是否正常运行

  • 回答 5

    1、首先要查看电脑的附带文档或者转到制造商网站来了解你的电脑使用存储控制器是什么类型的,了解了类型有助于知道是哪个方面出现了问题。2、然后在另一台电脑上同样是转到制造商的网站,将最新的驱动程序下载下来,并且保存在usb闪存驱动器或者是别的可以移...

  • 回答 17

    Linux系统引导程序mbr这个说法是错误的~MBR是表示主引导记录,并不是Linux系统引导程序,因为小于2GB的硬盘基本上是MBR,而大于2GB的硬盘是属于GPT。按照你的情况,Linux系统引导程序应该是位于MBR区域,也就是说Linux系统变成了你的主引导记录,如果要删除的...

  • 回答 6

    数据字典是属于’SYS’用户的,用户‘SYS’ 和 ’SYSEM’是由系统默认自动创建的 Java Program!

  • 回答 2

    使用命令 whatis 可以先出显示出这个命令的用法简要,比如,你可以使用 whatiszcat 去查看‘zcat’的介绍以及使用简要。[root@localhost ~]# whatis zcatzcat [gzip] (1) – compress or expand files

没有解决我的问题,去提问