tar zxvf nagios-3.2.3.tar.gz
cd nagios-3.2.3
./configure --prefix=/usr/local/nagios --with-command-group=nagcmd && make all && make install && make install-init && make install-config && make install-commandmode && make install-webconf
cd ..
tar xvf nagios-plugins-1.4.15.tar.gz
cd nagios-plugins-1.4.15
./configure --with-nagios-user=nagios --with-nagios-group=nagios && make && make install && cd ..
tar xvf nagios-cn-3.2.3.tar.bz2
cd nagios-cn-3.2.3
./configure && make all && make install && cd ..
5、启动npcd服务并设置为开机启动
service npcd start
chkconfig npcd on
6、修改nagios.cfg文件
cd /usr/local/nagios/etc
vi nagios.cfg
修改配置如下:
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
:wq
7、修改commands.cfg文件
cd /usr/local/nagios/etc/objects
vi commands.cfg
修改process-host-perfdata和process-service-perfdata为:
#'process-host-perfdata' command definitio
define command{
command_name process-host-perfdata
command_line /usr/bin/perl /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
8、修改模板,添加小太阳镶嵌在nagios页面上
vi templates.cfg
在最后添加:
define host{
name host-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=_HOST_
register 0
}
define service{
name srv-pnp
action_url /pnp4nagios/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
:wq
9、修改主机配置文件:
[root@localhost ~]# cat /usr/local/nagios/etc/objects/localhost.cfg |grep -v "#" |sed /^$/d
define host{
use linux-server,host-pnp ; 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 localhost
alias localhost
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 localhost ; Comma separated list of hosts that belong to this group
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description PING
check_command check_ping!100.0,20%!500.0,60%
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Root Partition
check_command check_local_disk!20%!10%!/
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Current Users
check_command check_local_users!20!50
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description Total Processes
check_command check_local_procs!250!400!RSZDT
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
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,srv-pnp ; Name of service template to use
host_name localhost
service_description Swap Usage
check_command check_local_swap!20!10
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description SSH
check_command check_ssh
notifications_enabled 0
}
define service{
use local-service,srv-pnp ; Name of service template to use
host_name localhost
service_description HTTP
check_command check_http
notifications_enabled 0
}
10、删除instal.php
cd /usr/local/pnp4nagios/share
rm -f install.php
12、无误后重启nagios和httpd 服务
service nagios restart
service httpd restart
最后登录nagios控制台,选择host--主机名旁边的小太阳,即可看到图形界面!大功告成!
好的至此 nagios监控端安装软件完成
下面安装cacti
cacti 是基于snmp的
所以配置安装snmp(net-snmp)
vim /etc/snmp/snmpd.conf 修改如下:
重启snmp服务器
/etc/init.d/snmpd restart
chkconfig snmpd on
tar zxvf cacti-0.8.7e.tar.gz
mv cacti-0.8.7e /var/www/html/cacti
修改cacti连接数据库的配置文件
vim /var/www/html/cacti/include/config.php
好的 我们需要创建一个cacti数据库设置密码 给予权限
>create database cacti;
>grant all privileges on cacti.* to cacti@localhost identified by 'cacti' with grant option;
>grant all privileges on cacti.* to cacti@127.0.0.1 identified by 'cacti' with grant option;
>use cacti;
>source /var/www/html/cacti/cacti.sql;
>exit
整合cacti+nagios
整合cacti和nagios是利用了cacti的一个插件nagios for cacti,它的原理是将nagios的数据通过ndo2db导入到mysql数据库(cacti的库中),然后cacti读取数据库信息将nagios的结果展示出来。
1、安装ndoutils
tar xvf ndoutils-1.4b7.tar.gz
cd ndoutils-1.4b7
./configure --with-mysql-lib=/usr/lib/mysql/ --with-mysql-inc=/usr/include/mysql/
make
cd src/
cp ndomod-3x.o /usr/local/nagios/bin/.
cd ndo2db-3x /usr/local/nagios/bin/ndo2db
cd ../config
cp ndo2db.cfg /usr/local/nagios/etc/
cp ndomod.cfg /usr/local/nagios/etc/
cd /usr/local/nagios/etc/
chown nagios:nagios ndo2db.cfg ndomod.cfg
cd ../bin/
chown nagios:nagios ndo2db ndomod-3x.o