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 if exits.[ ! -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 use apache 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 if by 'y'if [ $STR = "y" ]then printf "\033[32m ---------------------------------------------------------------------------- | Apache Software List | ---------------------------------------------------------------------------- |1.Download web server software of httpd.2.4.4 versions. | |2.Download web server software of httpd.2.2.25 versions. | |3.Download web server software of httpd.2.4.6 versions. | ---------------------------------------------------------------------------- \033[0m\n\n" read -p "Please you input number'1-4', select httpd install of httpd versions: " VERSIONS case "$VERSIONS" in 1) 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 1 printf "\033[31mError: Please input number \'1-4\',select httpd versions.\033[0m\n" exit 0 esacelse sleep 2 printf "\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 if uncompress after of directoryif [ ${RETURN_PWD} = ${ECHO_HTTPD} ]then sleep 1 printf "\033[33mIf you need support \'--with-included-arp\',please download software after install,\'yes/no\': \033[0m" DOWNLOAD read DOWNLOAD if [ "$DOWNLOAD" = "yes" ] then wget http://mirrors.hust.edu.cn/apache/apr/apr-1.4.6.tar.gz wget 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_DIR APR_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 apache APACHE_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-apr else #configure apache APACHE_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 fielse printf "\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/null 2>&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
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/1231102452-0.png "style =" float: none; "title =" qq 31106173430.png "alt =" 175640101.png"/>
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/1231104B9-1.jpg "style =" float: none; "title =" qq 31106173835.jpg "alt =" 175643486.jpg"/>
650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131229/1231104N3-2.jpg "style =" float: none; "title =" qq 31106174116.jpg "alt =" 175645914.jpg"/>
# Tip:
All apache versions provided in the script have been tested and can be used by O & M personnel who need to modify them according to their own ideas. I think you can use this script to write a script for interactive installation in the LAMP and LNMP environments, or automatically install the script to improve your script writing capability, avoid tedious operations and efficiency, and highlight your own strength.
This article from "Life has a dream and wonderful" blog, please be sure to keep this source http://cfwlxf.blog.51cto.com/3966339/1321064