码迷,mamicode.com
首页 > Web开发 > 详细

CentOS 6 apache源码编译一键部署脚本

时间:2017-05-11 14:36:31      阅读:249      评论:0      收藏:0      [点我收藏+]

标签: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环境下测试过,如果有报错可能是依赖包安装有缺失,本来想把这几个源码包上传上去的,上传一直失败,以上几个源码包需要到网上下载一下


[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 ] && {

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源码编译一键部署脚本

标签:apache源码编译脚本

原文地址:http://250919938.blog.51cto.com/962010/1924392

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!