nagios 详细的安装及配置! http://guojiping.blog.51cto.com/5635432/1293933            

                 

一、安装前的准备

1.下载到核心源码:

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

2.下载插件包nagios-plugins-1.4.16.tar.gz:

http://download.chinaunix.net/download.php?id=26943&ResourceID=7184

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库和开发库

yum install -y httpd php gcc glibc glibc-common gd gd-devel perl make


二、监控端:

1个步骤:

[root@localhost ~]# useradd -s /sbin/nologin nagios
[root@localhost ~]# mkdir /usr/local/nagios
[root@localhost ~]# chown -R nagios.nagios /usr/local/nagios  #提高安全性

创建一个名为nagios的帐号并给定登录口令  
[root@localhost ~]# useradd nagios  
passwd nagios  #密码123456  
      创建一个用户组名为nagcmd用于从Web接口执行外部命令
/usr/sbin/groupadd nagcmd  
/usr/sbin/usermod -G nagcmd nagios  
/usr/sbin/usermod -G nagcmd apache  
nagios安装及配置_nagios

[root@localhost ~]# yum install sendmail –y

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

下面这个,我这里没指定

nagios安装及配置_nagios_02

nagios安装及配置_iOS_03

make all  
make install

nagios安装及配置_iOS_04
make install-init

nagios安装及配置_iOS_05

make install-config  
nagios安装及配置_iOS_06

make install-commandmode

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

nagios安装及配置_nagios_07

现在还不能启动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插件


nagios安装及配置_nagios_08

下面使用的版本与上面不同:  
展开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汉化插件(此步,我跳过了)

nagios安装及配置_iOS_09

nagios安装及配置_iOS_10

4个步骤:

nagios安装及配置_nagios_11

nagios安装及配置_iOS_12

我在这里采用的yum安装!

nagios安装及配置_nagios_13

nagios安装及配置_nagios_14

nagios安装及配置_nagios_15

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

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

nagios安装及配置_nagios_17

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

nagios安装及配置_iOS_18

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

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

nagios安装及配置_nagios_19

nagios安装及配置_iOS_20

nagios安装及配置_iOS_21

启动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 该文件中的用户和密码!

nagios安装及配置_nagios_22

三、中间出现的问题及解决方法:


这时,监控端已配置好:

http://192.168.1.104:1080/nagios/

访问时,却发现,访问不到

nagios安装及配置_iOS_23

nagios安装及配置_nagios_24

nagios安装及配置_nagios_25

Apache重启才能生效!

nagios安装及配置_iOS_26

如果无法访问,查看apache服务是否开启,如果启动不了,查原因,我这里是由于selinux没关闭,导致的,vim /etc/selinux/config 把#SELINUX=enforcing

SELINUX=disabled

如果apache正常,扔无法打开web,则查看iptables

如iptables –F 规则,清理下,ok

四、NEPR监控远程主机


在监控机上安装

cd /root  
tar xvf nrpe-2.13.tar.gz  
cd nrpe-2.13  
./configure  
make all && make install-plugin  
在文件/usr/local/nagios/etc/objects/commands.cfg后面增加:  
# 'check_nrpe' command definition  
define command{  
command_name check_nrpe  
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -t 30 -c $ARG1$  
}

定义主机:

nagios安装及配置_iOS_27

vim /usr/local/nagios/etc/nagios.cfg

nagios安装及配置_iOS_28

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

监测看到如下: 这里有1个警告,是没问题的!

nagios安装及配置_iOS_29

/etc/init.d/nagios restart

看到界面如下:

nagios安装及配置_nagios_30

定义相应的服务:

vim /usr/local/nagios/etc/objects/service.cfg (自己创建的)

[root@root objects]# cat service.cfg

define service{

use generic-service;

host_name test;

service_description users;

check_command check_nrpe!check_users;

}

define service{

use generic-service;

host_name test;

service_description load;

check_command check_nrpe!check_load;

}

define service{

use generic-service;

host_name test;

service_description disk;

check_command check_nrpe!check_disk;

}

define service{

use generic-service;

host_name test;

service_description zombie;

check_command check_nrpe!check_zombie_procs;

}

define servicegroup{

servicegroup_name servergroup;

alias server-group;

members test,users,test,load,test,disk,test,zombie;

}(这个文档对应的是被监控端的vim /usr/local/nagios/etc/nrpe.cfg 中定义的命令,如command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 16)

写完后,进行验证:

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

然后记着重启nagios

nagios安装及配置_nagios_31

出现上面:

在被监控端192.168.1.106:

nagios安装及配置_iOS_32

在监控端:

[root@root objects]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.106 -c check_disk

DISK OK - free space: / 6666 MB (72% inode=95%);| /=2521MB;9188;9488;0;9688

nagios安装及配置_iOS_33

上面的HTTP错误,开放80端口,在httpd.conf中,增加Listen 80,然后,apache服务重启,解决!

nagios安装及配置_nagios_34

nagios安装及配置_nagios_35

nagios安装及配置_nagios_36nagios安装及配置_nagios_37

nagios安装及配置_nagios_38

nagios安装及配置_nagios_39

nagios安装及配置_iOS_40

在被监控机上:

nagios安装及配置_nagios_41

nagios安装及配置_nagios_42

在这里,我的操作如下:  
groupadd nagios  
useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios  
cd /tmp/  
tar xvf nagios-plugins-1.4.16.tar.gz  
cd nagios-plugins-1.4.16  
./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround  
make && make install  
nagios安装及配置_iOS_43
cd /root  
tar xvfz nrpe-2.13.tar.gz  
cd nrpe-2.13  
./configure  
make all  
make install-plugin  
make install-daemon  
make install-daemon-config  
nagios安装及配置_nagios_44
nagios安装及配置_iOS_45

具体操作如下:

更改/usr/local/nagios/etc/nrpe.cfg文件,在参数allowed_hosts后添加监控机ip(多个ip以逗号分隔,目前监控及ip为222.189.237.136,112.84.184.111)

nagios安装及配置_iOS_46

可以在/etc/services结尾增加:  
echo 'nrpe 5666/tcp # NRPE' >> /etc/services  
nagios安装及配置_nagios_47
/usr/local/nagios/libexec/check_nrpe -H localhost  
NRPE v2.13

nagios安装及配置_nagios_48

更改 /usr/local/nagios/etc/nrpe.cfg,把原来command都注释掉  
nrpe.cfg文件里包含需要监控远程主机的命令,如:  
echo '  
command[check_users]=/usr/local/nagios/libexec/check_users -w 10 -c 16  
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20  
command[check_disk]=/usr/local/nagios/libexec/check_disk -w 500 -c 200 -p /  
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z

command[check_cpu_procs]=/usr/local/nagios/libexec/check_procs -w 40 -c 80 -m CPU

command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200 ' >> /usr/local/nagios/etc/nrpe.cfg

7)手工启动  
手工启动方法 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d

8)添加开机启动

echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d' >> /etc/rc.local  
9)验证nrpe是否监听  
netstat -tanp | grep nrpe


---end---