apache-2.2与新出的apache-2.4安装不同的地方在于,2.4版的已经不自带apr库,所以在安装apache-2.4之前,需要下载apr。

1、下载软件

  1. cd /tmp
  2. wget http://mirrors.axint.net/apache//httpd/httpd-2.4.2.tar.gz
  3. wget http://mirrors.axint.net/apache//apr/apr-1.4.6.tar.gz
  4. wget http://mirrors.axint.net/apache//apr/apr-util-1.4.1.tar.gz
  5. tar xzf httpd-2.4.2.tar.gz
  6. tar xzf apr-1.4.6.tar.gz
  7. tar xzf apr-util-1.4.1.tar.gz

2、移动apr到srclib

  1. mv apr-1.4.6 httpd-2.4.2/srclib/apr
  2. mv apr-util-1.4.1 httpd-2.4.2/srclib/apr-util

3、安装apache-2.4

  1. cd /tmp/httpd-2.4.2
  2. ./configure --prefix=/usr/local/apache --enable-so --enable-deflate=shared --enable-ssl=shared --enable-expires=shared  --enable-headers=shared --enable-rewrite=shared --enable-static-support  --with-included-apr --with-mpm=prefork
  3. make && make install
  4. cp -f build/rpm/httpd.init /etc/init.d/httpd
  5. chmod +x /etc/init.d/httpd
  6. chkconfig --add httpd
  7. chkconfig httpd on
  8. cd /etc
  9. mv httpd httpd_old
  10. ln -s /usr/local/apache/ httpd
  11. cd /usr/sbin/
  12. ln -fs /usr/local/apache/bin/httpd
  13. ln -fs /usr/local/apache/bin/apachectl
  14. cd /var/log
  15. rm -rf httpd/
  16. ln -s /usr/local/apache/logs httpd
  17. Apache部分优化:

    • 1. 移除不用的模块。
    • 2. 使用 mod_disk_cache NOT mod_mem_cache 。
    • 3. 扁平架构配置mod_disk_cache。
    • 4. 安装恰当的Expires, Etag, 和 Cache-Control Headers 。
    • 5. 将缓存放在独立的磁盘
    • 6. 使用管道日志替代直接记录
    • 7. 将日志放在不同的磁盘
    • 8. 使用 mod_gzip/mod_deflate 。
    • 9. 将HostnameLookups关闭.
    • 10. 避免在configs中使用主机名。
    • 11. 使用持久连接。
    • 12. 不要设置KeepAliveTimeout太高。
    • 13. 禁用.htaccess。
    • 14. 允许symlinks。
    • 15. 关闭ExtendedStatus。
    • 16. 避免在DirectoryIndex中通配符
  18. OS 部分:

    • 17. 提高Swappiness。
    • 18. 提高写入缓冲器( Write Buffer)大小。
    • 19. 提高最大打开文件。

      应用部分:

        20. 设置图像和样式表的前端代理。

         

      • 21. 使用mod_passenger for rails。
      • 22. 关闭safe_mode for php。
      • 23. 不要使用threaded mpm with mod_php。
      • 24. 刷新缓冲区预渲染。
      • 25. 频繁访问的数据设置缓存。