httpd-2.4源码编译安装

一、httpd-2.4的新特性

1)MPM支持在运行时装载;

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

2)支持event mpm

3)异步读写

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

5)每请求的配置;<If>,<Elseif>

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

7)毫秒级的keep alive的timeout

8)基于FQDN的虚拟主机不再需要NameVirtualHost指令;

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

10)新增了一些模块:mod_proxy_fcgi, mode_ratelimit, mod_request, mod_remoteip

11)修改了一些配置机制。不再支持使用order, allow, deny定义基于ip的访问控制,改为require

二、安装配置开始

1、解决依赖关系    
安装 apr     

1
2
3
[root@server ~] # cd apr-1.5.0     
[root@server apr-1.5.0] # ./configure --prefix=/usr/local/apr     
[root@server apr-1.5.0] # make && make install

安装 apr-util    

1
2
3
4
[root@server ~] # tar  xf apr-util-1.5.3.tar.bz2     
[root@server ~] # cd apr-util-1.5.3     
[root@server apr-util-1.5.3] # ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/     
[root@server apr-util-1.5.3] #  make && make install

安装其他依赖关系,使用yum 就可以解决。这一过程可在安装httpd时候根据提示具体解决。

2、安装 http 2.4.9    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@server ~] # tar xf httpd-2.4.9.tar.bz2     
[root@server ~] # cd httpd-2.4.9     
[root@server httpd-2.4.9] # ./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-modules=most --enable-so  --enable-deflate --enable-ssl --enable-cgi --enable-rewrite  --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-mpm=event  --enable-mpms-shared=all
# --prefix 指明安装目录
# --sysconfdir 指明配置文件目录
# --enable-modules=most 启用大多数的模块
# --enable-so 允许动态加载模块
# --enable-deflate 允许使用压缩传输
# --enable-ssl  允许使用 SSL
# --enable-cgi 允许使用CGI
# --enable-rewrite 允许使用重写
# --with-apr --with-apr-util 指明 apr 和apr-util安装目录
# --with-mpm=event MPM为event
# --enable-mpms-shared=all 将所有的 MPM 编译从动态模块 
 
#########################构建MPM为静态模块#################################
在全部平台中,MPM都可以构建为静态模块。在构建时选择一种MPM,链接到服务器中。如果要改变MPM,必须重新构建。为了使用指定的MPM,请在执行configure脚本时,使用参数 --with-mpm=NAME。NAME是指定的MPM名称。编译完成后,可以使用 . /httpd  -l 来确定选择的MPM。 此命令会列出编译到服务器程序中的所有模块,包括 MPM。
 
#########################构建 MPM 为动态模块############################
在Unix或类似平台中,MPM可以构建为动态模块,与其它动态模块一样在运行时加载。 构建 MPM 为动态模块允许通过修改LoadModule指令内容来改变MPM,而不用重新构建服务器程序。在执行configure脚本时,使用-- enable -mpms-shared选项即可启用此特性。当给出的参数为all时,所有此平台支持的MPM模块都会被安装。还可以在参数中给出模块列表。默认MPM,可以自动选择或者在执行configure脚本时通过--with-mpm选项来指定,然后出现在生成的服务器配置文件中。编辑LoadModule指令内容可以选择不同的MPM。
[root@server httpd-2.4.9] # make && make install

3、导出二进制文件和帮助手册    

1
2
3
4
5
6
vim  /etc/profile .d /apache .sh   
PATH= /usr/local/apache24/bin :$PATH     
/etc/profile .d /apache .sh
 
vim  /etc/man .config    
MANPATH  /usr/local/apache24/man

4、提供服控制动脚本:    

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
[root@server httpd24] # cat /etc/init.d/httpd24     
#!/bin/bash     
#     
# httpd24        Startup script for the Apache HTTP Server     
#     
# chkconfig: - 85 15
# Source function library.    
/etc/rc .d /init .d /functions
HTTPD_LANG=${HTTPD_LANG- "C" }    
INITLOG_ARGS= ""     
apachectl= /usr/local/apache24/bin/apachectl     
httpd=${HTTPD- /usr/local/apache24/bin/httpd }    
prog=httpd     
pidfile=${PIDFILE- /usr/local/apache24/logs/httpd .pid}     
lockfile=${LOCKFILE- /var/lock/subsys/httpd }     
RETVAL=0    
STOP_TIMEOUT=${STOP_TIMEOUT-10}
 
start() {
         echo  -n $ "Starting $prog: "
         LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
         RETVAL=$?
         echo
         [ $RETVAL = 0 ] &&  touch  ${lockfile}
         return  $RETVAL
}
 
stop() {
     echo  -n $ "Stopping $prog: "
     killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
     RETVAL=$?
     echo
     [ $RETVAL = 0 ] &&  rm  -f ${lockfile} ${pidfile}
}
 
reload() {
     echo  -n $ "Reloading $prog: "
     if  ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >& /dev/null then
         RETVAL=6
         echo  $ "not reloading due to configuration syntax error"
         failure $ "not reloading $httpd due to configuration syntax error"
     else
         # Force LSB behaviour from killproc
         LSB=1 killproc -p ${pidfile} $httpd -HUP
         RETVAL=$?
         if  [ $RETVAL - eq  7 ];  then
             failure $ "httpd shutdown"
         fi
     fi
     echo
}
 
case  "$1"  in
   start)
     start
     ;;
   stop)
     stop
     ;;
   status)
         status -p ${pidfile} $httpd
     RETVAL=$?
     ;;
   restart)
     stop
     start
     ;;
   condrestart|try-restart)
     if  status -p ${pidfile} $httpd >& /dev/null then
         stop
         start
     fi
     ;;
   force-reload|reload)
         reload
     ;;
   graceful|help|configtest|fullstatus)
     $apachectl $@
     RETVAL=$?
     ;;
   *)
     echo  $ "Usage: $prog {start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
     RETVAL=2
esac
 
exit  $RETVAL


5、虚拟主机 和 SSL 的实现 

虚拟主机:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
vim  /etc/http24/http .conf:
注释:DocumentRoot  "/usr/local/apache24/htdocs"    
开启:Include  "extra/httpd-vhosts.conf"
 
vim  /etc/http24/extra/httpd-vhosts .conf
<VirtualHost *:80>    
     ServerAdmin webmaster@guoting.com     
     DocumentRoot  "/web/vhosts/www1"     
     ServerName www1.guoting.com     
     <Directory  "/web/vhosts/www1" >     
         Require all granted     
     < /Directory >     
     ErrorLog  "logs/www1.guoting.com.error_log"     
     CustomLog  "logs/www1.guoting.com.access_log"  common     
< /VirtualHost >
<VirtualHost *:80>    
     ServerAdmin webmaster2@guoting.com     
     DocumentRoot  "/web/vhosts/www2"     
     ServerName www2.guoting.com     
     <Directory  "/web/vhosts/www2" >     
         Require all granted     
     < /Directory >     
     ErrorLog  "logs/www2.guoting.com.error_log"     
     CustomLog  "logs/www2.guoting.com.access_log"  common     
< /VirtualHost >

在上一步的基础上实现ssl:     

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
##########################加载模块读取配置文件############################   
vim  /etc/http24/http .conf
开启:Include  "extra/httpd-ssl.conf"    
LoadModule socache_shmcb_module modules /mod_socache_shmcb .so     
LoadModule ssl_module modules /mod_ssl .so
当然可以动态添加 MPM 的方式:(选择添加)    
LoadModule mpm_event_module modules /mod_mpm_event .so
 
##############################制作证书#######################################  
在服务端:     
( umask  077;openssl genrsa -out  /etc/pki/CA/private/cakey .pem 2048)     
openssl req -new -x509 -key  /etc/pki/CA/private/cakey .pem -out  /etc/pki/CA/cacert .pem -days 1000     
touch  index.txt     
echo  "01"  > serial
在客户端:    
( umask  077;openssl genrsa -out  /etc/httpd24/httpd .key 2048)     
openssl req -new -key  /etc/httpd24/httpd .key -out  /etc/httpd24/httpd .csr     
将 httpd.csr 传到服务端签名:
在服务端:    
openssl ca - in  /root/httpd .csr -out  /root/httpd .crt -days 1000     
将签好的证书,httpd.crt 传回到客户端,放到 etc /httpd24/  目录下
 
#############################修改配置文件#############################
vim  /etc/http24/extra/httpd-ssl .conf
# 添加:    
<VirtualHost *:443>     
     DocumentRoot  "/web/vhosts/www1"     
     <Directory  "/web/vhosts/www1" >     
         Options none     
         Require all granted     
     < /Directory >     
     ServerName www1.guoting.com:443     
     ServerAdmin root@guoting.com     
     ErrorLog  "/web/vhosts/www1/logs/error_log"     
     TransferLog  "/web/vhosts/www1/logs/access_log"     
     SSLEngine on     
     SSLCertificateFile  "/etc/httpd24/httpd.crt"     
     SSLCertificateKeyFile  "/etc/httpd24/httpd.key"     
< /VirtualHost >  
<VirtualHost *:443>    
     DocumentRoot  "/web/vhosts/www2"     
     <Directory  "/web/vhosts/www2" >     
         Options none     
         Require all granted     
     < /Directory >     
     ServerName www2.guoting.com:443     
     ServerAdmin root@guoting.com     
     ErrorLog  "/web/vhosts/www2/logs/error_log"     
     TransferLog  "/web/vhosts/www2/logs/access_log"     
     SSLEngine on     
     SSLCertificateFile  "/etc/httpd24/httpd.crt"     
     SSLCertificateKeyFile  "/etc/httpd24/httpd.key"     
< /VirtualHost >
#######################创建日志目录############################    
mkdir  /web/vhosts/www1/logs  -p     
mkdir  /web/vhosts/www2/logs  -p
 
###################测试###################################
在浏览器中输入测试,以 Linux 为例:
输入:https: //www1 .guoting.com,导入证书即可访问。









本文转自 羊木狼 51CTO博客,原文链接:http://blog.51cto.com/guoting/1538388,如需转载请自行联系原作者
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值