運維監控工具之 Nagios 客戶端安裝(二)

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



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章