天天看點

CentOS 6 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環境下測試過,如果有報錯可能是依賴包安裝有缺失,本來想把這幾個源碼包上傳上去的,上傳一直失敗,以上幾個源碼包需要到網上下載下傳一下

軟體包:連結:http://pan.baidu.com/s/1jIyZrRS 密碼:q9uu

[root@linux-node7 ~]# 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 ] && {

} || 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 "####################準備編譯##################"

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 "###########安裝pcre######################"

sleep 4

tar -jxvf pcre-8.31.tar.bz2

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

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

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

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安裝失敗"

##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