longpan 发表于 2018-11-20 13:59:31

apache2.4.17 编译安装

  

准备安装包:
      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/
          http://httpd.apache.org/download.cgi
  

安装步骤:
1. 先安装编译开发环境和一些必须的包
    yum install pcre-devel #使用pcre正则表达式要用到
    yum install gcc gcc-c++ #编译工具2. 安装apache服务器
         (a)解压httpd安装包
    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库
    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
    注意:要确保名称为apr和apr-util 不然会提示找不到
    mv apr-1.5.2 apr
    mv apr-util-1.5.4 apr-util           (c)开始安装apache,根据需要调整所需选项
./configure --prefix=/usr/local/apache2 --with-included-apr --sysconfdir=/usr/local/apache2/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
              
    vim /usr/local/apache2/conf/httpd.conf
    Userdaemon      -> User apache
    Groupdaemon       -> Group apache  

            (e) 启动测试
    /usr/local/apache2/bin/apachectl start
    curl http://localhost            显示Itworks! 即为成功启动
  

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

        (b) 导出库文件(没有生成库文件)
  
        (c) 导出man手册
                 vim /etc/man.conf
     添加 MAN PATH /usr/local/apache2/man
     或者直接使用命令:man -M /usr/local/apache2/man apache
  
         (d) 添加PATH路径
                 vim /etc/profile.d/httpd2.4.sh
      添加export PATH=/usr/local/apache2/bin:$PATH
  
        (e) 创建启动服务和开机启动
                     修改/usr/local/apache2/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)每请求配置:,
   (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的主机访问
     
         require all granted
         require ip 192.168.1.1 (也可以写成网段)
     
                 
      禁止192.168.1.2的主机访问,其他的都允许
     
        require all granted
        require not ip 192.168.1.2
     
  

   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
   93start)
   94      start
   95      ;;
   96stop)
   97      stop
   98      ;;
   99status)
  100      status -p ${pidfile} $httpd
  101      RETVAL=$?
  102      ;;
  103restart)
  104      stop
  105      start
  106      ;;
  107condrestart|try-restart)
  108      if status -p ${pidfile} $httpd >&/dev/null; then
  109               stop
  110               start
  111      fi
  112      ;;
  113force-reload|reload)
  114      reload
  115      ;;
  116graceful|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]
查看完整版本: apache2.4.17 编译安装