1、添加nagios用户
echo “—— step 1: add nagios user——“
#create user group
/usr/sbin/useradd -m nagios -s /sbin/nologin

2、解压nagios软件包
echo “—— step 2: unzip nagios soft——“
mkdir -p /home/oldboy/tools/
cd /home/oldboy/tools/
[  ! -f ./oldboy_training_nagios_soft.zip ] &&{
echo “nagios soft is not exist.”
exit 1
}
/bin/cp oldboy_training_nagios_soft.zip /home/oldboy/tools/
cd /home/oldboy/tools/

3、安装nagios插件
echo “—— step 3: install nagios-plugins——“
yum -y install perl-devel
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure –prefix=/usr/local/nagios –enable-perl-modules –enable-redhat-pthread-workaround 
make && make install
cd ../
ls /usr/local/nagios/libexec/|wc -l

echo “—— step 4: install nrpe——“
cd /home/oldboy/tools/
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..

4、安装iostat监控相关插件
echo “—— step 4: install soft for iostat——“
cd /home/oldboy/tools/
tar zxvf Params-Validate-0.91.tar.gz 
cd Params-Validate-0.91 
perl Makefile.PL 
make
make install

#—————————————- 
cd /home/oldboy/tools/
tar zxvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31
perl Makefile.PL
make
make install

#—————————————- 
cd /home/oldboy/tools/
tar zxvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12
perl Makefile.PL
make
make install

#—————————————- 
cd /home/oldboy/tools/
tar zxvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install

#—————————————- 
cd /home/oldboy/tools/
tar zxvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install

#—————————————- 
cd /home/oldboy/tools/
tar zxvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install

#______________________ 

#for monitor iostat 
yum install sysstat -y

/bin/cp /home/oldboy/tools/check_memory.pl /usr/local/nagios/libexec
/bin/cp /home/oldboy/tools/check_iostat /usr/local/nagios/libexec

chmod 755 /usr/local/nagios/libexec/check_memory.pl
chmod 755 /usr/local/nagios/libexec/check_iostat

dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat

5、修改nrpe.cfg文件,添加服务端
echo “—— step 5: 修改nrpe.cfg——“
perl -pi -e \’s/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,192.168.8.42/g\’ /usr/local/nagios/etc/nrpe.cfg 

#delete 199–203
cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.ori
sed -i \’199,203d\’ /usr/local/nagios/etc/nrpe.cfg

echo “command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20”>>/usr/local/nagios/etc/nrpe.cfg
echo “command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%”>>/usr/local/nagios/etc/nrpe.cfg
echo “command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /”>>/usr/local/nagios/etc/nrpe.cfg
echo “command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%”>>/usr/local/nagios/etc/nrpe.cfg
echo “command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10”>>/usr/local/nagios/etc/nrpe.cfg

6、启动nagios客户端
echo “—— step 6: start nagios client——“
#start nagios client
pkill nrpe 
sleep 2
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo  “#nagios nrpe process cmd by jack 2016-07-21” >> /etc/rc.local
echo “/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d”>>/etc/rc.local

netstat -lnt|grep 5666 && echo “nagios client is ok”

自动化安装脚本:

将oldboy_training_nagios_soft.zip压缩包拷贝到系统中

#!/bin/sh
################################################
echo "# 安装 nagios 客户端AGENT  #"
echo "##############################"
#install nagios client---start---
mkdir -p /home/oldboy/tools/
cd /home/oldboy/tools/
# 将oldboy_training_nagios_soft.zip上传到/home/oldboy/tools/目录中

#install nagios client---start---
yum install -y gcc*
yum install gcc glibc glibc-common -y
yum install -y openssl*
echo "------ step 1: add nagios user------"
#create user group
/usr/sbin/useradd -m nagios -s /sbin/nologin


echo "------ step 2: unzip nagios soft------"
cd /home/oldboy/tools/
[  ! -f ./oldboy_training_nagios_soft.zip ] &&{
echo "nagios soft is not exist."
exit 1
}
/bin/cp oldboy_training_nagios_soft.zip /home/oldboy/tools/
cd /home/oldboy/tools/
unzip oldboy_training_nagios_soft.zip

echo "------ step 3: install nagios-plugins------"
yum -y install perl-devel
tar zxf nagios-plugins-1.4.16.tar.gz
cd nagios-plugins-1.4.16
./configure --prefix=/usr/local/nagios --enable-perl-modules --enable-redhat-pthread-workaround 
make && make install
cd ../
ls /usr/local/nagios/libexec/|wc -l


echo "------ step 4: install nrpe------"

cd /home/oldboy/tools/
tar zxf nrpe-2.12.tar.gz
cd nrpe-2.12
./configure
make all
make install-plugin
make install-daemon
make install-daemon-config
cd ..

echo "------ step 4: install soft for iostat------"
cd /home/oldboy/tools/
tar zxvf Params-Validate-0.91.tar.gz 
cd Params-Validate-0.91 
perl Makefile.PL 
make  
make install 
cd .. 
#---------------------------------------- 
cd /home/oldboy/tools/
tar zxvf Class-Accessor-0.31.tar.gz
cd Class-Accessor-0.31
perl Makefile.PL
make
make install
cd ..
#---------------------------------------- 
cd /home/oldboy/tools/
tar zxvf Config-Tiny-2.12.tar.gz
cd Config-Tiny-2.12
perl Makefile.PL
make
make install
cd ..
#---------------------------------------- 
cd /home/oldboy/tools/
tar zxvf Math-Calc-Units-1.07.tar.gz
cd Math-Calc-Units-1.07
perl Makefile.PL
make
make install
cd ..
#---------------------------------------- 
cd /home/oldboy/tools/
tar zxvf Regexp-Common-2010010201.tar.gz
cd Regexp-Common-2010010201
perl Makefile.PL
make
make install
cd ..
#---------------------------------------- 
cd /home/oldboy/tools/
tar zxvf Nagios-Plugin-0.34.tar.gz
cd Nagios-Plugin-0.34
perl Makefile.PL
make
make install
cd ..
#______________________ 

#for monitor iostat 
yum install sysstat -y

/bin/cp /home/oldboy/tools/check_memory.pl /usr/local/nagios/libexec
/bin/cp /home/oldboy/tools/check_iostat /usr/local/nagios/libexec

chmod 755 /usr/local/nagios/libexec/check_memory.pl
chmod 755 /usr/local/nagios/libexec/check_iostat

dos2unix /usr/local/nagios/libexec/check_memory.pl
dos2unix /usr/local/nagios/libexec/check_iostat
##################################################
echo "------ step 5: 修改nrpe.cfg------"
perl -pi -e \'s/allowed_hosts=127.0.0.1/allowed_hosts=127.0.0.1,10.0.0.7/g\' /usr/local/nagios/etc/nrpe.cfg 

#delete 199--203
cp /usr/local/nagios/etc/nrpe.cfg /usr/local/nagios/etc/nrpe.cfg.ori
sed -i \'199,203d\' /usr/local/nagios/etc/nrpe.cfg

echo "command[check_load]=/usr/local/nagios/libexec/check_load -w 15,10,6 -c 30,25,20">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_mem]=/usr/local/nagios/libexec/check_memory.pl -w 6% -c 3%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_disk]=/usr/local/nagios/libexec/check_disk -w 20% -c 8% -p /">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_swap]=/usr/local/nagios/libexec/check_swap -w 20% -c 10%">>/usr/local/nagios/etc/nrpe.cfg
echo "command[check_iostat]=/usr/local/nagios/libexec/check_iostat -w 6 -c 10">>/usr/local/nagios/etc/nrpe.cfg

echo "------ step 6: start nagios client------"
#start nagios client
pkill nrpe 
sleep 2
/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d
echo  "#nagios nrpe process cmd by oldboy 2012-6-7" >> /etc/rc.local
echo "/usr/local/nagios/bin/nrpe -c /usr/local/nagios/etc/nrpe.cfg -d">>/etc/rc.local
netstat -lnt|grep 5666 && echo "nagios client is ok"

版权声明:本文为reblue520原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/reblue520/p/6239770.html