当前位置: 代码迷 >> 综合 >> Linux下安装Apache httpd
  详细解决方案

Linux下安装Apache httpd

热度:78   发布时间:2023-12-14 23:14:45.0

httpd是Apache超文本传输协议(HTTP)服务器的主程序。它被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池对外提供服务。httpd支持基于 虚拟主机,以及基于HOST、IP、PORT实现虚拟主机,反向代理,负载均衡,路径别名,用户认证,basic,支持第三方模块等众多特性。本文主要描述了Linux下httpd的安装以及相关基本用法。

一、httpd的安装

演示环境及版本# cat /etc/issueCentOS release 6.5 (Final)Kernel \r on an \m# uname -r2.6.32-431.el6.x86_64查看httpd是否已安装# rpm -qa httpd使用yum列出相关httpd安装文件,此处为本地yum源    # yum list |grep httpd httpd.x86_64                 2.2.15-29.el6.centos        local_server httpd-devel.i686             2.2.15-29.el6.centos        local_server httpd-devel.x86_64           2.2.15-29.el6.centos        local_server httpd-manual.noarch          2.2.15-29.el6.centos        local_server httpd-tools.x86_64           2.2.15-29.el6.centos        local_server 安装及验证httpd  # yum -y install httpd# rpm -qa |grep httpdhttpd-tools-2.2.15-29.el6.centos.x86_64httpd-2.2.15-29.el6.centos.x86_64使用rpm方式寻找配置文件   # rpm -qc httpd 常用的配置文件:/etc/httpd/conf.d/*.conf ###辅助配置文件/etc/httpd/conf/httpd.conf ###主配置文件/etc/sysconfig/httpd ###httpd工作模式配置文件使用rpm方式查看安装位置及生成的二进制文件 # rpm -ql httpd 主程序:/usr/sbin/httpd MPM模式默认/usr/sbin/httpd.event/usr/sbin/httpd.worker使用rpm方式查看包的帮助文件 # rpm -qd httpd 启动脚本:/etc/rc.d/init.d/httpd日志文件目录:/var/log/httpdaccess_log:访问日志error_log: 错误日志站点文档目录:(站点根目录)/var/www/htmlhttpd的工作目录:/var/www

二、httpd的工作模式

1、MPM: Multipath Processing Module(多路处理模块)prefork: 多进程模型,每个进程响应一个请求;稳定性好,但并发能力有限;预先生成多个空闲进程;由于prefork使用select()系统调用,所以最大并发不能超过1024;worker:多进程模型,每个进程可生成多个线程,每个线程响应一个请求;预先生成多个空闲线程;event:一个进程直接响应n个请求;可同时启动多个进程;httpd-2.2: 测试使用;    ### Author : Leshamihttpd-2.4: 可生产使用;  ### Blog : http://blog.csdn.net/leshami2、几种工作方式的切换
prefork模式下      # service httpd startStarting httpd:                                            [  OK  ]# ps -ef|grep httpd |grep -v grep ###一个主进程,生成了8个空闲进程root       6413      1  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6416   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6417   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6418   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6419   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6420   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6421   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6422   6413  0 09:40 ?        00:00:00 /usr/sbin/httpdapache     6423   6413  0 09:40 ?        00:00:00 /usr/sbin/httpd   # ss -tulpn |grep httpdtcp    LISTEN     0   128  :::80   :::*      users:(("httpd",6413,4),("httpd",6416,4),("httpd",6417,4),("httpd",6418,4),("httpd",6419,4),("httpd",6420,4),("httpd",6421,4),("httpd",6422,4),("httpd",6423,4)# netstat -nltp|grep 80tcp        0      0 :::80                       :::*          LISTEN      6413/httpd   worker工作方式# cat /etc/sysconfig/httpd|grep -v ^#HTTPD=/usr/sbin/httpd.worker# service httpd restartStopping httpd:                                            [  OK  ]Starting httpd:                                            [  OK  ][root@orasrv1 ~]# ps -ef|grep httpd|grep -v greproot       2261      1  0 17:47 ?        00:00:00 /usr/sbin/httpd.workerapache     2264   2261  0 17:47 ?        00:00:00 /usr/sbin/httpd.workerapache     2265   2261  0 17:47 ?        00:00:00 /usr/sbin/httpd.workerapache     2266   2261  0 17:47 ?        00:00:00 /usr/sbin/httpd.workerevent工作方式
注,尽管2.2版本可以设置工作方式为httpd.event,生产环境不建议使用# cat /etc/sysconfig/httpd|grep -v ^#HTTPD=/usr/sbin/httpd.event[root@orasrv1 ~]# service httpd restartStopping httpd:                                            [  OK  ]Starting httpd:                                            [  OK  ][root@orasrv1 ~]# ps -ef|grep httpd|grep -v greproot       2402      1  0 17:49 ?        00:00:00 /usr/sbin/httpd.eventapache     2405   2402  0 17:49 ?        00:00:00 /usr/sbin/httpd.eventapache     2406   2402  0 17:49 ?        00:00:00 /usr/sbin/httpd.eventapache     2407   2402  0 17:49 ?        00:00:00 /usr/sbin/httpd.event

三、httpd模块化特性

高度模块化core + modules, DSO: Dynamic Shared Object模块目录:/etc/httpd/modules: 符号链接文件/usr/lib64/httpd/modules模块的查看       httpd -M          ###查看当前httpd进程的所有模块httpd.event -M    ###查看event工作模式下的所有模块 更正@20160712httpd.worker -M   ###worker工作模式下的所有模块 更正@20160712httpd.worker -l   ###worker工作模式下的核心模块 更正@20160712模块的查看示例 # httpd -MLoaded Modules:core_module (static)mpm_prefork_module (static)http_module (static)so_module (static)auth_basic_module (shared)..............# httpd.event -lCompiled in modules:core.cevent.chttp_core.cmod_so.c模块的动态装载与卸载# cp /etc/httpd/conf/httpd.conf /etc/httpd/conf/httpd.conf.bak# cat /etc/httpd/conf/httpd.conf |grep authn_alias_moduleLoadModule authn_alias_module modules/mod_authn_alias.so# vi /etc/httpd/conf/httpd.conf ###注释mod_authn_alias.so模块# cat /etc/httpd/conf/httpd.conf |grep authn_alias_module#LoadModule authn_alias_module modules/mod_authn_alias.so# service httpd restart# httpd -M ###使用该方式前后进行对比即可知道模块是否装载或卸载 

四、验证httpd服务

# echo "<h1>orasrv1.xlk.com</h1>" >/var/www/html/index.html
# curl http://192.168.21.10
<h1>orasrv1.xlk.com</h1>
  相关解决方案