目录
1 在客户服务器上配置... 1
1.1配置nrpe. 1
1) 加入可以监控该服务器的nagios server端的IP。... 1
2) 注释掉或者干脆删除199-203行即下面几行... 1
2 配置 nagios 监控服务... 1
1)nagios.cfg 基本配置... 1
2)注意:需要注释掉如下localhost.cfg 行,否则和我们要配的会冲突原 36 行... 1
3)需要在host.cfg 里添加客户端主机和主机组(HOST GROUP)... 1
4)同理添加要监控的服务配置到service.cfg. 1
5)重启服务... 1
3 错误整理... 1
1)错误1. 1
2)错误2:... 1
3)问题3. 1
4)问题4. 1
1 在客户服务器上配置
1.1配置nrpe
cd /usr/local/nagios/etc
#config nrpe.cfg
vi nrpe.cfg +79
1) 加入可以监控该服务器的nagios server端的IP。
allowed_hosts=127.0.0.1,172.16.1.196,172.16.1.190 ←主机的IP
2) 注释掉或者干脆删除199-203行即下面几行
shift+g到结尾
#command[check_users]=/usr/local/nagios/libexec/check_users-w $ARG1$ -c $ARG2$
#command[check_load]=/usr/local/nagios/libexec/check_load-w $ARG1$ -c $ARG2$
#command[check_disk]=/usr/local/nagios/libexec/check_disk-w $ARG1$ -c $ARG2$ -p $ARG3$
#command[check_procs]=/usr/local/nagios/libexec/check_procs-w $ARG1$ -c $ARG2$ -s $ARG3$
同时在下面新添加要监控的内容:
command[check_load]=/usr/local/nagios/libexec/check_load-w 15,10,6 -c 30,25,20
command[check_mem]=/usr/local/nagios/libexec/check_memory.pl-w 6% -c 3%
command[check_disk]=/usr/local/nagios/libexec/check_disk-w 20% -c 8% -p /
command[check_swap]=/usr/local/nagios/libexec/check_swap-w 20% -c 10%
command[check_iostat]=/usr/local/nagios/libexec/check_iostat-w 6 -c 10
或者:
echo"command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c3%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p/">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c10%">>/usr/local/nagios/etc/nrpe.cfg
echo"command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c10">>/usr/local/nagios/etc/nrpe.cfg
1.2启动:nagios client
[root@client01 etc]#
[root@client01 etc]# pkill nrpe
[root@client01etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
[root@client01 etc]# echo"/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">> /etc/rc.local
[root@client01etc]# ps -ef|grep nrpe
nagios 32431 1 0 12:44 ? 00:00:00 /usr/local/nagios/bin/nrpe -c/usr/local/nagios/etc/nrpe.cfg -d
root 32433 32397 0 12:44 pts/0 00:00:00 grep nrpe
[root@client01 etc]#
注意:
1、#执行完启动命令,进行检查是个良好的习惯
2、tips:重起nagios nrpe组合命令
pkillnrpe && /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
1.3 关闭防火墙
测试环境,建议最好先把iptables关掉,等nagios都测试通了在来调试iptables,否则给学习测试增加了复杂度。
关闭命令
/etc/init.d/iptablesstop
2 配置 nagios 监控服务
以下为server 端的操作
1)nagios.cfg 基本配置
在 nagios.cfg 文件中找到cfg_file 的部分,进行如下设置:
[root@nagios-server etc]# vi/usr/local/nagios/etc/nagios.cfg +34
# You can specify individualobject config files as shown below:
cfg_file=/usr/local/nagios/etc/objects/commands.cfg
cfg_file=/usr/local/nagios/etc/objects/contacts.cfg
cfg_file=/usr/local/nagios/etc/objects/timeperiods.cfg
cfg_file=/usr/local/nagios/etc/objects/templates.cfg
cfg_file=/usr/local/nagios/etc/objects/services.cfg
cfg_file=/usr/local/nagios/etc/objects/hosts.cfg
2)注意:需要注释掉如下localhost.cfg行,否则和我们要配的会冲突原 36 行
# Definitions for monitoring the local (Linux) host
#cfg_file=/usr/local/nagios/etc/objects/localhost.cfg
3)需要在host.cfg 里添加客户端主机和主机组(HOSTGROUP)
[root@nagios-serveretc]# cd /usr/local/nagios/etc/objects/
[root@nagios-server objects]# vihosts.cfg
# Define a host for the local machine
define host{
use linux-server
host_name 18-client01
alias 18-client01
address 192.168.1.18
}
define host{
use linux-server
host_name 19-nagios_server
alias 19-nagios_server
address 192.168.1.19
}
define hostgroup{
hostgroup_name linux-servers ; The name of the hostgroup
alias Linux Servers ; Long name of thegroup
members 18-client01,19-nagios_server
}
4)同理添加要监控的服务配置到service.cfg
[root@nagios-serverobjects]# cd /usr/local/nagios/etc/objects/
[root@nagios-serverobjects]# vi services.cfg
define service {
use generic-service
host_name 18-client01
service_description Disk Partition
check_command check_nrpe!check_disk
}
5)重启服务
[root@nagios-server objects]#/usr/local/nagios/libexec/check_nrpe -H 192.168.l.18 -c check_disk
Invalid host name '192.168.l.18'
[root@nagios-server objects]# ll
[root@nagios-serverobjects]# /etc/init.d/nagios reload
3 错误整理
1)错误1
[root@nagios-server objects]#/etc/init.d/nagios checkconfig
Running configuration check...CONFIG ERROR! Check your Nagiosconfiguration.
[root@nagios-server objects]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
Checking services...
Error: There are no servicesdefined!
Checked 0 services.
Total Warnings: 2
Total Errors: 1
处理方法:
[root@nagios-server objects]# vim/etc/init.d/nagios +178
status)
pid_nagios
# /dev/null 2>&1;
;;
checkconfig)
2)错误2:
[root@nagios-server objects]#/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
问题2:
Checking services...
Error: There are no servicesdefined!
Checked 0 services.
处理方法:
[root@nagios-serverobjects]# vi services.cfg
defineservice {
use generic-service
host_name 18-client01
service_description Disk Partition
check_command check_nrpe!check_disk
}
"services.cfg"8L, 138C written
[root@nagios-server objects]# /etc/init.d/nagioscheckconfig
3)问题3
问题3:
Checking services...
Error: Service check command'check_nrpe' specified in service 'Disk Partition' for host '18-client01' notdefined anywhere!
Checked 1 services.
处理方法:
[root@nagios-serverobjects]# vi commands.cfg
#'check_nrpe' command definition
definecommand{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c$ARG1$
}
4)问题4
打开网页会出现
It appears as though you do not have permission toview information for any of theservices you requested...
解决方法
[root@nagiosserver objects]#cd/usr/local/nagios/etc
[root@nagiosserver objects]#vi cgi.cfg +119
#把在1.6 节建立的用户oldboy 加到后面,注意用逗号隔开。
#default_user_name=oldboy
authorized_for_system_information=nagiosadmin,oldboy
authorized_for_configuration_information=nagiosadmin,oldboy
authorized_for_system_commands=nagiosadmin,oldboy
authorized_for_all_services=nagiosadmin,oldboy
authorized_for_all_hosts=nagiosadmin,oldboy
authorized_for_all_service_commands=nagiosadmin,oldboy
authorized_for_all_host_commands=nagiosadmin,oldboy
记得reload nagios 命令为:/etc/init.d/nagios reload