linux自动安装脚本
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux自动安装脚本相关的知识,希望对你有一定的参考价值。
测试的linux的内核参数是Linux rhel5 2.6.18-238.el5
系统是Red Hat Enterprise Linux Server release 5.6
相关apr,apu,pcre,openssl的包依赖性脚本并没有考虑进去,默认已经装好相关的依赖包。
脚本安装运行注意及功能特点:
1,默认在当前脚本文件所在的目录下创建名字为apache的,apache程序目录,支持配置目录,可按脚本运行提示修改,也可直接修改脚本,在脚本中直接修改默认配置。
2,默认配置apr,apu,pcre,openssl的安装目录,不支持在安装过程中修改。
3,支持使用不同的httpd,apr,apu,pcre及openssl安装包,可在安装过程中,按提示输入安装包名,以及直接修改脚本的默认配置
4,可选安装http及https,在安装过程中按提示输入选择即可,选择默认安装会安装https。
5,支持配置不同的apache编译参数,可在安装过程中按提示输入,也可直接修改脚本的默认配置参数。
6,支持修改安装过程中的提示时间,可以在脚本中修改。
#!/bin/bash #------------------------------------------------------------------------# # written by jm on 2016.02.25 # # # #------------------------------------------------------------------------# dir=`pwd` #apache安装时除apr,apu,pcre,openssl安装路径外的默认安装配置参数 apadefultprefix="--with-mpm=worker --enable-rewrite --enable-module=so --enable-proxy --enable-proxy-ajp --enable-forward --enable-proxy-connect --enable-proxy-http" #安装过程中所有提示语的显示时间,秒为单位 hinttime=15 #sethttpddefaultname,httpd安装包默认名配置 httpddefaultname=httpd-2.4.16.tar.gz #setaprdefaultname,apr安装包默认名配置 aprdefaultname=apr-1.5.2.tar.gz #setapudefaultnam,apu安装包默认名配置 apudefaultname=apr-util-1.5.4.tar.gz #setpcredefaultname,pcre安装包默认名配置 pcredefaultname=pcre-8.36.zip #setopenssldefaultname,openssl安装包默认名配置 openssldefaultname=openssl-1.0.2f.tar.gz #set apachedefaultdir,apache默认安装路径配置 apachedefaultdir=$dir/apache #set apachedir,设定apache安装路径 if read -t $hinttime -p "pls enter apache dir请设置全路径的apache安装目录如:/home/rs/apache:" apachedir then if [[ $apachedir == "" ]] then apachedir=$apachedefaultdir echo "apachedir is empty,would use default port $apachedir;输入为空,将使用默认目录$apachedir" else echo -e "\napachedir is $apachedir;apache目录为$apachedir" fi else apachedir=$apachedefaultdir echo -e "\napachedir is empty,would use default port $apachedir;输入为空,将使用默认目录$apachedir" fi #init apache interface,apache压缩包解压初始化接口 function httpakinit(){ cd $dir if [ ! -f $httppak ] then echo "httpd install package not exit,pls upload!" exit 1 else httpddir=`echo "$httppak"|sed ‘s/.tar.gz$//‘` tar -zxvf $httppak fi } #set apache pak 初始化apche源包,调用apache压缩包初始化接口 if read -t $hinttime -p "pls enter apache zip package name ex:httpd-2.4.16.tar.gz;输入apche压缩包名如:httpd-2.4.16.tar.gz:" httppak then if [[ $httppak == "" ]] then httppak=$httpddefaultname echo "apche pak is empty,would use default pak $httppak;输入apche压缩包名为空,将默认包名$httppak" httpakinit else echo "apche pak is $httppak;输入apche压缩包名为$httppak" httpakinit fi else httppak=$httpddefaultname echo -e "\napache pak is empty,would use default apche pak $httppak;输入apache压缩包名为空,将使用默认包名$httppak" httpakinit fi #init apr apk fuction 初始化apr包函数接口 function aprinit(){ cd $dir if [ ! -f $aprpak ] then echo "apr install package not exit,pls upload!" exit 1 else tar -zxvf $aprpak aprdir=`echo "$aprpak"|sed ‘s/.tar.gz$//‘` httpddir=`echo "$httppak"|sed ‘s/.tar.gz$//‘` cd ${httpddir}/srclib rm -rf apr cd ../../ mv ${aprdir} ${httpddir}/srclib/apr fi } #init apr pak 初始化apr源包 if read -t $hinttime -p "pls enter apache zip package name ex:apr-1.5.2.tar.gz;输入apche压缩包名如:apr-1.5.2.tar.gz:" aprpak then if [[ $aprpak == "" ]] then aprpak=$aprdefaultname echo "apr pak is empty,would use default pak $aprpak;输入apr压缩包名为空,将默认包名$aprpak" aprinit else echo "apr pak is $aprpak;输入apr压缩包名为$aprpak" aprinit fi else aprpak=$aprdefaultname echo -e "\napr pak is empty,would use default apche pak $aprpak;输入apr压缩包名为空,将使用默认包名$aprpak" aprinit fi #init apu pak fuction 初始化apu源包函数接口 function apuinit(){ cd $dir if [ ! -f $apupak ] then echo "apu install package not exit,pls upload!" exit 1 else tar -zxvf $apupak apudir=`echo "$apupak"|sed ‘s/.tar.gz$//‘` apchedir=`echo "$httppak"|sed ‘s/.tar.gz$//‘` cd ${httpddir}/srclib rm -rf apr-util cd ../../ mv ${apudir} ${httpddir}/srclib/apr-util fi } #init apu install function 初始化apu源包 if read -t $hinttime -p "pls enter apu zip package name ex:apr-util-1.5.4.tar.gz;输入apu压缩包名如:apr-util-1.5.4.tar.gz :" apupak then if [[ $apupak == "" ]] then apupak=$apudefaultname echo "apu pak is empty,would use default pak $apupak;输入apu压缩包名为空,将默认包名$apupak" apuinit else echo "apu pak is $apupak;输入apu压缩包名为$apupak" apuinit fi else apupak=$apudefaultname echo -e "\napr pak is empty,would use default apche pak $apupak;输入apr压缩包名为空,将使用默认包名$apupak" apuinit fi #install pcre apk,安装pcre函数接口 function pcreinstall(){ cd $dir if [ ! -f $pcrepak ] then echo "pcre install package not exit,pls upload!" exit 1 else unzip -o $pcrepak pcresrcdir=`echo "$pcrepak"|sed ‘s/.zip$//‘` cd $dir/$pcresrcdir chmod 777 -R * ./configure --prefix=$apachedir/pcre && make && make install if [[ `echo $?` == 0 ]] then echo "pcre install suscces" else echo "pcre install error,pls check!" exit 1 fi fi } #pcre pak init install function 初始化pcre源包及安装 if read -t $hinttime -p "pls enter pcre zip package name ex:pcre-8.36.zip;输入apu压缩包名如:pcre-8.36.zip :" pcrepak then if [[ $pcrepak == "" ]] then pcrepak=$pcredefaultname echo "pcre pak is empty,would use default pak $pcrepak;输入pcre压缩包名为空,将默认包名$pcrepak" pcreinstall else echo "pcre pak is $pcrepak;输入pcre压缩包名为$pcrepak" pcreinstall fi else pcrepak=$pcredefaultname echo -e "\npcre pak is empty,would use default pak $pcrepak;输入pcre压缩包名为空,将默认包名$pcrepak" pcreinstall fi #install openssl apk安装openssl函数接口 function opensslinstall(){ cd $dir if [ ! -f $opensslpak ] then echo "openssl install package not exit,pls upload!" exit 1 else tar -zxvf $opensslpak opensslsrcdir=`echo "$opensslpak"|sed ‘s/.tar.gz$//‘` cd $dir/$opensslsrcdir chmod 777 -R * ./config shared --prefix=$apachedir/ssl -DOPENSSL_NO_HEARTBEATS && make && make install if [[ `echo $?` == 0 ]] then echo "openssl install suscces" else echo "openssl install error,pls check!" exit 1 fi fi } #openssl pak init install function 初始化openssl源包及安装 #ssl install function include opesnsslinstall and ini function ,ssl安装接口包含opensslinstall过程调用 function sslinstall(){ if read -t $hinttime -p "pls enter openssl tar.gz package name ex:openssl-1.0.2f.tar.gz;输入openssl压缩包名如:openssl-1.0.2f.tar.gz :" opensslpak then echo "`pwd`" if [[ $opensslpak == "" ]] then opensslpak=$openssldefaultname echo "opensslpak pak is empty,would use default pak $opensslpak;输入openssl压缩包名为空,将默认包名$opensslpak" opensslinstall else echo "opensslpak pak is $opensslpak;输入pcre压缩包名为$opensslpak" opensslinstall fi else opensslpak=$openssldefaultname echo -e "\nopensslpak pak is empty,would use default pak $opensslpak;输入opensslpak压缩包名为空,将默认包名$opensslpak" opensslinstall fi } #http install interface,httpd安装函数接口 function httpdinstall(){ cd $dir/$httpddir ./configure --prefix=$httpdprefix && make && make install if [[ `echo $?` == 0 ]] then echo "apache install suscces" else echo "apache install error" exit 1 fi } #apache参数配置设定,httpd安装调用函数接口 function apacheinstall(){ if read -t $hinttime -p "pls enter httpd prefix,no need enter apachedir,apr,apu,pcre,ssl(不用输入apache,apr,apu,pcre,ssl编译路径),输入参数例子如:--with-mpm=worker --enable-rewrite:" httpdprefix then if [[ $httpdprefix == "" && $1 == "nhttps" ]] then httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre $apadefultprefix"` echo "1,httpdprefix is empty,would use default httpdprefix $httpdprefix;输入apache编译参数为空,将使用默认参数,$httpdprefix" httpdinstall elif [[ $httpdprefix == "" && $1 == "" ]] then httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre --enable-ssl --with-ssl=$apachedir/ssl $apadefultprefix"` echo "2,httpdprefix is empty,would use default httpdprefix $httpdprefix;输入apache编译参数为空,将使用默认参数,$httpdprefix" httpdinstall elif [[ $httpdprefix != "" && $1 == "nhttps" ]] then httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre $httpdprefix"` echo "6,httpdprefix pak is $httpdprefix;输入的编译参数为$httpdprefix" httpdinstall else httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre --enable-ssl --with-ssl=$apachedir/ssl $httpdprefix"` echo "3,httpdprefix is $httpdprefix;输入的编译参数为$httpdprefix" httpdinstall fi else if [[ $1 == "nhttps" ]] then httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre $apadefultprefix"` echo -e "\n4,httpdprefix is empty,would use default httpdprefix $httpdprefix;输入apache编译参数为空,将使用默认参数,$httpdprefix" httpdinstall else httpdprefix=`echo "$apachedir --with-included-apr --with-included-apr-util --with-pcre=$apachedir/pcre --enable-ssl --with-ssl=$apachedir/ssl $apadefultprefix"` echo -e "\n5,httpdprefix is empty,would use default httpdprefix $httpdprefix;输入apache编译参数为空,将使用默认参数,$httpdprefix" httpdinstall fi fi } #安装apache,调用apache安装函数接口 cd $dir read -n1 -t $hinttime -p "is install https?pls type\"y/n\";请输入y/n来选择是否安装https :" answer case $answer in Y|y) echo -e "\ninstall https,安装https" sslinstall apacheinstall cd $apachedir/lib cp $apachedir/ssl/lib/libssl.so.1.0.0 libssl.so.1.0.0 cp $apachedir/ssl/lib/libcrypto.so.1.0.0 libcrypto.so.1.0.0 ;; N|n) echo -e "\ninstall http,安装http" apacheinstall nhttps ;; "") echo -e "\nenter is empty,will install https,输入为空默认安装https" sslinstall apacheinstall cd $apachedir/lib cp $apachedir/ssl/lib/libssl.so.1.0.0 libssl.so.1.0.0 cp $apachedir/ssl/lib/libcrypto.so.1.0.0 libcrypto.so.1.0.0 ;; *) echo -e "\nonly can type Y/y/N/n,只能输入单字符y/n/Y/N";; esac exit 0
以上是关于linux自动安装脚本的主要内容,如果未能解决你的问题,请参考以下文章
Shell ❀ Linux系统自动挂载本地yum源并安装rpm依赖包
linux自动部署--sh脚本安装jdk,tomcat,mysqlclient