配置被监控机
本文讲述的是:Redhat配置nagios。返回大纲。
配置linux被监控机(客户端)
需要先安装gcc、openssl、openssl-devel。
先添加一个用户
-
[root@localhost ~]# useradd nagios
-
-
[root@localhost ~]# passwd nagios //123456
-
Changing password for user nagios.
New UNIX password:
BAD PASSWORD: it is too simplistic/systematic
Retype new UNIX password:
passwd: all authentication tokens updated successfully.
安装nagios-plugins-1.4.15.tar.gz
-
[root@localhost ~]# tar -zxvf nagios-plugins-1.4.15.tar.gz
-
-
[root@localhost ~]# cd nagios-plugins-1.4.15
-
-
[root@localhost nagios-plugins-1.4.15]# ./configure --prefix=/usr/local/nagios
-
-
[root@localhost nagios-plugins-1.4.15]# make
-
-
[root@localhost nagios-plugins-1.4.15]# make install
-
-
[root@localhost nagios-plugins-1.4.15]# chown nagios.nagios /usr/local/nagios
-
-
[root@localhost nagios-plugins-1.4.15]# chown -R nagios.nagios /usr/local/nagios/libexec
-
安装nrpe
-
[root@localhost ~]# tar -zxvf nrpe-2.8b1
-
-
[root@localhost ~]# cd nrpe-2.8b1
-
-
[root@localhost nrpe-2.8b1]# ./configure
-
-
[root@localhost nrpe-2.8b1]# make all
-
-
[root@localhost nrpe-2.8b1]# make install-plugin
-
-
[root@localhost nrpe-2.8b1]# make install-daemon
-
-
[root@localhost nrpe-2.8b1]# make install-daemon-config
-
编辑nrpe.cfg
-
[root@localhost ~]# vi /usr/local/nagios/etc/nrpe.cfg
-
查找如下加上nagios服务器ip地址
allowed_hosts=127.0.0.1,10.155.2.65
保存后,用如下命令启动nrpe和添加到开机启动中
-
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg –d
-
-
echo '/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d &> /dev/null' >> /etc/rc.local
-
验证
-
[root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H localhost
-
NRPE v2.8b1
-
[root@localhost etc]# netstat -atulnp | grep 'nrpe'
-
tcp 0 0 0.0.0.0:5666 0.0.0.0:* LISTEN 24823/nrpe
如果不正常见文章最后的问题和解决(1)
这里客户端的配置已经完成,已经可以到nagios服务器配置command.cfg监控,但是这里介绍另一种方法在编辑nrpe.cfg配置命令,nagios服务器会调用客户端的nrpe命令
-
vi /usr/local/nagios/etc/nrpe.cfg
-
-
command[check_users]=/usr/local/nagios/libexec/check_users -w 5 -c 10
-
-
command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
-
-
command[check_zombie_procs]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
-
-
command[check_total_procs]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
-
-
command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
-
下面这条是自己添加
-
command[check_ping81]=/usr/local/nagios/libexec/check_ping -H 10.155.0.1 -w 100.0,20% -c 500.0,60%#
-
-
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
-
-
#command[命令名称]=命令定义
-
具体使用见帮助
-
[root@localhost nagios]# ls
-
-
bin etc include libexec share
-
-
[root@localhost nagios]# pwd
-
-
/usr/local/nagios
-
-
[root@localhost nagios]# libexec/check_ping -h
-
-
check_ping v1.4.15 (nagios-plugins 1.4.15)
-
-
Copyright (c) 1999 Ethan Galstad
-
-
Copyright (c) 2000-2007 Nagios Plugin Development Team
-
-
Use ping to check connection statistics for a remote host.
-
-
Usage:
-
-
check_ping -H -w ,% -c ,%
-
-
[-p packets] [-t timeout] [-4|-6]
-
-
Options:
-
-
-h, --help
-
-
Print detailed help screen
-
-
-V, --version
-
-
Print version information
-
-
-4, --use-ipv4
-
-
Use IPv4 connection
-
-
-6, --use-ipv6
-
-
Use IPv6 connection
-
-
-H, --hostname=HOST
-
-
host to ping
-
-
-w, --warning=THRESHOLD
-
-
warning threshold pair
-
-
-c, --critical=THRESHOLD
-
-
critical threshold pair
-
-
-p, --packets=INTEGER
-
-
number of ICMP ECHO packets to send (Default: 5)
-
-
-L, --link
-
-
show HTML in the plugin output (obsoleted by urlize)
-
-
-t, --timeout=INTEGER
-
-
Seconds before connection times out (default: 10)
-
配置nrpe.cfg后,必须重启nrpe。重启方法(杀死进程,在重启),否则更改不会生效
-
[root@localhost ~]# ps aux|grep nrpe
-
-
nagios 3327 0.0 0.0 4880 924 ? Ss Sep02 0:03 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
-
-
root 22293 0.0 0.0 3908 648 pts/0 R+ 11:07 0:00 grep nrpe
-
-
[root@localhost ~]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
-
服务器端
测试与客户端连接,如下表示正常
-
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H 10.155.2.81
-
-
NRPE v2.8b1
-
下面表示不正常,见问题与解决(2)
-
[root@localhost nrpe-2.8b1]# /usr/local/nagios/libexec/check_nrpe -H 10.155.2.81
-
-
Connection refused by host
-
配置nagios.cfg,增加一条记录
-
[root@localhost ~]# vi /usr/local/nagios/etc/nagios.cfg
-
-
cfg_file=/usr/local/nagios/etc/objects/mylinux.cfg
-
-
cfg_file=/usr/local/nagios/etc/objects/commands.cfg ;此前面已经设置过
-
配置nagios.cfg,增加一条记录
-
vi /usr/local/nagios/etc/objects/commands.cfg
-
#在后面增加追加如下内容
#check nrpe
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
mylinux
-
.cfg在目录中没有,需要自己添加
-
[root@localhost ~]# touch /usr/local/nagios/etc/objects/mylinux.cfg
-
#---------------------------------------------此段定义主机--------------------------------------------------------
-
define host{
-
-
use linux-server
-
-
host_name 10.155.2.81-cacti
-
-
alias mylinux
-
-
address 10.155.2.81
-
-
}
-
#--------------------------------下面定义服务器,也就是监控项------------------------------------------
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description Swap Usage
-
-
check_command check_nrpe!check_swap
-
-
}
-
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description Current Load
-
-
check_command check_nrpe!check_load
-
-
}
-
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description Partition Usage
-
-
check_command check_nrpe!check_hda1
-
-
}
-
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description Current Users
-
-
check_command check_nrpe!check_users
-
-
}
-
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description Total Processes
-
-
check_command check_nrpe!check_total_procs
-
-
}
-
-
define service{
-
-
use generic-service
-
-
host_name 10.155.2.81-cacti
-
-
service_description PING
-
-
check_command check_nrpe!check_ping81
-
-
}
-
重启nagios,ie浏览(图3)
(责任编辑:IT) |