#!/bin/bash
groupadd nagios
useradd nagios -g nagios
chmod 755 check_cpu.sh check_mem.sh
yum -y install openssl openssl-devel gcc gcc-c++ xinetd
tar -zxf nrpe-2.12.tar.gz
tar -zxf nagios-plugins-2.1.1.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
make install-xinetd
if ! [ `cat /etc/services | grep NRPE| wc -l` -ge 1 ]
then
echo "nrpe 5666/tcp # NRPE">>/etc/services
fi
cd ../nagios-plugins-2.1.1
./configure --with-nagios-user=nagios --with-nagios-group=nagios
make && make install
/bin/cp ../check_mem.sh /usr/local/nagios/libexec/
/bin/cp ../check_cpu.sh /usr/local/nagios/libexec/
/bin/cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.default
cat >>/usr/local/nagios/etc/nrpe.cfg<<EOF
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_hda1]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /dev/hda1
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_disk_root]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /
command[check_disk_home]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /home
command[check_disk_boot]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p /boot
command[check_Cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 20 -c 10
command[check_Memory]=/usr/local/nagios/libexec/check_mem.sh -w 20 -c 10
command[check_Swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%
EOF
sed -i 's/only_from/\#only_from/g' /etc/xinetd.d/nrpe
sed -i '/}/d' /etc/xinetd.d/nrpe
cat >>/etc/xinetd.d/nrpe<<EOF
only_from = 127.0.0.1 xxx.xxx.xxx.xxx #这里的xxx换成对应nagios server的IP
}
/etc/init.d/xinetd restart
#check_cpu.sh和check_mem.sh是从网上找的,一并贴上来了
check_cpu.sh: