centos6.5下制作bin文件

1.首先把需要安装的rpm,gz,zip文件打包在一起
# tar zcvf packages.tar.gz nagios-plugins-1.4.16.tar.gz nrpe-2.12.tar.gz
2.编辑安装脚本
#!/bin/bash
for rpm in {automake,make,gcc,libgcc,xinetd};do rpm -q $rpm || yum install $rpm ;done
dir=/tmp/install/
if [ -e $dir ];then
    rm -rf $dir/*
else
    mkdir $dir
fi
#tail -n +30 $0 >$dir/packages.tar.gz #30表示脚本的行数,此命令是把shell后面的gz文件提出来。
sed -n -e '1,/^exit 0$/!p' $0 > ${dir}/packages.tar.gz 2>/dev/null #跟上面一个意思,这个是从第一行到"exit 0"这行结束提出来。
cd $dir
tar xf packages.tar.gz
echo "###useradd nagios###"
id nagios
if [ $? -eq 0 ];then echo "user nagios was exist" ; else useradd -s /sbin/nologin nagios ; fi
echo "###install nagios-plugins###"
cd $dir
tar xf nagios-plugins-1.4.16.tar.gz && cd nagios-plugins-1.4.16 && ./configure || echo "configure is wrong" && make && make install
echo "###chown privilege for directory nagios####"
chown nagios. /usr/local/nagios -R
echo "###install nrpe###"
cd $dir
tar xf nrpe-2.12.tar.gz  && cd nrpe-2.12 && ./configure || echo "configure was wrong" && make all && make install-plugin && make ins
tall-daemon && make install-daemon-config && make install-xinetd
echo "###change config file###"
sed -i '/only_from/s/127\.0\.0\.1/127\.0\.0\.1 10\.6\.8\.200/g'  /etc/xinetd.d/nrpe
echo "nrpe              5666/tcp                # nrpe" >> /etc/services
echo "###start services###"
/etc/init.d/xinetd restart && echo "xinetd services was running" || echo "xinetd services was wrong"
exit 0 #脚本执行完需要退出,不然会重复执行,此处很重要。。。
3.然后封装成bin文件
# cat install_nagios_client.sh packages.tar.gz >nagios.bin
# chmod +x nagios.bin
# ./nagios.bin

4.验证是否正常运行

# netstat -lutnp |grep 5666
tcp        0      0 0.0.0.0:5666                0.0.0.0:*                   LISTEN      28374/xinetd
# /usr/local/nagios/libexec/check_nrpe -H 10.6.1.34
NRPE v2.12



你可能感兴趣的:(nagios.bin,linux制作bin文件)