CentOS6.x下通過shell指令碼互動安裝Web服務

來源:互聯網
上載者:User

PS:寫指令碼的初衷,是為了方便自己更有效率的去工作,同時鍛煉自己寫指令碼的能力,當然還希望能夠給大家帶來一些小的協助,希望大家多多支援,評論評論,指出不足的地方。


一、測試環境

[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


二、互動式安裝Web服務指令碼

註:在編譯安裝apche之前,必須確保你當前的系統中安裝了Additional Development、Development tools、Base軟體包組,其中包含了apache所需的庫檔案與編譯工具,zlib,gcc,automake,pcre等,不然安裝可能無法完成。

[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


#提示:

指令碼執行過程中,會提示使用者選擇apache的版本,若指令碼中所提供的版本都不能滿足公司需求的話,那麼你可以把需要的版本連結添加至指令碼,略做修改即可。如果對APR不瞭解的朋友,可以點擊網址:http://baike.baidu.com/link?url=8NJ28ufytnW1h6opu-Z3q3sVaAN82__ePE9okiCUkwsP-WB6ymhYGFmitXL5gUPg3MUaWpTVgglBnAfrRqDAdK 詳細瞭解,指令碼可能還有很多不足的地方,歡迎大家評論。


三、執行個體示範

650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131229/1231102452-0.png" style="float:none;" title="QQ圖片20131106173430.png" alt="175640101.png" />


650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131229/1231104B9-1.jpg" style="float:none;" title="QQ圖片20131106173835.jpg" alt="175643486.jpg" />


650) this.width=650;" src="http://www.bkjia.com/uploads/allimg/131229/1231104N3-2.jpg" style="float:none;" title="QQ圖片20131106174116.jpg" alt="175645914.jpg" />

#提示:

指令碼中所提供的apache版本,都已測試通過,有需求的營運朋友們可以按照自己的思維,略作修改後使用。我覺得大家剛好可以借照此指令碼,去編寫一個LAMP,LNMP環境互動式安裝的指令碼,或者自動安裝的指令碼,動動手提升你寫指令碼的能力,避免繁瑣的操作,有效率,也能突出你自己的實力。

本文出自 “人生有夢而精彩” 部落格,請務必保留此出處http://cfwlxf.blog.51cto.com/3966339/1321064

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.