六、pnp4nagios 安装:
./configure --prefix=/usr/local/pnp4nagios --with-nagios-user=nagios --with-nagios-group=nagios
make all
make install
make install-webconf
make install-config
make install-init
cd /usr/local/pnp4nagios/etc/
mv misccommands.cfg-sample misccommands.cfg
mv nagios.cfg-sample nagios.cfg
mv rra.cfg-sample rra.cfg
cd pages/
mv web_traffic.cfg-sample web_traffic.cfg
cd ../check_commands/
mv *.cfg{-sample,}
mv check_all_local_disks.cfg{-sample,}
mv check_nrpe.cfg{-sample,}
mv check_nwstat.cfg{-sample,}
/etc/init.d/npcd restart
七、nagios于pnp4nagios 结合
vim nagios.cfg
process_performance_data=1
host_perfdata_command=process-host-perfdata
service_perfdata_command=process-service-perfdata
vim commands.cfg
##添加
define command {
command_name process-service-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl
}
define command {
command_name process-host-perfdata
command_line /usr/local/pnp4nagios/libexec/process_perfdata.pl -d HOSTPERFDATA
}
vim templates.cfg
define host {
name host-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$
register 0
}
define service {
name srv-pnp
action_url /pnp4nagios/index.php/graph?host=$HOSTNAME$&srv=$SERVICEDESC$
register 0
}
八、 远程主机和本地主机安装nrpe
./configure --prefix=/usr/local/nrpe
make
make install
vi /etc/rc.local
/diska/mysqldata/bin/mysqld_safe --defaults-file= /mysqldata/my.cnf &
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
vi /usr/local/nrpe/etc/nrpe.cfg
allowed_hosts=127.0.0.1, 192.168.1.157#(监控服务器)
vi /etc/services
nrpe 5666/tcp #NRPE
九、NDOUTILS安装
./configure --prefix=/usr/local/nagios --enable-mysql LDFLAGS=-L/usr/local/mysql/lib --with-ndo2db-user=nagios --with-ndo2db-group=nagios
Make 出错
In file included from io.c:11:
../include/config.h:261:25: error: mysql/mysql.h: No such file or directory
../include/config.h:262:26: error: mysql/errmsg.h: No such file or directory
make[1]: *** [io.o] Error 1
make[1]: Leaving directory `/nagios/ndoutils-1.5.2/src'
make: *** [all] Error 2
vi include/config.h.in
#include <mysql/mysql.h>
#include <mysql/errmsg.h>
修改为
#include </usr/local/mysql/include/mysql.h>
#include </usr/local/mysql/include/errmsg.h
数据库生成监控所需要的表:
mysql -uroot -pmysql -e "create database nagios;"
mysql -uroot -pmysql nagios< /nagios/ndoutils-1.5.2/db/mysql.sql
# cp ./src/ndomod-3x.o /usr/local/nagios/bin
# cp ./src/ndo2db-3x /usr/local/nagios/bin
# cp ./src/log2ndo /usr/local/nagios/bin
# cp ./src/file2sock /usr/local/nagios/bin
# chown nagios:nagios /usr/local/nagios/bin/*
# cp ./config/ndo* /usr/local/nagios/etc/
# chown nagios:nagios /usr/local/nagios/etc/*
mv ndo2db.cfg{-sample,}
mv ndomod.cfg{-sample,}
vi /usr/local/nagios/etc/ndo2db.cfg
db_name=nagios
db_user=root
db_pass=mysql
vi /usr/local/nagios/etc/nagios.cfg
broker_module=/usr/local/nagios/bin/ndomod-3x.o config_file=/usr/local/nagios/etc/ndomod.cfg
event_broker_options=-1
重启nagios,启动ndo2db
# /usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg
# echo '/usr/local/nagios/bin/ndo2db-3x -c /usr/local/nagios/etc/ndo2db.cfg' >> /etc/rc.local 开机自动启动
vi ndo2db.cfg
socket_type=tcp
vim ndomod.cfg
output_type=tcpsocket
output=127.0.0.1
修改ndo2db.cfg ndomod.cfg属性为nagios
查看nagios.log日志,是否启动成功。
[1352735582] ndomod: Successfully connected to data sink. 0 queued items to flush.
[1352735582] Event broker module '/usr/local/nagios/bin/ndomod-3x.o' initialized successfully.
[1352735582] Finished daemonizing... (New PID=14849)
十、添加监控主机:(chenck_system为自写脚本,可监控disk|mem|cpu|swap|load|ping)
1、host158.cfg
define host{
use host-pnp
host_name host158
alias host158
contact_groups admins
check_command check-host-alive
max_check_attempts 5
notification_interval 10
notification_period 24x7
notification_options d,u,r
address 192.168.1.158
}
define service{
use generic-service,srv-pnp
host_name host158
service_description load
check_command check_nrpe!check_load!15,10,5 30,25,20
contact_groups admins
}
define service{
use generic-service
host_name host158
service_description disk
check_command check_nrpe!check_system!disk 80 90
contact_groups admins
}
define service{
use generic-service,srv-pnp
host_name host158
service_description memonry
check_command check_nrpe!check_system!mem 95 98
contact_groups admins
}
define service{
use generic-service,srv-pnp
host_name host158
service_description cpu
check_command check_nrpe!check_system!cpu 70 80
contact_groups admins
}
define service{
use generic-service,srv-pnp
host_name host158
service_description swap
check_command check_nrpe!check_system!swap 80 90
contact_groups admins
}
define service{
use generic-service,srv-pnp
host_name host158
service_description PING
check_command check_ping!100.0,20%!500.0,60%
contact_groups admins
}
2、定义监控报警联系人
vim contacts.cfg
define contact{
contact_name nagiosadmin ;
use generic-contact ;
alias Nagios Admin ; service_notification_period 24x7
host_notification_period 24x7
service_notification_options w,u,c,r
host_notification_options d,u,r
service_notification_commands notify-service-by-email
host_notification_commands notify-host-by-email
email [email protected] ;
}
3、 客户端和服务端同时添加nrpe命令
nrpe.cfg文件修改一下内容:
command[check_load]=/usr/local/nagios/libexec/check_load -w $ARG1$ -c $ARG2$
command[check_system]=/usr/local/nagios/ownlibexec/check_system -d $ARG1$ -w $ARG2$ -c $ARG3$
check_system 脚本上传至
/usr/local/nagios/ownlibexec/check_system,修改文件属性
重启nrpe。
十一、重启nagios,nrpe,检查搭建情况