Linux下apache和fcgi的关系,Linux下编译安装Apache httpd 2.4

目录

一 编译安装的优势

二httpd的版本

三httpd 24的新特性

四 编译安装httpd 24

五 配置http24启动及停止

六 配置man手册

七 验证

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件之一。当前Apache版本为2.4,本文主要描述基于CentOS 6.5以源码方式安装Apache httpd。

一、编译安装的优势

源码的编译安装一般由3个步骤组成:

配置(configure),通常依赖gcc编译器,binutils,glibc。配置软件特性,检查编译环境,生成 Makefile文件

编译(make)

安装(make install)

优势

自定义软件功能

优化编译参数,提高性能

解决不必要的软件间依赖

方便清理与卸载

configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –-help输出详细的选项列表。

常用的选项

--prefix

该选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,

库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share

如果配置--prefix,如: ./configure --prefix=/usr/local/test

则可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。

用了—prefix选项的?一个好处是卸载软件或移植软件。

当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;

移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。

当然要卸载程序,也可以在原来的make目录下用一次make uninstall?但前提是make文件指定过uninstall。

二、httpd的版本

版本:

httpd-1.3

httpd-2.0

httpd-2.2

httpd-2.4

三、httpd 2.4的新特性

1) MPM支持运行时装载

--enable-mpms-shared=all --with-mpm=prefork|worker|event

2) 支持event MPM

3) 异步读写支持

4) 支持每模块及每目录分别使用不同的日志级别

5) 支持per-request(即支持, , and 条件判断)

6) 增强版的表达式分析器;

7) 支持毫秒级keepalive timeout;

8) 基于FQDN(域名)的虚拟主机不再需要NameVirtualHost;

9) 支持用户使用自定义变量;

新增一些模块:mod_proxy_fcgi, mod_ratelimit, mod_request, mod_remoteip

修改了一些配置机制:不再支持使用order, allow, deny来实现基于IP的访问控制;

四、编译安装httpd 2.4

1、依赖关系

httpd依赖于apr, apr-util

apr全称为apache portable runtime,能实现httpd跨平台运行

httpd-2.4 依賴于1.4+及以上版本的apr

apr-1.5.0.tar.bz2

apr-util-1.5.3.tar.bz2

httpd-2.4.9.tar.bz2

pcre-devel包

openssl-devel

2、编译安装

# yum install gcc

# yum install pcre-devel

# tar xf apr-1.5.0.tar.bz2

# cd apr-1.5.0

# ./configure --prefix=/usr/local/apr   (--prefix指定apr安装的目录)

# make

# make  install

# tar xf apr-util-1.5.3.tar.bz2

# cd apr-util-1.5.3

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

# make && make install ###该项被漏掉,补充@20160714

# tar xf httpd-2.4.9.tar.bz2

以下为几个主要的配置项

--sysconfdir=/etc/httpd24  指定配置文件路径

--enable-so  启动模块动态装卸载

--enable-ssl 编译ssl模块

--enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)

--enable-rewrite  支持url重写     --Author : Leshami

--with-zlib  支持数据包压缩       --Blog   : http://blog.csdn.net/leshami

--with-pcre  支持正则表达式

--with-apr=/usr/local/apr  指明依赖的apr所在目录

--with-apr-util=/usr/local/apr-util/  指明依赖的apr-util所在的目录

--enable-modules=most      启用的模块

--enable-mpms-shared=all   以共享方式编译的模块

--with-mpm=prefork         指明httpd的工作方式为prefork

# cd httpd-2.4.9

# ./configure

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

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

--prefix=/usr/local/apache

--sysconfdir=/etc/httpd24

--enable-so

--enable-ssl

--enable-cgi

--enable-rewrite

--with-zlib

--with-pcre

--with-mpm=prefork

--enable-modules=most

--enable-mpms-shared=all

# make

# make install

五、配置http2.4启动及停止

1、修改端口号

修改端口号使得与2.2版本使用不同的端口,可以同时运行,修改后如下

# cat /etc/httpd24/httpd.conf |grep Listen |grep -v ^#

Listen 8080

2、启动与停止

# /usr/local/apache/bin/apachectl start

# netstat -nltp|grep 80

tcp        0      0 :::8080    :::*     LISTEN      17365/httpd

# /usr/local/apache/bin/apachectl status

Not Found

The requested URL /server-status was not found on this server.

通过修改httpd.conf,增加如下配置

# grep server-stat /etc/httpd24/httpd.conf -A5

SetHandler server-status

#    Order deny,allow

#    Deny from all

Allow from 192.168.21.157 192.168.21.10

# /usr/local/apache/bin/apachectl restart

# /usr/local/apache/bin/apachectl status

Apache Server Status for localhost (via 127.0.0.1)

Server Version: Apache/2.4.9 (Unix)

Server MPM: prefork

..........

# /usr/local/apache/bin/apachectl stop

3、配置自启动文件

可以通过复制2.2版本的启动文件,修改相关路径后将2.4版作为单独服务运行,如下

注启动文件pid文件位置要配置成与/usr/local/apache/bin/apachectl -V看到的pid位置一致

查看pid位置

# /usr/local/apache/bin/apachectl -V|grep pid

-D DEFAULT_PIDLOG="logs/httpd.pid"

# cp /etc/init.d/httpd /etc/init.d/httpd24

# vi /etc/init.d/httpd24

# diff /etc/init.d/httpd /etc/init.d/httpd24

26,27c26,27

< if [ -f /etc/sysconfig/httpd ]; then

---

> if [ -f /etc/httpd24 ]; then

>         . /etc/httpd24

42,46c42,46

< apachectl=/usr/sbin/apachectl

< httpd=${HTTPD-/usr/sbin/httpd}

< prog=httpd

< pidfile=${PIDFILE-/var/run/httpd/httpd.pid}

< lockfile=${LOCKFILE-/var/lock/subsys/httpd}

---

> apachectl=/usr/local/apache/bin/apachectl

> httpd=${HTTPD-/usr/local/apache/bin/httpd}

> prog=httpd24

> pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}

> lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

# service httpd24 start

Starting httpd24:                          [  OK  ]

# service httpd24 status

httpd (pid  15641) is running...

# netstat -nltp|grep 80

tcp        0      0 :::80     :::*     LISTEN      15677/httpd   ###2.2版httpd

tcp        0      0 :::8080   :::*     LISTEN      15641/httpd   ###2.4版httpd

可以通过复制apachectl文件生成服务脚本

# cp /usr/local/apache/bin/apachectl /etc/init.d/httpd249

# service httpd249 start

# service httpd249 status

ELinks: Connection refused    ###该方式无法查看到状态

[root@orasrv1 bin]# netstat -nltp|grep 80

tcp        0      0 :::8080     :::*     LISTEN      15999/httpd

最后将配置文件添加到服务,以下为http24为例

# chkconfig --add httpd24

# chkconfig httpd24 on

六、配置man手册

vi /etc/man.config

MANPATH /usr/local/apache/man

七、验证

# echo "This is a apached 2.4.9 version">>/usr/local/apache/htdocs/index.html

# curl http://192.168.21.10:8080

It works!

This is a apached 2.4.9 version

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值