~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
监控一个远程机器
1 使用插件监控远程计算机服务[icmp http snmp]
添加一个远程主机
vim localhost.cfg
define host {
host_name instructor.example.com
alias dell_R510
address 192.168.18.247
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups admins
notification_interval 10 通知间隔
notification_period 24x7
}
添加一个监控服务#注意默认apache没有页面 所以返回值是403 去根目录下写一个index页面就可以了
vim /var/www/html/index.html
hello
vim localhost.cfg
define service {
host_name instructor.example.com
service_description apache
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}
检查错误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
2 编写一个插件监控本机的磁盘IO
脚本返回值 0 成功 1 警告 2 严重错误 3 未知
编写一个插件脚本 iostat -d 频率 1秒一次 2次 第二次取值才是当前的io对列
vim /usr/local/nagios/libexec/check_disk_io
#!/bin/bash
IO_NOW=`iostat -xd 1 2|grep -w [v,s]da|tail -1 |awk '{print $9}'`
IO=`iostat -xd 1 2|grep -w [v,s]da|tail -1 |awk '{print $9*100}'`
if [ $IO -ge 200 ]
then
echo "BUSY IO is $IO_NOW"
exit 2
elif [ $IO -ge 1500 ]
then
echo "WARNING IO is $IO_NOW"
exit 1
else
echo "OK IO is $IO_NOW"
exit 0
fi
chmod 755 check_disk_io
[root@nagios ~]# /usr/local/nagios/libexec/check_disk_io localhost
OK IO is 0.29
定义一个命令
vim commands.cfg
define command {
command_name check_disk_io
command_line $USER1$/check_disk_io $HOSTADDRESS$ -u $ARG1$ -s $ARG2$
}
添加一个服务
vim localhost.cfg
define service {
host_name localhost
service_description disk_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_disk_io
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
使用nrpe监控远端机器
注意 NRPE是安装在被监控端 并且是个服务
#在监控服务器安装nrpe插件 check_nrpe
tar xf nrpe-2.15.tar.gz
cd nrpe-2.15
yum -y install openssl-*
./configure --prefix=/usr/local/nagios
make
make install-plugin 注意看输出会给你的本机的插件库考贝一个check_nrpe的插件
cd ./src/ && make install-plugin
make[1]: Entering directory `/usr/src/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/usr/src/nrpe-2.15/src'
#在被监控机上安装nrpe服务 及插件
tar xf nrpe-2.15.tar.gz
cd nrpe-2.1
yum -y install xinetd
useradd nagios
./configure --prefix=/usr/local/nagios
make
make install-daemon
make install-daemon-config
make install-xinetd
vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1
}
修改only_from 定义监控服务器的IP地址
[root@localhost nrpe-2.15]#vim /etc/services
nrpe 5666/tcp
[root@localhost nrpe-2.15]#service xinetd restart
查看NRPE服务是否启动
[root@localhost nrpe-2.15]# lsof -i :5666
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 7962 root 5u IPv6 205762 0t0 TCP *:nrpe (LISTEN)
安装插件 nagios-plugins-1.5.tar.gz 同上
将插件拷贝到被监控服务器插件库
scp /usr/local/nagios/libexec/check_disk_io 192.168.18.247:/usr/local/nagios/libexec/
添加监控命令
[root@localhost libexec]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_disk_io]=/usr/local/nagios/libexec/check_disk_io -w 2 -c 3
#监控服务器
定义check_nrpe命令 vim commands.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
定义监控远端服务器的内容 定义一个监控服务
define service {
host_name instructor.example.com
service_description DISK_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_disk_io
}
测试命令
[root@nagios libexec]# ./check_nrpe -H 192.168.18.247 -c check_disk_io
OK IO is 0.00
测试监控
监控一个远程机器
1 使用插件监控远程计算机服务[icmp http snmp]
添加一个远程主机
vim localhost.cfg
define host {
host_name instructor.example.com
alias dell_R510
address 192.168.18.247
check_command check-host-alive
notification_options d,u,r
check_interval 1
max_check_attempts 2
contact_groups admins
notification_interval 10 通知间隔
notification_period 24x7
}
添加一个监控服务#注意默认apache没有页面 所以返回值是403 去根目录下写一个index页面就可以了
vim /var/www/html/index.html
hello
vim localhost.cfg
define service {
host_name instructor.example.com
service_description apache
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_http
}
检查错误
/usr/local/nagios/bin/nagios -v /usr/local/nagios/etc/nagios.cfg
2 编写一个插件监控本机的磁盘IO
脚本返回值 0 成功 1 警告 2 严重错误 3 未知
编写一个插件脚本 iostat -d 频率 1秒一次 2次 第二次取值才是当前的io对列
vim /usr/local/nagios/libexec/check_disk_io
#!/bin/bash
IO_NOW=`iostat -xd 1 2|grep -w [v,s]da|tail -1 |awk '{print $9}'`
IO=`iostat -xd 1 2|grep -w [v,s]da|tail -1 |awk '{print $9*100}'`
if [ $IO -ge 200 ]
then
echo "BUSY IO is $IO_NOW"
exit 2
elif [ $IO -ge 1500 ]
then
echo "WARNING IO is $IO_NOW"
exit 1
else
echo "OK IO is $IO_NOW"
exit 0
fi
chmod 755 check_disk_io
[root@nagios ~]# /usr/local/nagios/libexec/check_disk_io localhost
OK IO is 0.29
定义一个命令
vim commands.cfg
define command {
command_name check_disk_io
command_line $USER1$/check_disk_io $HOSTADDRESS$ -u $ARG1$ -s $ARG2$
}
添加一个服务
vim localhost.cfg
define service {
host_name localhost
service_description disk_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_disk_io
}
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
使用nrpe监控远端机器
注意 NRPE是安装在被监控端 并且是个服务
#在监控服务器安装nrpe插件 check_nrpe
tar xf nrpe-2.15.tar.gz
cd nrpe-2.15
yum -y install openssl-*
./configure --prefix=/usr/local/nagios
make
make install-plugin 注意看输出会给你的本机的插件库考贝一个check_nrpe的插件
cd ./src/ && make install-plugin
make[1]: Entering directory `/usr/src/nrpe-2.15/src'
/usr/bin/install -c -m 775 -o nagios -g nagios -d /usr/local/nagios/libexec
/usr/bin/install -c -m 775 -o nagios -g nagios check_nrpe /usr/local/nagios/libexec
make[1]: Leaving directory `/usr/src/nrpe-2.15/src'
#在被监控机上安装nrpe服务 及插件
tar xf nrpe-2.15.tar.gz
cd nrpe-2.1
yum -y install xinetd
useradd nagios
./configure --prefix=/usr/local/nagios
make
make install-daemon
make install-daemon-config
make install-xinetd
vim /etc/xinetd.d/nrpe
# default: on
# description: NRPE (Nagios Remote Plugin Executor)
service nrpe
{
flags = REUSE
socket_type = stream
port = 5666
wait = no
user = nagios
group = nagios
server = /usr/local/nagios/bin/nrpe
server_args = -c /usr/local/nagios/etc/nrpe.cfg --inetd
log_on_failure += USERID
disable = no
only_from = 127.0.0.1
}
修改only_from 定义监控服务器的IP地址
[root@localhost nrpe-2.15]#vim /etc/services
nrpe 5666/tcp
[root@localhost nrpe-2.15]#service xinetd restart
查看NRPE服务是否启动
[root@localhost nrpe-2.15]# lsof -i :5666
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
xinetd 7962 root 5u IPv6 205762 0t0 TCP *:nrpe (LISTEN)
安装插件 nagios-plugins-1.5.tar.gz 同上
将插件拷贝到被监控服务器插件库
scp /usr/local/nagios/libexec/check_disk_io 192.168.18.247:/usr/local/nagios/libexec/
添加监控命令
[root@localhost libexec]# vim /usr/local/nagios/etc/nrpe.cfg
command[check_disk_io]=/usr/local/nagios/libexec/check_disk_io -w 2 -c 3
#监控服务器
定义check_nrpe命令 vim commands.cfg
define command {
command_name check_nrpe
command_line $USER1$/check_nrpe -H $HOSTADDRESS$ -c $ARG1$
}
定义监控远端服务器的内容 定义一个监控服务
define service {
host_name instructor.example.com
service_description DISK_io
check_period 24x7
normal_check_interval 2
retry_check_interval 1
max_check_attempts 5
notification_period 24x7
notification_options w,u,c,r
check_command check_nrpe!check_disk_io
}
测试命令
[root@nagios libexec]# ./check_nrpe -H 192.168.18.247 -c check_disk_io
OK IO is 0.00
测试监控
for i in `seq 1 20`; do dd if=/dev/zero of=/tmp/bigfile bs=1M count=10000; done