您的位置:首页 > 移动开发 > IOS开发

nagios 使用源码包自动部署脚本

2010-09-06 11:07 633 查看
把这个脚本和nagios安装源码包以及插件源码包放到一起,执行脚本就可以自动部署了,现在分为2部分,第一部分安装nagios ,第二部分安装nagios-plugins,安装之前会判断需要的软件包是否存在,如果有未安装的会提示你安装,yum安装就可以,关于yum仓库配置,我之前有发过一个脚本,执行那个脚本就可以,在第一部分安装的最后,会提示你输入密码,那个密码就是web访问的密码,登陆用户为nagiosadmin,安装完成后直接访问即可,后续会加入nrpe以及nsca 部分配置内容。

#install nagios
#chenjian
#2010-009-01

export LANG=en_US.UTF-8

NAGIOS=./nagios-[0-9]*.tar.gz
NAGIOS_PLIUGINS=./nagios-plugins-*.tar.gz
NEED_PACKAGE="httpd gcc glibc glibc-common gd gd-devel php"
MYDATE=`date +%Y-%m-%d`

if [ $(id -u) -ne 0 ]
then  echo error -please use super user.
exit 2
fi

check_status () {
if [ $? -ne 0 ]
then clear
echo $1 [fail]
exit 2
else
echo $1 [OK]
fi
}

check_need_package () {
echo -------- Step1 : Check the relevant package installation situation.
echo `rpm -qa $NEED_PACKAGE |sed 's/-[0-9]*\..*//g'` > /tmp/install_nagios

for i in  $NEED_PACKAGE
do `grep $i /tmp/install_nagios >& /dev/null`
if [ $? -eq 0 ]
then
:
else
echo $i is not install.
SITUATION=OK
fi

done

if [ $SITUATION ]
then exit 2
fi
}

server () {
cat <<eof
nagios install
-----------------------------------------------------------------------------------------------------------------
User:$USER     Select the choice you want install      Date:$MYDATE
-----------------------------------------------------------------------------------------------------------------

1) install nagios

2) install nagios-plugins

q)  exit programe
-----------------------------------------------------------------------------------------------------------------
eof
}

portal () {
clear
server
read info
case $info in
1)
clear

check_need_package

if ! id nagios >& /dev/null
then
useradd -m nagios
groupadd nagcmd
usermod -a -G nagcmd nagios
usermod -a -G nagcmd apache
fi

if [ ! -f $NAGIOS ]
then echo "Nagios source package not found."
exit 2
else

tar -zxf $NAGIOS -C /tmp
cd /tmp/nagios-[0-9]*
clear
echo Step2 : Configure and compile the source code for your system ,please wait.....
sleep 5
./configure --with-command-group=nagcmd
fi

if [ $? -eq 0 ]
then echo -------- Configure Successful.
fi
clear
echo Step3 : Make and install everything ,please wait.....
sleep 5
make all
check_status "make all"
make install
check_status "make install"
make install-init
check_status "make install-init"
make install-config
check_status "make install-config"
make install-commandmode
check_status "make install-commandmode"
make install-webconf
check_status "make install-webconf"

if [ $? -eq 0 ]
then
clear
echo  Nagios make install Successful.
fi

clear
echo set nagios web access password,username is nagiosadmin.

htpasswd -c /usr/local/nagios/etc/htpasswd.users nagiosadmin
cd ~
rm -rf /tmp/install_nagios
rm -rf /tmp/nagios-[0-9]*

clear

if ! sestatus |awk '{print $3}' |grep disabled >& /dev/null
then
chcon -R -t httpd_sys_content_t /usr/local/nagios/sbin/
chcon -R -t httpd_sys_content_t /usr/local/nagios/share/
fi

echo Set apache and nagios start at boot time.

chkconfig httpd on && echo apache set [OK]
chkconfig nagios on && echo nagios set [OK]

service httpd start
service nagios start

echo -e "
-------------------------------------------------------------------\n
install nagios successful ,please use http://yourip/nagios access\n
user: nagiosadmin              password: ***(just set)
-------------------------------------------------------------------"
exit 0

;;

2)
clear
check_need_package

if [ ! -f $NAGIOS_PLIUGINS ]
then echo "Nagios-pliugins source package not found."
exit 2
else
tar -zxf $NAGIOS_PLIUGINS -C /tmp
cd /tmp/nagios-plugins*
clear
echo Step2 : Configure and compile the source code for your system ,please wait.....
sleep 5
./configure --with-nagios-user=nagios --with-nagios-group=nagios
fi

if [ $? -eq 0 ]
then echo -------- Configure Successful.

fi

clear
echo Step3 : Make and install everything ,please wait.....
sleep 5
make
check_status "make"
make install
check_status "make install"
echo -e "
-------------------------------------------------------------------\n
install nagios plugins successful.\n
-------------------------------------------------------------------"
cd ~

rm -rf /tmp/nagios-plugins*
rm -rf /tmp/install_nagios
;;

q)
exit 0
;;
*)
portal
;;
esac
}

main () {
clear
portal
exit 0
}

main
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: