nagios的客户端安装脚本
#!/bin/bash #解决依赖 yum -y install sysstat openssl-devel bc xinetd #新建用户 groupadd nagios useradd -g nagios -M -s /sbin/nologin nagios #编译安装插件 cd /root/soft/ tar -zxf nagios-plugins-1.5.tar.gz cd nagios-plugins-1.5 ./configure make && make install #编译安装nrpe cd /root/soft/ tar -zxf nrpe-2.15.tar.gz cd nrpe-2.15 ./configure make all && make install-plugin && make install-daemon make install-daemon-config && make install-xinetd #在守护进程的主配置文件添加监控端 ip cd /root/soft/ sed -i '/only_from/s/$/ 10.10.10.21/' /etc/xinetd.d/nrpe #添加nrpe服务 echo "nrpe 5666/tcp # nrpe" >> /etc/services #修改snmp配置文件,暂时不需要修改。因为此时的被监控端是使用 check_nrpe 命令来监测相关信息内容 #sed -i '41a com2sec notConfigUser 127.0.0.1 public' /etc/snmp/snmpd.conf #sed -i '41a view systemview included .1' /etc/snmp/snmpd.conf #sed -i 's/#view all included .1 80/view all included .1 80/' /etc/snmp/snmpd.conf #提供"内存,cpu,流量"的监控脚本,因为系统默认没有这些脚本 cd /root/soft/ chmod +x check_mem.sh check_cpu.sh check_traffic.sh mv check_mem.sh check_cpu.sh check_traffic.sh /usr/local/nagios/libexec/ #使用自定义好的 nrpe.cfg 配置文件。同时也可以自己修改配置文件,主要是添加一些 nrpe的一些监控命令,如下条内容 cp -f nrpe.cfg /usr/local/nagios/etc/nrpe.cfg chown nagios.nagios /usr/local/nagios/etc/nrpe.cfg #自定义修改 nrpe.cfg 的相关内容,主要就是添加一些 nrpe的一些监控命令,如果使用了上面的方法,那此处就不用修改 #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_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 160 -c 200 #command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10% #command[check_http]=/usr/local/nagios/libexec/check_http -I 127.0.0.1 #command[check_disk]=/usr/local/nagios/libexec/check_disk -w 15% -c 10% #command[check_mem]=/usr/local/nagios/libexec/check_mem.sh -w 85 -c 95 #command[check_cpu]=/usr/local/nagios/libexec/check_cpu.sh -w 85 -c 95 #command[check_traffic]=/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -I 3 -w 4200,4500 -c 5400,5500 -K -B #EOF #df_=`df -h|grep /|awk 'NR==1'|awk '{print $1}'` #echo "command[check_/]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p $df_" >>/usr/local/nagios/etc/nrpe.cfg #df_data=`df -h|grep data|awk '{print $1}'` #echo "command[check_/data]=/usr/local/nagios/libexec/check_disk -w 20% -c 10% -p $df_data" >>/usr/local/nagios/etc/nrpe.cfg #service snmpd restart #启动 nrpe 的守护进程,这样如再修改 nrpe的相关内容就不用再重新启动 service xinetd restart #/usr/local/nagios/libexec/check_traffic.sh -V 2c -C public -H 127.0.0.1 -L #检测 nrpe 是否启动 netstat -tnlp | grep 5666 if [ $? == 0 ]; then echo "nrpe is Success" else echo "Down" exit fi