Apache2.4.4的安装及实现service和chkconfig系统控制httpd开启关闭

[日期:2013-03-23]来源:Linux社区  作者:左安[字体:]
201253120192839760.gif

Apache2.4.4的安装及实现service和chkconfig系统控制httpd开启关闭

不废话了,根据apache2.4.4的手册我们知道还要有三个准备包,如下

:  apr-1.4.6.tar.bz2  apr-uti-1.5.1.tar.bz2和pcre-8.32.tar.bz2

安装apr

# tar -jxvf apr-1.4.6.tar.bz2

# cd apr-1.4.6

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

# make

# make install

# make clean all



安装apr-util

# tar -jxvf apr-util-1.5.1.tar.bz2

# cd apr-util-1.5.1

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

   --with-apr=/usr/local/apr

# make

# make install

# make clean all



安装pcre

# tar jxvf pcre-8.32.tar.bz2

# cd pcre-8.32

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

# make

# meke install



安装apache2.4.4

# tar -jxvf httpd-2.4.4.tar.bz2



将apr-1.4.6 拷贝到httpd-2.4.4/srclib/apr文件夹

将apr-util-1.5.1 拷贝到httpd-2.4.4/srclib/apr-util文件夹



# cp -rf apr-1.4.6 httpd-2.4.4/srclib/apr

# cp -rf apr-util-1.5.1 httpd-2.4.4/srclib/apr-util

# ./configure --prefix=/usr/local/apache2.4.4 --enable-so --enable-mods-shared=most --with-mpm=worker --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --with-included-apr

# make && make install && make clean all

下面是将lib库加入到系统自动查找的默认库当中:

root@rhel5 ld.so.conf.d]# ll /etc/ld.so.conf.d

-rw-r--r-- 1 root root 20 Sep  5  2007 qt-i386.conf

[root@rhel5 ld.so.conf.d]# vim apache2.4.4.conf //在上面的目录下新建一个文件并编辑洗出库路径

/usr/local/apache2.4.4/lib

然后进入到、etc/init.d/ 下编写一个httpd的脚本,别忘了把它变成可执行

哦(chmod a+x httpd),就是实现service和chkconfig系统控制httpd开启关闭的脚本:

#!/bin/bash

#description: httpd server

#chkconfig: - 90 90                          //这两行是实现chkconfig控制的关键

#difine path

HTTP='/usr/local/apache2.4.4/bin/httpd'

CONF='/usr/local/apache2.4.4/conf/httpd.conf'

. /etc/init.d/functions

#start

start () {

   echo -n "httpd is starting...."

   sleep 1

   $HTTP  -f $CONF

   [  $? -eq 0 ] &&touch /var/lock/subsys/http && echo -e "It is \033[31m OK \033[0m" || echo -e "It is \033[31m  FAIL \033[0m"

}

#stop

stop (){

   echo -n "httpd is stoping...."

   sleep 1

   killproc $HTTP && rm -rf /var/lock/subsys/http || echo -e "It is \033[31m FAIL \033[0m "

}

#restart

restart (){

   [ -f /var/lock/subsys/http ] && echo "httpd is runing" && exit

   stop

   start

}

case $1 in

 start )

       start

       ;;

 stop )

       stop

       ;;

 restart )

       restart

       ;;

 * )

   echo "Usag:  start|stop|restart"

       ;;

esac

到这就结束了,小编没有截图,相信有点基础的都能看懂吧




apache 2.4.4安装

[root@LinkIDC httpd-2.4.4]# ./configure --prefix=/usr/local/apache/ --enable-so --enable-mods-shared=all --with-mpm=worker --with-apr=/usr/local/apr-1.4.6/ --with-apr-util=/usr/local/apr-util-1.5.1/


下文仅仅是简单记录了apache2.4.4的安装过程,没有过多的讲解,详细了解请参考水芊芊博客http://www.cnblogs.com/qyddbear/archive/2012/05/04/2451623.html

安装环境:CentOS6.3

一、下载安装包

wget http://mirror.bjtu.edu.cn/apache/httpd/httpd-2.4.4.tar.bz2  //apache2.4.4

wget http://mirror.bjtu.edu.cn/apache/apr/apr-1.4.6.tar.bz2   //apr

wget http://mirror.bjtu.edu.cn/apache/apr/apr-util-1.5.1.tar.bz2  //apr-util

wget http://sourceforge.net/projects/pcre/files/pcre/8.32/pcre-8.32.tar.bz2/download  //pcre

APR(Apache portable Run-time libraries,Apache可移植运行库)主要为上层的应用程序提供一个可以跨越多操作系统平台使用的底层支持接口库

PCRE用于提供编译环境的函数库

其实apache有APR绑定的安装包,我没用


二、准备安装环境

解包

tar -jxvf apr-util-1.5.1.tar.bz2
tar -jxvf apr-1.4.6.tar.bz2
tar -jxvf httpd-2.4.4.tar.bz2
tar -zxvf pcre-8.32.tar.gz

1.安装C++

yum  install gcc-c++   //安装C++编译环境

2.安装 APR

cd apr-1.4.6/

./configure --prefix=/usr/local/apr-1.4.6   //配置

make    //编译

make test    //测试

make install    //安装

3.安装APR-UTIL

cd ../apr-util-1.5.1/

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

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

make

make test

make install

4.安装 PCRE

cd ../pcre-8.32/

./configure

make

make check

make install

5.安装apache

cd ../httpd-2.4.4/

./configure --prefix=/usr/local/apache --enable-mods-shared=all --with-apr=/usr/local/apr-1.4.6/ --with-apr-util=/usr/local/apr-util-1.5.1/    //--prefix指定安装路径,--enable-mods-shared启用所有支持的动态加载模块,--with-apr指定APR路径,--with-apr-util指定APR-util路径

make

make install

/usr/local/apache/bin/apachectl start    //启动apache


三、注册apache为系统服务

cp  /usr/local/apache/apachectl /etc/init.d/httpd    //把apache启动脚本复制到系统脚本目录下

vi  /etc/init.d/httpd在第一行下插入# chkconfig: 2345 85 35    //修改脚本用于在运行界别2345下自启动,并指定启动脚本序号为85,关闭脚本序号为35

chkconfig --add httpd    //注册为自启动服务

四、修改防火墙设置

vi /etc/sysconfig/iptables   //编辑iptables配置文件

-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT     //在适当位置插入

service iptables restart    //重启防火墙服务