天天看点

nagios 详细的安装及配置!

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

我本地DVD上没有gd-devel,所以我又加一一个163的镜像源 

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378817705KGS4.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378817779fsuT.jpg" target="_blank"></a>

创建一个名为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 

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818187WLPD.jpg" target="_blank"></a>

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818202l4lO.jpg" target="_blank"></a>

cd /root nagios下载目录 

tar xzf nagios-3.4.3.tar.gz

cd nagios 

运行Nagios配置脚本并使用先前开设的用户及用户组: 

./configure --with-command-group=nagcmd

下面这个,我这里没指定

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818205bzTE.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818209Gnkd.jpg" target="_blank"></a>

make all 

make install

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818210noss.jpg" target="_blank"></a>

make install-init

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788182103VPH.jpg" target="_blank"></a>

make install-config 

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818212mZrJ.jpg" target="_blank"></a>

make install-commandmode

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818216bXqn.jpg" target="_blank"></a>

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818302kaMB.jpg" target="_blank"></a>

下面使用的版本与上面不同: 

展开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 &amp;&amp; make install

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818372YRNv.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818394sdLY.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818411z7ME.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818451NWcJ.jpg" target="_blank"></a>

我在这里采用的yum安装!

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818481PLXe.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818506qL0k.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818537RSuY.jpg" target="_blank"></a>

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818566mk6u.jpg" target="_blank"></a>

创建一个nagiosadmin的用户用于Nagios的WEB接口登录。记下你所设置的登录口令,一会儿你会用到它。 

htpasswd -c /usr/local/nagios/etc/htpasswd nagiosadmin #密码123456

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818574ynIN.jpg" target="_blank"></a>

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

service httpd restart

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818578yjMT.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788185810ucc.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818585xVxh.jpg" target="_blank"></a>

启动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.

界面:

<a href="http://192.168.1.104:1080/nagios/" target="_blank">http://192.168.1.104:1080/nagios/</a>

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

<a href="http://blog.51cto.com/attachment/201309/211524500.jpg" target="_blank"></a>

这时,监控端已配置好:

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818594rJFo.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818597yyrO.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818601VmtP.jpg" target="_blank"></a>

Apache重启才能生效!

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186034yg0.jpg" target="_blank"></a>

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

SELINUX=disabled

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

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

tar xvf nrpe-2.13.tar.gz 

cd nrpe-2.13 

./configure 

make all &amp;&amp; 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$ 

}

定义主机:

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818608WuyO.jpg" target="_blank"></a>

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186130M9e.jpg" target="_blank"></a>

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

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818616kMpb.jpg" target="_blank"></a>

/etc/init.d/nagios restart

看到界面如下:

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818621e1O9.jpg" target="_blank"></a>

定义相应的服务:

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;

service_description load;

check_command check_nrpe!check_load;

service_description disk;

check_command check_nrpe!check_disk;

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)

写完后,进行验证:

然后记着重启nagios

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_13788186256B9Z.jpg" target="_blank"></a>

出现上面:

在被监控端192.168.1.106:

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_137881862886HZ.jpg" target="_blank"></a>

在监控端:

[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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818631adTF.jpg" target="_blank"></a>

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818636WZrn.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818639UQng.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_137881864119pA.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818644488O.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818647tKVx.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818652oh3w.jpg" target="_blank"></a>

在被监控机上:

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818656ii7U.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818659o77D.jpg" target="_blank"></a>

在这里,我的操作如下: 

groupadd nagios 

useradd -g nagios -d /usr/local/nagios -s /sbin/nologin nagios 

cd /tmp/ 

tar xvf nagios-plugins-1.4.16.tar.gz 

./configure --with-nagios-user=nagios --with-nagios-group=nagios --enable-redhat-pthread-workaround 

make &amp;&amp; make install 

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818659wSv2.jpg" target="_blank"></a>

tar xvfz nrpe-2.13.tar.gz 

make install-plugin 

make install-daemon 

make install-daemon-config 

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818661pHC7.jpg" target="_blank"></a>

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818663kQe7.jpg" target="_blank"></a>

具体操作如下:

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

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818665DtJh.jpg" target="_blank"></a>

可以在/etc/services结尾增加: 

echo 'nrpe 5666/tcp # NRPE' &gt;&gt; /etc/services 

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818668gOKa.jpg" target="_blank"></a>

/usr/local/nagios/libexec/check_nrpe -H localhost 

NRPE v2.13

<a href="http://guojiping.blog.51cto.com/attachment/201309/10/5635432_1378818671Wpx4.jpg" target="_blank"></a>

更改 /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 ' &gt;&gt; /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' &gt;&gt; /etc/rc.local 

9)验证nrpe是否监听 

netstat -tanp | grep nrpe

上述部分参考截图来自:

《高性能Linux服务器构建实战:运维监控、性能调优与集群应用%28完整%29.pdf》

本文转自 gjp0731 51CTO博客,原文链接:http://blog.51cto.com/guojiping/1293933

继续阅读