1. 程式人生 > >CentOS 6 apache源碼編譯一鍵部署腳本

CentOS 6 apache源碼編譯一鍵部署腳本

apache源碼編譯腳本

需求:源碼編譯apache

環境:CentOS 6 64位系統安裝的桌面版

軟件:httpd-2.4.12.tar.gz、pcre-8.31.tar.bz2、apr-util-1.5.3、apr-1.5.1.tar.gz

備註:目前只在centos 6環境下測試過,如果有報錯可能是依賴包安裝有缺失,本來想把這幾個源碼包上傳上去的,上傳一直失敗,以上幾個源碼包需要到網上下載一下


[[email protected] ~]# cat apache.sh

#!/bin/bash

#

#適用版本CentOS 6 64位

#2017.5.11

. /etc/init.d/functions

dir=/root/test

del_dir() {

read -p "需要刪除${dir} 是否刪除[Y|y/N|n]:" del

case $del in

Y|y)

rm -rf $dir

mkdir $dir

cd $dir

;;

N|n)

echo "安裝終止"

exit 7

;;

*)

echo "請輸入正確的值"

exit 8

;;

esac

}

[ ! -d $dir ] && {

mkdir $dir

cd $dir

} || del_dir

yum -y install gcc gcc-c++ cmake ncurses-devel bison ncurses

sleep 2

echo "##################################下載依賴包###################################"

wget http://172.2.0.68/apr-1.5.1.tar.gz

wget http://172.2.0.68/apr-util-1.5.3.tar.gz

wget http://172.2.0.68/pcre-8.31.tar.bz2

wget http://172.2.0.68/httpd-2.4.12.tar.gz

#wget http://172.2.0.68/configure.txt

[ $? -eq 0 ] && echo "下載apr依賴包,準備安裝" || exit 7

sleep 5

tar -xzvf apr-1.5.1.tar.gz

tar -xzvf apr-util-1.5.3.tar.gz

sleep 3

cd apr-1.5.1

[ $? -eq 0 ] && {

./configure --prefix=/usr/local/apr

} || {

echo "解壓包出錯"

exit 9

}

echo "####################準備編譯##################"

sleep 3

make && make install

cd ..

[ $? -eq 0 ] && cd apr-util-1.5.3 || exit 5

./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr

echo "####################準備編譯##################"

make && make install

cd ..

echo "###########安裝pcre######################"

sleep 4

tar -jxvf pcre-8.31.tar.bz2

[ $? -eq 0 ] && cd pcre-8.31 || exit 6

./configure --prefix=/usr/local/pcre

make && make install

echo "###########安裝apache###############"

cd ..

groupadd www

useradd -M -g www -s /sbin/nologin www

tar -xzvf httpd-2.4.12.tar.gz

[ $? -eq 0 ] && cd httpd-2.4.12 || exit 3

echo "##################編譯apache##################"

#configure

./configure --prefix=/usr/local/apache --enable-so --enable-deflate --enable-expires --enable-headers --enable-modules=most --with-mpm=worker --enable-ssl --enable-rewite --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

[ $? -eq 0 ] && echo "編譯apache成功" || {

echo "編譯apache失敗"

exit 5

}

echo "###################安裝Apache##############################"

sleep 2

make && make install

[ $? -eq 0 ] && echo "##################apache安裝成功#######" || {

echo "apache安裝失敗"

exit 7

}

sleep 2

##apache服務啟動腳本

cp build/rpm/httpd.init /etc/init.d/httpd

chmod 700 /etc/init.d/httpd

sed -i ‘s/HTTPD-\/usr\/sbin\/httpd/HTTPD-\/usr\/local\/apache\/bin\/httpd/g‘ /etc/init.d/httpd

sed -i ‘s/PIDFILE-\/var\/run/PIDFILE-\/usr\/local\/apache\/logs/g‘ /etc/init.d/httpd

sed -i ‘s/CONFFILE=\/etc\/httpd\/conf\/httpd.conf/CONFFILE=\/usr\/local\/apache\/conf\/httpd.conf/g‘ /etc/init.d/httpd

[ $? -eq 0 ] && echo "#########繼續############" || exit 5

chkconfig --add httpd

[ $? -eq 0 ] && echo "###########添加httpd啟動項成功########" || echo "###################添加httpd啟動項失敗############"

chkconfig --level 35 httpd on


本文出自 “常想一二” 博客,請務必保留此出處http://250919938.blog.51cto.com/962010/1924392

CentOS 6 apache源碼編譯一鍵部署腳本