分类: 系统运维
2013-02-26 11:13:35
测试的为两台虚拟机
vm linux1:192.168.1.122 //作为监控主机
vmlinux2:192.168.1.192 //作为被监控的主机
首先是被监控主机的
[root@localhost ~]# ls nagios-plugins-1.4.15.tar.gz //安装nagios的套件
nagios-plugins-1.4.15.tar.gz
[root@localhost ~]# tar zxvf nagios-plugins-1.4.15.tar.gz
[root@localhost nagios-plugins-1.4.15]# useradd -s /sbin/nologin nagios
[root@localhost nagios-plugins-1.4.15]# ./configure
[root@localhost nagios-plugins-1.4.15]# make;make install
[root@localhost nagios-plugins-1.4.15]# cd /usr/local/
[root@localhost local]# chown nagios:nagios nagios/
[root@localhost local]# chown nagios:nagios -R nagios/libexec/
[root@localhost ~]# ls nrpe-2.8b1.tar.gz //这里就是安装配置nrpe的部分
nrpe-2.8b1.tar.gz
[root@localhost ~]# tar zxvf nrpe-2.8b1.tar.gz
[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
当然啦,你如果英语不错的话,直接参考分包内的说明安装(以下)
[root@localhost nrpe-2.8b1]# ll NRPE.pdf
-rw-rw-r-- 1 nagios nagios 212236 Mar 14 2007 NRPE.pdf
[root@localhost ~]# cd /usr/local/nagios/etc/
[root@localhost etc]# vi nrpe.cfg //修改主配置档
server_address=192.168.1.192 //被监控主机ip
allowed_hosts=127.0.0.1,192.168.1.122,192.168.1.192 //这里是监控主机的设置,为了检测使用,本机的ip也加上
[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d //启动nrpe这个守护进程
[root@localhost etc]# netstat -tulnp|grep 5666
tcp 0 0 192.168.1.192:5666 0.0.0.0:* LISTEN 3384/nrpe
[root@localhost etc]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.192 //nrpe是否正常工作时的检测
NRPE v2.8b1
[root@localhost etc]# vi nrpe.cfg //对监控内容的设置,添加以下的部分
command[check_users1]=/usr/local/nagios/libexec/check_users -w 5 -c 10 //要重点记住那个check_user1,以为在监控端要引用
command[check_load1]=/usr/local/nagios/libexec/check_load -w 15,10,5 -c 30,25,20
command[check_hda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/hda1
command[check_zombie_procs1]=/usr/local/nagios/libexec/check_procs -w 5 -c 10 -s Z
command[check_total_procs1]=/usr/local/nagios/libexec/check_procs -w 150 -c 200
command[check_ping81]=/usr/local/nagios/libexec/check_ping -H 10.155.0.1 -w 100.0,20% -c 500.0,60%
command[check_sda1]=/usr/local/nagios/libexec/check_disk -w 20 -c 10 -p /dev/sda1
[root@localhost etc]# ps aux|grep nrpe //重启服务,客户端的设置就结束啦
nagios 3384 0.0 0.3 5072 928 ? Ss 01:06 0:00 /usr/local/nagios/bin/nrpe -c /usr/
local/nagios/etc/nrpe.cfg -d
root 3404 0.0 0.2 4000 672 pts/0 R+ 01:11 0:00 grep --color=auto nrpe
[root@localhost etc]# kill -9 3384
[root@localhost etc]# /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
下边是监控主机的设置(这个监控主机是在先前配置的nagios服务器基础之上的)
[root@localhost ~]# ls nrpe-2.8b1.tar.gz //安装nrpe的套件
nrpe-2.8b1.tar.gz
[root@localhost ~]# tar zxvf nrpe-2.8b1.tar.gz
[root@localhost nrpe-2.8b1]# ./configure
[root@localhost nrpe-2.8b1]# make all
[root@localhost nrpe-2.8b1]# make install-plugin //通过这个命令把check_nrpe这个插件安装到插件的默认目录
[root@localhost nrpe-2.8b1]# cd
[root@localhost ~]# /etc/init.d/nagios restart
[root@localhost ~]# /usr/local/nagios/libexec/check_nrpe -H 192.168.1.192 //对被监控主机的连接测试,出现以下的版本号就OK啦
NRPE v2.8b1
[root@localhost ~]# cd /usr/local/nagios/etc/objects/
[root@localhost objects]# vi commands.cfg //添加nrpe的全局命令
define command{
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
[root@localhost objects]# vi services.cfg //添加对主机的监控
#################### NRPE ###################################
define service{
use local-service
host_name mysql
service_description users
check_command check_nrpe!check_users1 //这个名字就是之前要求记忆的啦,万万不可写错了
}
define service{
use local-service
host_name mysql
service_description load
check_command check_nrpe!check_load1
}
#################################### #####################################
define servicegroup{ //同时加入组中
servicegroup_name servicegroup
alias service-group
members
web,PING,web,SSH,web,SSHD,web,http,mysql,PING,mysql,SSH,mysql,ftp,mysql,mysqlport,mysql,load,mysql,disk,mysql,users,mysql,load,mysql,process
}
这样配置就结束啦
最后的测试 //在被测试端,打开相应的服务
[root@localhost ~]# /usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg //检查配置有无错误,有误根据提示修改
[root@localhost ~]# iptables -F
[root@localhost ~]# /etc/init.d/httpd restart
[root@localhost ~]# /etc/init.d/nagios restart
IE 登录之后,可以看到对远程主机的信息