linux下编译httpd,Linux下编译安装Apache httpd 2.4
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
# 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
< . /etc/sysconfig/httpd
---
> 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
Ubuntu 13.04 安裝 LAMP\Vsftpd\Webmin\phpMyAdmin 服務及設置 http://www.linuxidc.com/Linux/2013-06/86250.htm
CentOS 5.9下編譯安裝LAMP(Apache 2.2.44+MySQL 5.6.10+PHP 5.4.12) http://www.linuxidc.com/Linux/2013-03/80333p3.htm
Apache 的詳細介紹:請點這里
Apache 的下載地址:請點這里
總結
以上是生活随笔為你收集整理的linux下编译httpd,Linux下编译安装Apache httpd 2.4的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 挂载exfat u盘 yum
- 下一篇: Linux系统自动备份脚本,供参考的Li