nagios的客户端安装脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#!/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
|
本文出自 “行 者--->” 博客,请务必保留此出处http://liumissyou.blog.51cto.com/4828343/1623853
转载于:https://blog.51cto.com/lucifer119/1729410