一键安装nagios客户端

  1 #!/bin/sh
  2 #**********************************************************
  3 #*Author:               abner
  4 #*Email:                517465591@qq.com
  5 #*Blog                  http://www.cnblogs.com/lord-dang/
  6 #*Last modified:        2016-09-19 18:28
  7 #*Filename:             install_nagios_client.sh
  8 #*Description:         auto install nagios client
  9 #*Version:              v1.0  
 10 #*********************************************************
 11 . /etc/init.d/functions
 12 host="192.168.115.1"
 13 NAGIOS_TOOLS_DIR=/tmp/nagios
 14 echo "#######################Install Nagios Client######################"
 15 #------ step 1: add nagios user------"
 16 #create user group
 17 /usr/sbin/useradd -m nagios -s /sbin/nologin
 18 [ $? -eq 0 ]&&action "[1/6]:Add nagios user" /bin/true||action "[1/6]:Add nagios user" /bin/false
 19 
 20 #------ step 2: unzip nagios soft------"
 21 cd $NAGIOS_TOOLS_DIR/
 22 [ ! -f nagios_package.zip ] && {
 23     echo "Not found nagios_package.zip ,please tansfer it in $NAGIOS_TOOLS_DIR"
 24     exit 1
 25 }
 26 unzip nagios_package.zip>/dev/null 2>&1
 27 [ $? -eq 0 ]&&action "[2/6]:Unzip nagios soft" /bin/true||action "[2/6]:Unzip nagios soft" /bin/false
 28 
 29 #------ step 3: install nagios-plugins------"
 30 yum -y install perl-devel dos2unix openssl-devel >/dev/null 2>&1
 31 tar -xf nagios-plugins-1.4.16.tar.gz
 32 cd nagios-plugins-1.4.16
 33 ./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround >/dev/null 2>&1
 34 `make >/dev/null 2>&1`&& `make install >/dev/null 2>&1`
 35 cd ../
 36 #ls /usr/local/nagios/libexec/|wc -l
 37 [ $? -eq 0 ]&&action "[3/6]:Install nagios-plugins" /bin/true||action "[3/6]:Install nagios-plugins" /bin/false
 38 
 39 #------ step 4: install nrpe------"
 40 cd $NAGIOS_TOOLS_DIR/
 41 tar -xf nrpe-2.12.tar.gz
 42 cd nrpe-2.12
 43 ./configure>/dev/null 2>&1
 44 make all >/dev/null 2>&1
 45 make install-plugin >/dev/null 2>&1
 46 make install-daemon >/dev/null 2>&1
 47 make install-daemon-config >/dev/null 2>&1
 48 [ $? -eq 0 ]&&action "[4/6]:Install nrpe" /bin/true||action "[4/6]:Install nrpe" /bin/false
 49 
 50 
 51 #------ step 5: install soft for iostat------
 52 cd $NAGIOS_TOOLS_DIR/
 53 tar -xf Params-Validate-0.91.tar.gz 
 54 cd Params-Validate-0.91 
 55 perl Makefile.PL >/dev/null 2>&1
 56 make  >/dev/null 2>&1
 57 make install >/dev/null 2>&1
 58 cd .. 
 59 ################################################## 
 60 cd $NAGIOS_TOOLS_DIR/
 61 tar -xf Class-Accessor-0.31.tar.gz
 62 cd Class-Accessor-0.31
 63 perl Makefile.PL>/dev/null 2>&1
 64 make >/dev/null 2>&1
 65 make install >/dev/null 2>&1
 66 cd ..
 67 ##################################################
 68 cd $NAGIOS_TOOLS_DIR/
 69 tar -xf Config-Tiny-2.12.tar.gz
 70 cd Config-Tiny-2.12 >/dev/null 2>&1
 71 perl Makefile.PL >/dev/null 2>&1
 72 make >/dev/null 2>&1
 73 make install>/dev/null 2>&1
 74 cd ..
 75 ##################################################
 76 cd $NAGIOS_TOOLS_DIR/
 77 tar -xf Math-Calc-Units-1.07.tar.gz
 78 cd Math-Calc-Units-1.07>/dev/null 2>&1
 79 perl Makefile.PL>/dev/null 2>&1
 80 make>/dev/null 2>&1
 81 make install>/dev/null 2>&1
 82 cd ..
 83 ##################################################
 84 cd $NAGIOS_TOOLS_DIR/
 85 tar -xf Regexp-Common-2010010201.tar.gz
 86 cd Regexp-Common-2010010201
 87 perl Makefile.PL>/dev/null 2>&1
 88 make>/dev/null 2>&1
 89 make install>/dev/null 2>&1
 90 cd ..
 91 ##################################################
 92 cd $NAGIOS_TOOLS_DIR/
 93 tar -xf Nagios-Plugin-0.34.tar.gz
 94 cd Nagios-Plugin-0.34
 95 perl Makefile.PL>/dev/null 2>&1
 96 make>/dev/null 2>&1
 97 make install>/dev/null 2>&1
 98 cd ..
 99 ##################################################
100 
101 #for monitor iostat 
102 yum install sysstat -y>/dev/null 2>&1
103 
104 /bin/cp $NAGIOS_TOOLS_DIR/check_memory.pl /usr/local/nagios/libexec
105 /bin/cp $NAGIOS_TOOLS_DIR/check_iostat /usr/local/nagios/libexec
106 
107 chmod 755 /usr/local/nagios/libexec/check_memory.pl
108 chmod 755 /usr/local/nagios/libexec/check_iostat
109 
110 dos2unix /usr/local/nagios/libexec/check_memory.pl>/dev/null 2>&1
111 dos2unix /usr/local/nagios/libexec/check_iostat>/dev/null 2>&1
112 [ $? -eq 0 ]&&action "[5/6]:Install soft for iostat" /bin/true||action "[5/6]:Install soft for iostat" /bin/false
113 
114 ##################################################
115 #echo "------ step 6: modified nrpe.cfg------"
116 sed -i "s#allowed_hosts=127.0.0.1#allowed_hosts=127.0.0.1,$host#g" /usr/local/nagios/etc/nrpe.cfg
117 #delete 199--203
118 cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.ori
119 sed -i '199,203d' /usr/local/nagios/etc/nrpe.cfg
120 
121 echo "command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20">>/usr/local/nagios/etc/nrpe.cfg
122 echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%">>/usr/local/nagios/etc/nrpe.cfg
123 echo "command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /">>/usr/local/nagios/etc/nrpe.cfg
124 echo "command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%">>/usr/local/nagios/etc/nrpe.cfg
125 echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10">>/usr/local/nagios/etc/nrpe.cfg
126 [ $? -eq 0 ]&&action "[6/6]:Modified nrpe.cfg" /bin/true||action "[6/6]:Modified nrpe.cfgt" /bin/false
127 
128 #------ step 7: start nagios client------"
129 #start nagios client
130 /usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
131 #echo  "#nagios nrpe process cmd by abner at 2016/09/25" >> /etc/rc.local
132 echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local
133 #netstat -lnt|grep 5666 && echo "nagios client is ok"
134 rm -fr $NAGIOS_TOOLS_DIR
135 count=`lsof -i :5666|wc -l`
136 [ $count -ne 0 ]&&action "Install nagios client " /bin/true||action "Install nagios client" /bin/false

下载文件安装包,将文件放入脚本中自定义的路径(默认为/tmp/nagios)执行安装脚本

安装完成后会自动删除/tmp/nagios目录

posted @ 2016-09-25 10:41  党小伟  阅读(290)  评论(0编辑  收藏  举报