Nagios——虚拟机性能收集
第一步:安装所需环境
sudo apt-get install apache2
sudo apt-get install libapache2-mod-php5
sudo apt-get install build-essential
验证apache2的安装是否成功:
打开浏览器输入http://localhost/index.html
然后,在/var/www/ 目录下创建一个index.php文件
打开并编辑:
<html><body>
<?php
phpinfo();
?>
</body></html>保存退出
重启apache2#/etc/init.d/apache2 restart
再打开地址栏输入:http://localhost/index.php
如出现蓝色的php信息列表单则表示,以上三个安装成功
第二步:编辑nagios用户与组别
sudo -s 如果以root用户进入则不需要输入sudo -s
/usr/sbin/useradd -m -s /bin/bash nagios
passwd nagios(生成组密码)
/usr/sbin/groupadd nagios(会有提示已经存在?!)这步骤无需执行
/usr/sbin/usermod -G nagios nagios
/usr/sbin/groupadd nagcmd
/usr/sbin/usermod -a -G nagcmd nagios
/usr/sbin/usermod -a -G nagcmd www-data
第三步:安装nagios(3.3.1)
Nagios所需要的组件已经存放在/root/performance_collect
#cd /root/ performance_collect
#tar zvxf nagios-3.2.3.tar.gz
#cd nagios/
# ./configure --prefix=/usr/local/nagios
--with-nagios-user=nagios --with-nagios-group=nagios
#make all
(在make install之前必须输入以下两句话)
sed -i 's:for file in includes/rss/\*;:for file in includes/rss/\*.\*;:g' ./html/Makefile
sed -i 's:for file in includes/rss/extlib/\*;:for file in includes/rss/extlib/\*.\*;:g' ./html/Makefile
#make install
#make install-init
#make install-commandmode
#make install-config
#make install-webconf
make install-exfoliation 红色的2个标示不用安装
make install-classicui
第四步:安装nagios-plugins(1.4.15)
Install nagios-plugins
#cd ..
#tar zvxf nagios-plugins-1.4.15.tar.gz
#cd nagios-plugins-1.4.15
# cd nagios-plugins-1.4.15
# ./configure --prefix=/usr/local/nagios
#make all
#make install
第五步:安装RRDtool(1.4.3)
Install rrdtool (已经有下载的包)
#cd ..
#tar zvxf rrdtool-1.4.3
#cd rrdtool-1.4.3
#./configure 默认是装在/opt目录下的,可以修改configure更换目录
此处提示缺少7个组件,需要补充:
apt-get install libxml2-dev
apt-get install libcairo2-dev
apt-get install libglib2.0-dev
apt-get install libpango1.0-dev
#make
#make install
第六步:安装pnp4nagios(0.6.12)
Install PNP4nagios plugins with nagios
#cd ..
#tar zvxf pnp4nagios-0.6.11.tar.gz
# mv pnp4nagios-0.6.11 pnp4nagios
# cd pnp4nagios
#./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios --with-rrdtool=/opt/rrdtool-1.4.3/bin/rrdtool
# make all
#make install
#make install-webconf
#make install-config
#make install-init
#make fullinstall
第七步:重启和检测已经安装的组件
Change the folder permissions
[root@localhost nrpe]# chown -R nagios.nagios /usr/local/nagios/
[root@localhost local]# chown -R nagios.nagios /usr/local/nrpe/这句暂时不需要,为监测linux虚拟机的。
重启apache2以及nagios
#/etc/init.d/apache2 start
重启nagios需要进行一次检测,指令如下:
#/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
#/etc/init.d/nagios start
Add & Change access nagios web site password:
#htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
>Keqisoft1
>Keqisoft1
第八步:PNP4Nagios与 Nagios 整合
#vi /usr/local/nagios/etc/nagios.cfg
修改并打开下面内容:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
#vi /usr/local/nagios/etc/objects/commands.cfg
把相应部份修改如下:
define command{
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
define command{
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
#vi /usr/local/nagios/etc/objects/templates.cfg
在文件尾添加如下内容:
#Add by HeQiang
define host{
name host-pnp
register 0
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$
}
define service{
name srv-pnp
register 0
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
}
让PNP4Nagios显示图形在nagios的主机中或服务中,加入host-pnp,srv-pnp,如下:
#vi /usr/local/nagios/etc/objects/localhost.cfg
define host{
use linux-server,host-pnp
host_name localhost
alias localhost
address 127.0.0.1
}
define service{ //每个service都要增加srv-pnp的格式
use local-service,srv-pnp
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
重新启动apache2 & nagios
#/etc/init.d/apache2 restart
#/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
#/etc/init.d/nagios restart
删除/usr/local/pnp4nagios/share/install.php,否则不能浏览.
然后,输入地址即可浏览nagios的监控界面
http://10.20.65.50/nagios 访问地址 用户名:nagiosadmin 密码:Keqisoft1
ln -s /etc/init.d/nagios /etc/rcS.d/S99nagios
设置下次开机自动启动
Hubian-nagios 10.20.65.87
To-nagios 10.20.65.114
To-nagios 10.20.65.115
第九步:客户端的操作
①winxp上安装两个程序:NSClient和Spicec_agent
②修改NSC.ini文件;路径为:c:\KQsoft\nsclient++\
记事本打开:(最大化)
第60行:将IP改为cloud的IP(nagios服务端的IP)
第98行:删除开头的“;”,解开注释即打开该端口
保存退出
③重启服务:
开始à管理工具à服务àNSClientpp
右键重启服务
④修改配置文件:
#cd /usr/local/nagios/etc/objects
复制拷贝一份windown.cfg出来,并修改名字如:hubian.cfg
修改hubian.cfg:
Define host{……}中:
第一行尾部就爱上host-pnp
最后一行IP改为pc的IP
所有的host_name 改为 hubian
所有的services 同样格式加上srv-pnp
#vi /usr/local/nagios/etc/nagios.cfg
解注释,第39行,并且把后面的文件名改成hubian.cfg
⑤重启nagios和apache2
#/etc/init.d/apache2 restart(reload)
#/usr/local/nagios/bin/nagios –v /usr/local/nagios/etc/nagios.cfg
#/etc/init.d/nagios restart
⑥在页面键入地址,核查nagios的页面!