PS: the original intention of writing a script is to facilitate your work more efficiently and exercise your ability to write a script. Of course, I hope it will bring you some small help, I hope you can provide more support, comment, and point out the shortcomings. I. Test Environment [root @ hello ~] # Uname-r2.6.32-279.el6.x86_64 [root @ hello ~] # Cat/etc/issueCentOSrelease6.3 (Final) Kern
PS: the original intention of writing a script is to facilitate your work more efficiently and exercise your ability to write a script. Of course, I hope it will bring you some small help, I hope you can provide more support, comment, and point out the shortcomings.
I. Test Environment
[root@hello ~]# uname -r2.6.32-279.el6.x86_64[root@hello ~]# cat /etc/issueCentOS release 6.3(Final)Kernel \r on an \m[root@hello ~]# dmidecode -s system-product-nameVMware Virtual Platform
Ii. Interactive Web service installation script
Note: Before compiling and installing apche, you must ensure that Additional Development, Development tools, and Base software package groups are installed in your current system, including the library files and compilation tools required by apache, zlib, gcc, automake, pcre, etc. Otherwise, the installation may fail.
[root@hello scripts]# cat auto_install_web.sh#!/bin/bash#blog http://cfwlxf.blog.51cto.com#create date of 2013-10-30#Load user environment variablePATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbinexport PATH#source system functions library.. /etc/init.d/functions#definition software download and install directoySOURCE_DIR=/download/source/INSTALL_DIR=/application/#Judge SOURCE_DIR INSTALL_DIR directoy ifexits.[ ! -d ${SOURCE_DIR} ] && mkdir ${SOURCE_DIR} -p[ ! -d ${INSTALL_DIR} ] && mkdir ${INSTALL_DIR} -p && sleep 1&& printf "\033[32mDirectory $SOURCE_DIR $INSTALL_DIR by create.\033[0m"#Download httpd softwareprintf "\033[33m----------------------------------------------------------------------------| Welcome to useapache auto install scripts |----------------------------------------------------------------------------\033[0m\n"printf "\033[36mDownload Web Server of sourece package,please input staring \'y/n\': \033[0m"STRread STR#Judge User input of string ifby 'y'if[ $STR = "y"]thenprintf "\033[32m----------------------------------------------------------------------------| Apache Software List |----------------------------------------------------------------------------|1.Download web server software of httpd.2.4.4versions. ||2.Download web server software of httpd.2.2.25versions. ||3.Download web server software of httpd.2.4.6versions. |----------------------------------------------------------------------------\033[0m\n\n"read -p "Please you input number'1-4', select httpd install of httpd versions: "VERSIONScase"$VERSIONS"in1)cd ${SOURCE_DIR}wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.4.tar.gz;;2)cd ${SOURCE_DIR}wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.2.25.tar.gz;;3)cd ${SOURCE_DIR}wget http://mirrors.hust.edu.cn/apache/httpd/httpd-2.4.6.tar.gz;;*)sleep 1printf "\033[31mError: Please input number \'1-4\',select httpd versions.\033[0m\n"exit 0esacelsesleep 2printf "\033[31mError: You enter the error string,Please anew input.\033[0m\n"exit 0fi#Uncompress httpd software packagecd ${SOURCE_DIR}HTTPD_SOFTWARE=$(find /download/source/ -type f | grep httpd |awk 'BEGIN{FS="/"}END{print $4}')tar -xf ${HTTPD_SOFTWARE} && sleep 2&& printf "\033[35mUncompress software by successfully.\033[0m\n"#Judge current directoy yes or on uncompress later of directoryHTTPD_UNCOMPRESS=$(find ./ -maxdepth 1-type d | grep httpd)cd ${HTTPD_UNCOMPRESS}RETURN_PWD=$(pwd | cut -d '/'-f4)ECHO_HTTPD=$(echo ${HTTPD_UNCOMPRESS}|awk 'BEGIN{FS="/"}END{print $2}')#Judge whether the current directory ifuncompress after of directoryif[ ${RETURN_PWD} = ${ECHO_HTTPD} ]thensleep 1printf "\033[33mIf you need support \'--with-included-arp\',please download software after install,\'yes/no\': \033[0m"DOWNLOADread DOWNLOADif[ "$DOWNLOAD"= "yes"]thenwget http://mirrors.hust.edu.cn/apache/apr/apr-1.4.6.tar.gzwget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.4.1.tar.gz#Judge download apr apr-util file of exits.APR_FILE=$(find ./ -maxdepth 1-type f | sed -n '/apr-1/p'| grep -Po '(?<=./).*')APR_UTIL_FILE=$(find ./ -maxdepth 1-type f | sed -n '/apr-util/p'| grep -Po '(?<=./).*')[ -e $APR_FIEL $APR_UTIL_FILE ] && sleep 2&& printf "\033[35mDownload File $APR_FILE,$APR_UTIL_FILE already successfully.\033[0m\n"#Uncompress apr apr-util software package.APACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1-type d| grep httpd)APACHE_UNCOMPRESS_SRCLIB_DIR=${APACHE_UNCOMPRESS_FILE}/srclib/tar -xf $APR_FILE -C $APACHE_UNCOMPRESS_SRCLIB_DIR && tar -xf $APR_UTIL_FILE -C $APACHE_UNCOMPRESS_SRCLIB_DIR && cd $APACHE_UNCOMPRESS_SRCLIB_DIRAPR_UNCOMPRESS_FILE=$(find ./ -maxdepth 1-type d | grep 'apr-1'| grep -Po'(?<=./).*')APR_UTIL_UNCOMPRESS_FILE=$(find ./ -maxdepth 1-type d | grep 'apr-util'| grep -Po '(?<=./).*')mv -f $APR_UNCOMPRESS_FILE apr && mv -f $APR_UTIL_UNCOMPRESS_FILE apr-util && sleep 2&& action "Uncompress file apr aprutil is successfully."true#configure apacheAPACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1-type d| grep httpd)cd $APACHE_UNCOMPRESS_FILE./configure --prefix=/application/${ECHO_HTTPD} --enable-substitute --enable-deflate --enable-expires --enable-ssl --enable-http --enable-rewrite --enable-so --with-mpm=worker --enable-mods-shared=mos --with-z --with-included-aprelse#configure apacheAPACHE_UNCOMPRESS_FILE=$(find /download/source/ -maxdepth 1-type d| grep httpd)cd $APACHE_UNCOMPRESS_FILE./configure --prefix=/application/${ECHO_HTTPD} --enable-substitute --enable-deflate --enable-expires --enable-ssl --enable-http --enable-rewrite --enable-so --with-mpm=worker --enable-mods-shared=mos --with-zfielseprintf "\033[31mError: Your current of directory fault $ECHO_HTTPD.\033[0m\n"exit 0fi#Compile apache software packageRETVAL=0make && [ $? = $RETVAL ] && make installsleep 2&& printf "\033[35mApache compile is successfully,please start apache server of 'yes/no\': \033[0m"STARTread STARTAPACHE_BIN=$(find /application/ -maxdepth 1-type d | grep httpd)[ "$START"= "yes"] && ${APACHE_BIN}/bin/apachectl start > /dev/null2>&1#Judge elinsk sottware of already install.SERVER_IP=$(ifconfig eth0 | grep 'inet addr:'| sed 's/.*r:\(.*\) B.*$/\1/g')ELINKS_RPM=$(rpm -qa elinks| wc -l)[ $ELINKS_RPM = 1] && elinks --dump http://$SERVER_IP/index.html[ $ELINKS_RPM != 1] && yum install elinks && elinks --dump http://$SERVER_IP/index.html
# Tip:
During script execution, you will be prompted to select the apache version. if the version provided in the script cannot meet your company's requirements, you can add the required version link to the script, just make a few changes. If you do not know APR friends, you can click URL: http://baike.baidu.com/link? Url = 8NJ28ufytnW1h6opu-Z3q3sVaAN82 _ ePE9okiCUkwsP-WB6ymhYGFmitXL5gUPg3MUaWpTVgglBnAfrRqDAdK for details, the script may have many deficiencies, welcome to comments.
Iii. instance demonstration