主监控机设置:
1、安装epel
# cat /etc/issue
CentOS release 6.0 (Final)
Kernel \r on an \m
# rpm -ivh http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
2、安装nagios、nagios-plugin与nrpe (nagios 3.3.1版本)
# yum install nagios nagios-plugins nagios-plugins-all nagios-plugins-nrpe nrpe
3、创建一个nagiosadmin 的用户用于Nagios的WEB接口登录,用户认证配置
# htpasswd /etc/nagios/passwd nagiosadmin
New password:
Re-type new password:
Adding password for user nagiosadmin
4、修改nagios.conf
修改保存用户密码文件
AuthUserFile /etc/nagios/passwd 修改成--> AuthUserFile /etc/nagios/htpasswd.users
保存退出
5、,要改变nagios所在目录rw的权限,命令如下。
先找出目录find / -name nagios
查看权限命令ls -l /usr/lib/nagios
非系统目录则添加rw权限
chown nagios.nagios /etc/logrotate.d/nagios
chmod g+w /etc/logrotate.d/nagios
chown -R nagios.nagios /etc/nagios
最后重起nagios:
/etc/init.d/nagios restart
再去更新设置,就能成功了!
6、启动apache与nagios
# /etc/init.d/httpd restart
# /etc/init.d/nagios start
7、登陆http://localhost/nagios/,输入用户密码后查看是否正常运行
注:别忘记了nagios后面那个/,不然……
发现iptables没加相应的端口
vi /etc/sysconfig/iptables
编辑一下,添加相应的端口;
service iptables restart
现在可以访问了;
--------------------------------------------------
--------------------------------------------------
被监控机设置:
1、安装需要软件
# yum install nagios-plugins nagios-plugins-nrpe nrpe
2、配置nrpe
# vi /etc/nagios/nrpe.cfg 修改监控机的地址或域名
allowed_hosts=127.0.0.1,192.168.5.11
3、修改/etc/hosts.allow增加监控机ip
# echo 'nrpe:192.168.5.22' >> /etc/hosts.allow
4、检查 NRPE 是否正常:
# /usr/lib/nagios/plugins/check_nrpe -H 192.168.5.11
NRPE v2.12
查看相应的端口:netstat -an |grep 5666
防火墙开启5666 允许局域网IP或固定IP连接
5、启动 NRPE 守护进程:
# /usr/sbin/nrpe -c /etc/nagios/nrpe.cfg -d
在回到监控机:
添加nrpe的定义
# vi commands.cfg
# 'check_nrpe' command definition
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
增加主机监控配置项11.cfg
define host{
use linux-server
host_name 192.168.5.11
alias 192.168.5.11
address 192.168.5.11
}
define service{
use generic-service
host_name 192.168.5.11
service_description load
check_command check_nrpe!check_load
}
define service{
use generic-service
host_name 192.168.5.11
service_description PING
check_command check_ping!100.0,20%!200.0,50%
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.5.11
service_description FTP
check_command check_ftp!21
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.5.11
service_description SSH
check_command check_ssh
max_check_attempts 5
normal_check_interval 1
}
define service{
use generic-service
host_name 192.168.5.11
service_description HTTP
check_command check_http
max_check_attempts 5
normal_check_interval 1
}
并把11.cfg添加到nagios主配置项
# echo "cfg_file=/etc/nagios/objects/11.cfg" >> /etc/nagios/nagios.cfg
其他机器如法炮制即可