shell脚本自动编译安装Apache
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了shell脚本自动编译安装Apache相关的知识,希望对你有一定的参考价值。
shell脚本自动安装Apache,适用于CentOS
#!/bin/bash ##################################################### #Create date 2018.4.10 #Author: wansheng #Function: shell script install apache2.4 #Email: [email protected] #System: Linux CentOS-7 ##################################################### if [ $UID -ne 0 ];then please use root user running script!! exit 1 fi #下载安装包 apache_name="https://mirrors.tuna.tsinghua.edu.cn/apache/httpd/httpd-2.4.33.tar.gz" zlib_name="https://jaist.dl.sourceforge.net/project/libpng/zlib/1.2.11/zlib-1.2.11.tar.gz" apr_name="https://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gz" apr_util_name="https://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz" pcre_name="https://ftp.pcre.org/pub/pcre/pcre-8.42.tar.gz" openssl_name="https://www.openssl.org/source/openssl-1.1.1-pre3.tar.gz" libxml2_name="http://distfiles.macports.org/libxml2/libxml2-2.9.7.tar.gz" #安装包目录定义 apache_dir=`echo $apache_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` zlib_dir=`echo $zlib_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` pcre_dir=`echo $pcre_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2}'` openssl_dir=`echo $openssl_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` libxml2_dir=`echo $libxml2_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` apr_dir=`echo $apr_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` apr_util_dir=`echo $apr_util_name|awk -F"[/]" '{print $NF}'|awk -F"[.]" '{print $1"."$2"."$3}'` ##################################安装目录及服务目录############################## apache_install_dir=/server/application/${nginx_dir} apache_server_dir=/usr/local/apche [ ! -d /root/soft ] && mkdir -p /root/soft [ ! -d /server/application ] && mkdir -p /server/application package=( wget curl gcc gcc-c++ libxml2-devel gd-devel GeoIP GeoIP-devel perl perl-devel perl-ExtUtils-Embed libxslt libxslt-devel lsof make tree lrzsz expat expat-devel lua lua-devel openssl openssl-devel ) #安装包 software=( $zlib_name $apache_name $pcre_name $openssl_name $libxml2_name $apr_name $apr_util_name ) ############################################################################ function apache_check(){ if [ $? -ne 0 ];then echo $_ echo "please check error!!!!!" exit 2 fi } ######################################################### function package_install(){ yum -y groupinstall "Development Tools" for package_i in ${package[*]} do rpm -ql $package_i if [ $? -ne 0 ];then yum -y install $package_i echo $package_i else continue fi done cd /root/soft for software_i in ${software[*]} do echo $software_i software_ls=`echo $software_i |awk -F"[/]" '{print $NF}'` if [ -f $software_ls ];then tar zxvf $software_ls else wget $software_i tar zxvf $software_ls fi done } ######################################################### function apr_install(){ if [ ! -d /usr/local/apr ];then cd /root/soft/$apr_dir ./configure --prefix=/usr/local/apr apache_check make apache_check make install apache_check cd /root/soft/$apr_util_dir ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr --with-crypto apache_check make apache_check make install apache_check echo 2222 else echo 111 fi } function pcre_install(){ if [ ! -d /usr/local/pcre ];then cd /root/soft/$pcre_dir ./configure --prefix=/usr/local/pcre --enable-utf8 apache_check make apache_check make install apache_check echo 2222 else echo 111 fi } function apache_install(){ cd /root/soft/$apache_dir ./configure --prefix=/server/application/apache-2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-z=/root/soft/zlib-1.2.11 --with-libxml2=/root/soft/libxml2-2.9.7 --with-ssl --with-curl --with-mpm=prefork --enable-so --enable-authnz-fcgi --enable-file-cache --enable-cache --enable-cache-disk --enable-cache-socache --enable-cgi --enable-rewrite --enable-mpms-shared --enable-proxy --enable-proxy-connect --enable-proxy-ftp --enable-proxy-http --enable-proxy-fcgi --enable-proxy-scgi --enable-proxy-express --enable-proxy-hcheck --enable-slotmem-shm --enable-slotmem-plain --enable-ssl --enable-ssl-staticlib-deps --enable-static-support --enable-static-htpasswd --enable-static-htdigest --enable-static-htdbm --enable-static-ab --enable-static-logresolve --enable-unixd --enable-expires --enable-authn-dbm --enable-lua --enable-luajit --libdir=/usr/lib64 apache_check make apache_check make install apache_check } function apache_optimize(){ ln -s /server/application/apache-2.4 /usr/local/apache sed -i 's/#Server.*80/ServerName localhost:80/g' /server/application/apache-2.4/conf/httpd.conf /usr/local/apache/bin/apachectl -k start apache_check ss -tunl|grep 80 curl -I -s http://127.0.0.1|awk NR==1 apache_check echo -e "\033[32;1m 恭喜您,Apache-2.4安装成功\033[0m" } main(){ package_install apr_install pcre_install apache_install apache_optimize } main
以上是关于shell脚本自动编译安装Apache的主要内容,如果未能解决你的问题,请参考以下文章
shell脚本专题之-----------全自动编译安装mysql