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

[经验分享] Apache HTTP Server 2.4编译安装及其新特性(四)

[复制链接]

尚未签到

发表于 2018-11-20 09:09:00 | 显示全部楼层 |阅读模式
一、安装环境说明
系统环境:CentOS 6.5-x86_64
所需软件源码包:
apr-1.5.2.tar.gz         apr(Apache Portable Runtime)
apr-util-1.5.4.tar.gz
httpd-2.4.18.tar.bz2
Perl-Compatible Regular Expressions Library(PCRE): pcre-devel



二、Apache 组成结构
DSC0000.png
根据上图,我们就能够更好理解为什么需要安装 apr这个软件包了。 apr工作于OS上的一层,用于封装底层操作系统的不同,从而实现跨平台。apache 2.4 依赖于更高版本(1.5以上)的apr及apr-util包。



三、Apache 2.4编译安装
3.1 准备工作

## 临时关闭 SELinux
# setenforce 0
## 关闭 iptables
# service iptables stop
## 同步系统时间
# ntpdate time.nist.gov3.2 配置编译环境

## 安装开发工具包
# yum groupinstall -y "Development tools"
## 安装 pcre-devel
# yum install -y pcre-devel
# yum install -y zlib-devel
# yum install -y openssl-devel3.3 编译安装 apr及apr-util

## 安装 apr-1.5.2
# tar xf apr-1.5.2.tar.gz
# cd apr-1.5.2
# ./configure --prefix=/usr/local/apr
# make && make install
## 安装 apr-util-1.5.4
# tar xf apr-util-1.5.4.tar.gz
# cd apr-util-1.5.4
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/
# make && make install3.4 编译安装 httpd 2.4
# tar xf httpd-2.4.18.tar.bz2
# cd httpd-2.4.18
# ./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd \
--enable-so --enable-ssl --enable-cgi --enable-rewrite --with-z --with-pcre \
--with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ \
--enable-modules=most --enable-mpms-shared=all --with-mpm=event
# make && make install
## 各编译参数详解
--prefix:    #安装路径
--sysconfdir:#指定配置文件路径
--enable-so: #DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态加载
--enable-ssl:#支持SSL/TLS,可以实现https访问
--enable-cgi:#支持CGI脚本(默认对非线程的MPM模式开启)
--enable-rewrite:#启用Rewrite功能
--with-z:#使用指定的zlib库,不指定路径会自动寻找
--with-pcre:#使用指定的PCRE库,不指定路径会自动寻找
--with-apr:#指定apr安装路径
--with-apr-util:#指定apr-util安装路径
--enable-modules:#支持动态启用的模块,可选参数有“all”,“most”,“few”,“reallyall”
--enable-mpms-shared:#支持动态加载的MPM模块,可选“all”
--with-mpm:#设置默认启用的MPM模式
## 查看安装的模块
# /usr/local/apache/bin/httpd -l
Compiled in modules:
  core.c
  mod_so.c
  http_core.c3.5 编译完成后的基本配置
## 编辑 /etc/httpd/httpd.conf, 设置 httpd pid 路径
PidFile "/var/run/httpd.pid"
## 添加PATH环境变量
# vim /etc/profile.d/httpd.sh #必须要以.sh结尾,并且放在这里可以单独管理,不要的时候可以直接删除,添加如下内容
export PATH=/usr/local/apache/bin:$PATH   
# . /etc/profile.d/httpd.sh  
# httpd -t3.6 导出头文件以及man手册
## 导出头文件
# ln -sv /usr/local/apache/include/ /usr/local/include/httpd
`/usr/local/include/httpd' -> `/usr/local/apache/include/'
## 导出man手册,编辑 /etc/man.config
MANPATH /usr/man
MANPATH /usr/share/man
MANPATH /usr/local/man
MANPATH /usr/local/share/man
MANPATH /usr/X11R6/man
MANPATH /usr/local/apache/man        # 添加这一行3.7 Apache 服务启动脚本



# vim /etc/init.d/httpd
#!/bin/bash
#
# httpd        Startup script for the Apache HTTP Server
#
# chkconfig: - 85 15
# description: Apache is a World Wide Web server.  It is used to serve \
#        HTML files and CGI.
# processname: httpd
# config: /etc/httpd/conf/httpd.conf
# config: /etc/sysconfig/httpd
# pidfile: /var/run/httpd.pid
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/httpd ]; then
        . /etc/sysconfig/httpd
fi
# Start httpd in the C locale by default.
HTTPD_LANG=${HTTPD_LANG-"C"}
# This will prevent initlog from swallowing up a pass-phrase prompt if
# mod_ssl needs a pass-phrase from the user.
INITLOG_ARGS=""
# Set HTTPD=/usr/sbin/httpd.worker in /etc/sysconfig/httpd to use a server
# with the thread-based "worker" MPM; BE WARNED that some modules may not
# work correctly with a thread-based MPM; notably PHP will refuse to start.
# Path to the apachectl script, server binary, and short-form for messages.
apachectl=/usr/local/apache/bin/apachectl
httpd=${HTTPD-/usr/local/apache/bin/httpd}
prog=httpd
pidfile=${PIDFILE-/var/run/httpd.pid}
lockfile=${LOCKFILE-/var/lock/subsys/httpd}
RETVAL=0
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 10 $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=$?
        echo $"not reloading due to configuration syntax error"
        failure $"not reloading $httpd due to configuration syntax error"
    else
        killproc -p ${pidfile} $httpd -HUP
        RETVAL=$?
    fi
    echo
}
# See how we were called.
case "$1" in
start)
    start;;
stop)
    stop;;
status)
    status -p ${pidfile} $httpd
    RETVAL=$?;;
restart)
    stop
    start;;
condrestart)
    if [ -f ${pidfile} ] ; then
        stop
        start
    fi;;
reload)
    reload;;
graceful|help|configtest|fullstatus)
    $apachectl $@
    RETVAL=$?;;
*)
    echo $"Usage: $prog {start|stop|restart|condrestart|reload|status|fullstatus|graceful|help|configtest}"
    exit 1
esac
exit $RETVAL
## end of script
## 添加可执行权限
# chmod +x /etc/init.d/httpd3.8 启动httpd

## 设置开机启动
# chkconfig httpd on
## 检查配置
# service httpd configtest
Syntax OK
## 启动httpd
# service httpd start
# ss -tulpn | grep 80
## 访问测试
# curl http://localhost
It works!到此,我们就成功编译安装完成 httpd 2.4.



四、Apache 2.4配置
1、与rpm包或yum安装的不同,编译安装时许多默认配置在 /etc/httpd/extra目录。
2、与apache 2.2不同, apache 2.4 正式支持 event 模型。
3、与apache 2.2不同, apache 2.4 配置基于主机名的虚拟主机时,不再需要NameVirtualHost指令。


4.1 配置基于主机名的虚拟主机
1、编辑 /etc/httpd/extra/httpd-vhosts.conf文件,定义虚拟主机
# vi /etc/httpd/extra/httpd-vhosts.conf

    DocumentRoot "/web/vhost/a.com"
    ServerName www.a.com
    ErrorLog "logs/a.com-error_log"
    CustomLog "logs/a.com-access_log" common
   
        Require all granted
   



    DocumentRoot "/web/vhost/b.org"
    ServerName www.b.org
    ErrorLog "logs/b.org-error_log"
    CustomLog "logs/b.org-access_log" common
   
        Require all granted
   
2、创建相关目录以及默认主页

# mkdir -pv /web/vhost/{a.com,b.org}
# echo "www.a.com" > /web/vhost/a.com/index.html
# echo "www.b.org" > /web/vhost/b.org/index.html3、修改主配置文件 httpd.conf, 注释中心主机,以及取消注释Include 虚拟主机行

# vi /etc/httpd/httpd.conf
#DocumentRoot "/usr/local/apache/htdocs"
# Virtual hosts
Include /etc/httpd/extra/httpd-vhosts.conf4、检查配置,启动httpd

# service httpd configtest
# service httpd restart5、通过 其他机器访问(这里是win7)
首先修改 win7 的hosts文件,绑定不同的域名。 C:\Windows\System32\drivers\etc
192.168.1.31  www.a.com
192.168.1.31  www.b.org检查是否解析成功
[c:\~]$ ping www.b.org
Pinging www.b.org [192.168.1.31] with 32 bytes of data:
Reply from 192.168.1.31: bytes=32 time=29ms TTL=64
Reply from 192.168.1.31: bytes=32 time

运维网声明 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-637199-1-1.html 上篇帖子: apache配置文件:http.conf配置详解 下篇帖子: Apache 源码包安装
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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