×

扫描二维码登录本站

QQ登录

只需一步,快速开始

学习安装Nagios

标签: 暂无标签
来自:网络





最近一段时间,一直在学习有关Nagios监控系统的相关知识。

有关Nagios监控系统,你可以在百度或者google搜索下,那文章是一堆一堆的。让人看起来很简单。但是在实际的搭建过程中,却不是那么回事。下面就把自己在搭建过程的步骤及注意的事项记录下来。
在安装Nagios前,有些软件与套件需要首先安装。具体如下:                nagios安装
PHP、Apache、Net-snmp、gcc、perl-CPAN
其中Apache是nagios打开必须要使用的。因为Nagios监控主要是通过插件来实现的,而插件有包括SNMP方式、NRPE方式。在接下来的几篇文章,都是围绕SNMP方式来进行监测。所以需要安装net-snmp相关组件。
而SNMP方式监测都是通过check_snmp_mem.pl等perl文件来实现的,所以在安装SNMP相关的插件时,需要perl-CPAN的支持。所以需要安装perl-CPAN。
有关perl-CPAN的安装,可以参考我的另外一篇文章《烂泥:perl中CPAN的安装》。
首先,我们来安装相关的软件及套件。我们可以通过yum方式安装,也可以通过编译方式来。因为牵涉的软件及套件比较多,各个软件集套件的依赖比较麻烦,所以建议使用yum方式来安装。
本次实验OS:CentOS 6.6 mini 32bit
Nagios版本是中文版:nagios-cn
本次相关的软件可以到这个地址下载:
http://pan.baidu.com/s/1jGzFtiQ
[url=http://static.oschina.net/uploads/img/201503/13175425_EFn7.jpg][/url]
nagios的运行是在nagios用户下进行的,所以在此之前我们要创建nagios。如下:
useradd nagios
id nagios
[url=http://static.oschina.net/uploads/img/201503/13175426_FcoJ.jpg][/url]
下面我们来使用yum方式安装,如下图:
yum -y install php httpd net-snmp gcc perl-CPAN
[url=http://static.oschina.net/uploads/img/201503/13175427_ThZR.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175428_uJ8J.jpg][/url]
安装完毕后,我们把Nagios的相关软件包上传到Linux服务器上。
具体如何上传,这个我就在此作介绍了。你可以通过FTP、SSH等等都可以,就看你自己喜欢的方式了。
上传完毕后,我们来进行解压。我现在把相关的软件包都放在/home/ilanni目录下,如下图:             开源监控软件
[url=http://static.oschina.net/uploads/img/201503/13175429_OjYP.jpg][/url]
tar -xf nagios-cn-3.2.0.tar.bz2
tar -xf nagios-plugins-2.0.1.tar.gz
tar -xf nagios-snmp-plugins.1.1.1.tgz
[url=http://static.oschina.net/uploads/img/201503/13175430_sfEv.jpg][/url]
解压完毕后,我们来进入nagios-cn-3.2.0目录,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175430_QOIY.jpg][/url]
开始编译nagios,如下图:
./configure --prefix=/usr/local/nagios
/usr/local/nagios表示nagios的安装路径
[url=http://static.oschina.net/uploads/img/201503/13175432_i2Gb.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175433_95EB.jpg][/url]
编译完毕,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175434_9vH1.jpg][/url]
可以看到需要新建用户nagios,系统中如果没有的话。我们现在可以新建用户,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175434_etuH.jpg][/url]
Nagios用户新建完毕后,我们还继续nagios编译后的工作。
继续执行make all ,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175435_w6si.jpg][/url]
make all完毕后,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175436_5iDP.jpg][/url]
我们只需要按照上边的命令执行即可,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175437_TRnJ.jpg][/url]
make install安装nagios的相关程序文件。
[url=http://static.oschina.net/uploads/img/201503/13175438_ypIg.jpg][/url]
make install-init安装nagios启动的初始化脚本。            nagios配置
[url=http://static.oschina.net/uploads/img/201503/13175439_BpgJ.jpg][/url]
make install-commandmode 安装nagios的命令文件。
[url=http://static.oschina.net/uploads/img/201503/13175441_iES9.jpg][/url]
make install-config安装nagios的配置文件。
[url=http://static.oschina.net/uploads/img/201503/13175441_rPcC.jpg][/url]
make install-webconf安装nagios的web配置文件。
注意:如果apache是使用源码安装的话,我们在执行make install-webconf会报错。
此时,我们只需要把sample-config/httpd.conf文件复制到/usr/local/apache2/conf/下,并重命名为nagios.conf即可。在这apache是安装到/usr/local/apache2下。
如下:
cp sample-config/httpd.conf /usr/local/apache2/conf/nagios.conf
ll /usr/local/apache2/conf/
[url=http://static.oschina.net/uploads/img/201503/13175442_S477.jpg][/url]
以上操作之后,我们还需要在/usr/local/apache/conf/httpd.conf 文件中添加 Include conf/nagios.conf。如下:
[url=http://static.oschina.net/uploads/img/201503/13175443_k7Yu.jpg][/url]
注意:include第一个字母大写意。
以上是nagios的安装步骤,下面进行nagios插件的安装。
进入nagios的插件目录,如下图:
[root@ilanni nagios-cn-3.2.0]# cd ../nagios-plugins-2.0.1
[root@ilanni nagios-plugins-2.0.1]# pwd
/home/ilanni/nagios-plugins-2.0.1
[root@ilanni nagios-plugins-2.0.1]# ll
[url=http://static.oschina.net/uploads/img/201503/13175444_Itn8.jpg][/url]
编译插件
./configure --prefix=/usr/local/nagios/
[url=http://static.oschina.net/uploads/img/201503/13175445_vsXp.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175446_Q56m.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175447_yRIA.jpg][/url]
编译完毕,没有报错就可以进行安装。
make
make install
[url=http://static.oschina.net/uploads/img/201503/13175448_Bc1E.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175449_VvyK.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175450_nVfs.jpg][/url]
Nagios与nagios插件基本安装完毕,我们可以查看下。    监控软件
[url=http://static.oschina.net/uploads/img/201503/13175451_xGad.jpg][/url]
插件截图:
[url=http://static.oschina.net/uploads/img/201503/13175452_LDlb.jpg][/url]
如果你仔细看的话,会发现这个插件时没有有关SNMP的。如下图:
[url=http://static.oschina.net/uploads/img/201503/13175453_eHSv.jpg][/url]
下面我们就安装SNMP的插件。切换到nagios_plugins目录,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175454_8i1p.jpg][/url]
注意:SNMP安装之前一定要安装CPAN。有关CPAN的安装,我在文章开头就说过,可以参考我的另外一篇文章《烂泥:perl中CPAN的安装》。
执行install.sh进行安装,如下图:
[url=http://static.oschina.net/uploads/img/201503/13175454_sVgg.jpg][/url]
接下来一路回车即可。
[url=http://static.oschina.net/uploads/img/201503/13175456_clFw.jpg][/url]
安装完毕如下图示:
[url=http://static.oschina.net/uploads/img/201503/13175456_D7yB.jpg][/url]
现在SNMP的插件已经安装完毕,我们来查看下:    nagios实施
[url=http://static.oschina.net/uploads/img/201503/13175457_71ux.jpg][/url]
查看命令是否可以使用:
[url=http://static.oschina.net/uploads/img/201503/13175459_6fJt.jpg][/url]
通过上图可以看到,snmp插件已经可以正常使用。
下面我们把nagios加入到系统的服务中,如下:
chkconfig --add nagios
chkconfig nagios on
chkconfig --list nagios
[url=http://static.oschina.net/uploads/img/201503/13175459_3Zwp.jpg][/url]
在开始启动nagios之前,我们还要为nagios配置登录的用户名和密码。
有关nagios登录的用户名和密码,我们可以查看nagios.conf文件,如下:
cat nagios.conf |grep -v ^#|grep -v ^$
[url=http://static.oschina.net/uploads/img/201503/13175500_AdUP.jpg][/url]
通过上图,我们可以很明显看出nagios用户存放在/usr/local/nagios/etc/htpasswd.users文件中。
但是如果此时查看htpasswd.users文件会发现该文件是不存在的。
为什么回是这样呢?
这个是因为nagios安装完毕后,需要使用apache的htpasswd工具创建nagios登录的用户。如下:           nagios培训
/usr/local/apache2/bin/htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
[url=http://static.oschina.net/uploads/img/201503/13175501_3vID.jpg][/url]
通过上图,我们可以很明显的看出,htpasswd在创建nagios登录用户的同时,也设置了该用户的密码。
注意:nagios默认的用户名是nagiosadmin。我们可以通过查看/usr/local/nagios/etc/cgi.conf文件得知。如下:
cat cgi.cfg |grep -v ^#|grep -v ^$
[url=http://static.oschina.net/uploads/img/201503/13175502_IiVJ.jpg][/url]
现在我们再来查看htpasswd.users文件,内容如下:
cat /usr/local/nagios/etc/htpasswd.users
[url=http://static.oschina.net/uploads/img/201503/13175502_xBwW.jpg][/url]
nagios用户创建完毕后,我们来启动nagios并登录,如下:
/etc/init.d/nagios start
ps aux |grep nagios
[url=http://static.oschina.net/uploads/img/201503/13175503_uqIG.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175504_v2BI.jpg][/url]
[url=http://static.oschina.net/uploads/img/201503/13175506_h0fK.jpg][/url]
以上安装的nagios中文版,nagios最新版的安装和这个步骤基本一直。
[url=http://static.oschina.net/uploads/img/201503/13175507_ZVlI.jpg][/url]
这个是nagios4.1版本的界面。

nagios4.1的下载地址如下:

至此Nagios的安装已经结束,下篇我们来介绍Nagios的相关配置。





想做Nagios Zabbix,Cacti,iTop各种交流的,可以进入开源监控工具Nagios交流  QQ群号 476809427






上一篇:学习Nagios——Nagios配置
下一篇:解析【Nagios】contacts.cfg
monicazhang

写了 2297 篇文章,拥有财富 12859,被 21 人关注

您需要登录后才可以回帖 登录 | 立即注册
B Color Link Quote Code Smilies

成为第一个吐槽的人

手机版|小黑屋|最新100贴|论坛版块|ITIL先锋论坛 |粤ICP备11099876号|网站地图
Powered by Discuz! X3.4 Licensed  © 2001-2017 Comsenz Inc.
返回顶部