设为首页 收藏本站
查看: 924|回复: 0

[经验分享] apache2.4.17 编译安装

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2015-11-6 09:48:55 | 显示全部楼层 |阅读模式
准备安装包:
        httpd-2.4.17.tar
        apr-util-1.5.4.tar
        apr-1.5.2.tar
        httpd-2.4依赖于较高版本的apr(1.5以上)和apr-util
        apr: apache portable runtime(移植运行)是一个让api,让apache能够跨平台的工具,是一个底层库
        apache支持正则表达式依赖于pcre(正则表达式函数库),安装其开发包pcre-devel即可
    下载地址:
          http://apr.apache.org/

安装步骤:
1. 先安装编译开发环境和一些必须的包
1
2
3
    yum install cmake #编译时要用到
    yuminstall pcre-devel #使用pcre正则表达式要用到
    yuminstall gcc gcc-c++ #编译工具



2. 安装apache服务器
         (a)  解压httpd安装包
1
    tar xvzf httpd-2.4.17.tar.gz



       (b) httpd需要apr和apr-util,解压后放在已解压的httpd-2.4.17/srclib目录下,并把目录名字分别改为apr和apr-util。后
       面编绎要用到--with-included-apr选项,安装apr和apr-util库
1
2
    tar xvzf apr-1.5.2.tar.gz -C httpd-2.4.17/srclib
    tar xvzf apr-util-1.5.4.tar.gz -C httpd-2.4.17/srclib



           (c)  开始安装apache,根据需要调整所需选项
1
2
./configure --prefix=/usr/local/apache2--with-included-apr --sysconfdir=/etc/httpd2.4/conf/ --enable-so--enable-rewrite --with-pcre --enable-modules=most --with-zlib --enable-cgi
            make && make install




            各项参数含义:
            --prefix=/usr/local/apache  #指定安装目标路径
             --sysconfdir=/etc/httpd2.4     #指定配置文件安装位置
             --enable-so                 #支持动态共享模块
             --enable-cgi                #启用支持cgi
             --enable-rewirte            #支持URL重写
             --with-zlib                #网络上发送数据报文时通用压缩库的API
             --enable-ssl                #启用支持ssl
             --with-apr=/usr/local/apr   #指定依赖包apr路径
             --with-apr-util=/usr/local/apr-util  #指定依赖包apr-util路径
             --enable-modules=all|most            #安装全部模块或大多数模块
             --enable-mpms-shared=all             #支持全部多道处理方式
             --with-event:                        #指定默认使用event
             --enable-cgid :启用支持带线状图形的CGI脚本 MPMs

          (d)  编辑/usr/local/apache2/conf/httpd.conf 修改用户名和组名为apache,没有的话就创建一个。默认用户和组为
        daemon
            
1
2
3
    vim /usr/local/apache2/conf/httpd.conf
    Userdaemon        -> User apache
    Groupdaemon       -> Group apache





           (e) 启动测试
1
2
    /usr/local/apache2/bin/apachectl start
    curl http://localhost



          显示<html><body><h1>Itworks!</h1></body></html> 即为成功启动

3. 后续的配置
      (a) 导出头文件
1
2
    ln -sv /usr/local/apache2/include/ /usr/include/httpd
    "/usr/include/httpd" -> "/usr/local/apache2/include/"





        (b) 导出库文件(没有生成库文件)

        (c) 导出man手册
                 vim/etc/man.conf
        添加 MANPATH /usr/local/apache2/man
        或者直接使用命令:man -M /usr/local/apache2/man apache

        (d) 添加PATH路径
                 vim/etc/profile.d/httpd2.4.sh
        添加  exportPATH=/usr/local/apache2/bin:$PATH

        (e) 创建启动服务和开机启动
                   修改/etc/httpd2.4/conf/httpd.conf添加一行PidFile “/var/run/httpd2.4.pid”
                   然后修改/etc/init.d/httpd,以下3行改为相对应的地址
                   apachectl=/usr/local/apache2/bin/apachectl
                   httpd=${HTTPD-/usr/local/apache2/bin/httpd}
                   pidfile=${PIDFILE-/var/run/httpd2.4.pid}
                  
                   service httpd start 即可启动
            注意:
            编译安装2.4版本的主配置文件/etc/apache2.4没有像yum安装的2.2版本的主配置文件/etc/httpd/conf/httpd.conf
                   一样分为三段,分段配置文件为/etc/apache2.4/extra/*.conf
            httpd-vhost.conf:配置虚拟主机
            httpd-ssl.conf:配置ssl
            httpd-mpm.conf:配置MPM
            
        (f) 日志轮循设置
                复制安装包中 /httpd-2.4.17/build/rpm/httpd.logrotate到 /etc/logrotate.d/ 目录 
                    httpd.logrotate中 /var/log/httpd/*log 可以更改为自己需要的路径,例:/usr/local/apache2/logs/*log
                执行logrotate -d来dbug下有没错误
                    logrotate -d /etc/logrotate.conf
                 执行logrotate 使日志轮循生效
                    logrotate /etc/logrotate.conf
               至此apache安装完成。

4. httpd-2.4新特性
         (a) MPM支持在运行时装载:
               --enable-mpms-shared=all(编译所有支持的MPM) --with-mpm=event(设定默认启用的MPM)
         (b)支持event
         (c)  异步读写
         (d)  在每模块及每目录上指定日志级别
         (e)  每请求配置:<If>,<Elseif>
         (f) 增强版的表达分析器
         (g) 毫秒级的keepalivetimout
         (h)  基于FQDN的虚拟主机不再需要NameVirtualHost指令
         (i)   配置文件支持使用自定义变量
               新增了一些模块:mod_proxy_fcgi,mod_ratelimit,mod_request,mod_remoteip
               对于基于IP的访问控制做了修改:不再支持用order,allow,deny这些机制而是统一使用require进行
            注意:

            1. 访问控制参数的写法:
                 原本使用 Order Deny / Allow 的方式,改用 Require
                 require all granted 允许所有访问
                 require all denied  拒绝所有访问
                 仅允许IP为192.168.1.1的主机访问
                 <RequireAll>
                     require all granted
                     require ip 192.168.1.1 (也可以写成网段)
                 </RequireAll>
                  
                禁止192.168.1.2的主机访问,其他的都允许
                <RequireAll>
                    require all granted
                    require not ip 192.168.1.2
                </RequireAll>


            2. Namevirtualhost参数被移除
              3. RewriteLogLevel 参数改为 logLevel
              4. 压缩使用mod_deflate 外, Apache 2.4 中还需要mod_filter
                  SSL开启mod_ssl 外,Apache 2.4 中还需要mod_socache_shmcb

附上原有yum安装后,经修改的/etc/init.d/httpd 脚本,没装过httpd的可以直接使用:
  1#!/bin/bash
  2 #
  3 #httpd        Startup script for theApache HTTP Server
  4 #
  5 #chkconfig: - 85 15
  6 #description: The Apache HTTP Server is an efficient and extensible  \
  7#              server implementing thecurrent HTTP standards.
  8 #processname: httpd
  9 #config: /etc/httpd/conf/httpd.conf
10 #config: /etc/sysconfig/httpd
11 #pidfile: /var/run/httpd/httpd.pid
12 #
13### BEGIN INIT INFO
14 #Provides: httpd
15 #Required-Start: $local_fs $remote_fs $network $named
16 #Required-Stop: $local_fs $remote_fs $network
17 #Should-Start: distcache
18 #Short-Description: start and stop Apache HTTP Server
19 #Description: The Apache HTTP Server is an extensible server
20#  implementing the current HTTPstandards.
21 ###END INIT INFO
22
23 #Source function library.
24 ./etc/rc.d/init.d/functions
25
26if [ -f /etc/sysconfig/httpd ]; then
27         . /etc/sysconfig/httpd
28fi
29
30 #Start httpd in the C locale by default.
31HTTPD_LANG=${HTTPD_LANG-"C"}
32
33 #This will prevent initlog from swallowing up a pass-phrase prompt if
34 #mod_ssl needs a pass-phrase from the user.
35INITLOG_ARGS=""
36
37 #Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
38 #with the thread-based "worker" MPM; BE WARNED that some modules maynot
39 #work correctly with a thread-based MPM; notably PHP will refuse to start.
40
41 #Path to the apachectl script, server binary, and short-form for messages.
42#apachectl=/usr/sbin/apachectl
43 apachectl=/usr/local/apache/bin/apachectl
44 httpd=${HTTPD-/usr/local/apache/bin/httpd}
45prog=httpd
46pidfile=${PIDFILE-/var/run/httpd/httpd2.4.pid}
47 lockfile=${LOCKFILE-/var/lock/subsys/httpd}
48RETVAL=0
49 STOP_TIMEOUT=${STOP_TIMEOUT-10}
50
51 #The semantics of these two functions differ from the way apachectl does
52 #things -- attempting to start while running is a failure, and shutdown
53 #when not running is also a failure.  Sowe just do it the way init scripts
54 #are expected to behave here.
55start() {
56        echo -n $"Starting $prog: "
57        LANG=$HTTPD_LANG daemon --pidfile=${pidfile} $httpd $OPTIONS
58        RETVAL=$?
59        echo
60        [ $RETVAL = 0 ] && touch ${lockfile}
61        return $RETVAL
62 }
63
64 #When stopping httpd, a delay (of default 10 second) is required
65 #before SIGKILLing the httpd parent; this gives enough time for the
66 #httpd parent to SIGKILL any errant children.
67stop() {
68        echo -n $"Stopping $prog: "
69        killproc -p ${pidfile} -d ${STOP_TIMEOUT} $httpd
70        RETVAL=$?
71        echo
72        [ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
73 }
74reload() {
75    echo -n $"Reloading $prog: "
76    if ! LANG=$HTTPD_LANG $httpd $OPTIONS -t >&/dev/null; then
77         RETVAL=6
78        echo $"not reloading due to configuration syntax error"
79        failure $"not reloading $httpd due to configuration syntaxerror"
80    else
81         # Force LSB behaviour from killproc
82        LSB=1 killproc -p ${pidfile} $httpd -HUP
83        RETVAL=$?
84        if [ $RETVAL -eq 7 ]; then
85            failure $"httpd shutdown"
86        fi
87    fi
88    echo
89 }
90
91 #See how we were called.
92case "$1" in
93  start)
94        start
95        ;;
96  stop)
97        stop
98        ;;
99  status)
100        status -p ${pidfile} $httpd
101        RETVAL=$?
102        ;;
103  restart)
104        stop
105        start
106        ;;
107  condrestart|try-restart)
108        if status -p ${pidfile} $httpd >&/dev/null; then
109                 stop
110                 start
111        fi
112        ;;
113  force-reload|reload)
114        reload
115        ;;
116  graceful|help|configtest|fullstatus)
117        $apachectl $@
118        RETVAL=$?
119        ;;
120  *)
121        echo $"Usage: $prog{start|stop|restart|condrestart|try-restart|force-reload|reload|status|fullstatus|graceful|help|configtest}"
122        RETVAL=2
123 esac
124
125 exit $RETVAL






运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-135766-1-1.html 上篇帖子: 搭建CA认证中心,使用CA证书搭建HTTPS 下篇帖子: apache配置httpd-vhosts
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表