Httpd服务实战

2020-06-27  本文已影响0人  4e8ea348373f

HTTPD服务

基础知识:

  1. 有base源提供,可以直接使用yum 安装
  2. centos6 提供的是2.2版本(停止维护) / centos7 提供的2.4的版本
  3. 2.4的版本和2.2的版本有了很大的不同

HTTPD特性

程序主要文件

# httpd-2.2版本
    # 配置文件
        /etc/httpd/conf/httpd.conf
        /etc/httpd/conf/*conf
    # 服务脚本
        /etc/init.d/httpd
        /etc/sysconfig/httpd #脚本配置文件,修改MPM时需要用到
    # 主程序文件:
        /user/sbin/httpd
        /user/sbin/httpd.worker
        /user/sbin/httpd.event
    # 模块文件路径
        /usr/lib64/httpd/modules
        
# httpd-2.4版本
    # 配置文件
        /etc/httpd/conf/httpd.conf
        /etc/httpd/conf/*conf
        /etc/httpd/conf.modules.d/*.conf # 模块配置路径
    # 服务脚本
        /etc/init.d/httpd
        /etc/sysconfig/httpd #脚本配置文件,修改MPM时需要用到
    # 主程序文件:
        /user/sbin/httpd # 支持MPM动态切换
    # 模块文件路径
        /usr/lib64/httpd/modules

HTTPD2.2的常用配置

# 主要配置段,2和3 不能同时开启,一般都是用虚拟主机
[root@localhost ~]# grep "^###" /etc/httpd/conf/httpd.conf
### Section 1: Global Environment
### Section 2: 'Main' server configuration
### Section 3: Virtual Hosts

# 持续连接
# tcp建立连接后,每个资源获取完成后并不马上断开连接,而是等待其他资源的请求
# 优势:减少频繁的tcp三次握手和四次挥手
# 缺点:如果时间过长,会造成占用浪费
[root@localhost ~]# grep "KeepAlive" /etc/httpd/conf/httpd.conf
# KeepAlive: Whether or not to allow persistent connections (more than
KeepAlive Off
# MaxKeepAliveRequests: The maximum number of requests to allow
MaxKeepAliveRequests 100
# KeepAliveTimeout: Number of seconds to wait for the next request from the
KeepAliveTimeout 15

# MPM 
# 2.2不支持同时编译多个MPM模块,rpm为此专门提供了3个
[root@localhost ~]# ll /usr/sbin/httpd*
-rwxr-xr-x 1 root root 367136 Jun 19  2018 /usr/sbin/httpd
-rwxr-xr-x 1 root root 379688 Jun 19  2018 /usr/sbin/httpd.event
-rwxr-xr-x 1 root root 379688 Jun 19  2018 /usr/sbin/httpd.worker
[root@localhost ~]# cat /etc/sysconfig/httpd | grep -P 'HTTPD='
#HTTPD=/usr/sbin/httpd.worker
# 修改需要重启服务生效

# 查看静态编译的模块
[root@localhost ~]# httpd -l
Compiled in modules:
  core.c
  prefork.c
  http_core.c
  mod_so.c

# 查看静态和动态编译的模块
[root@localhost ~]# httpd -M
httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain for ServerName
Loaded Modules:
 core_module (static)
 mpm_prefork_module (static)
 http_module (static)
 so_module (static)
 auth_basic_module (shared)
 auth_digest_module (shared)
 ...
 
# MPM配置
# 注意: 最大的不能小于start的,不然刚起来就杀了
<IfModule prefork.c>
StartServers       8
MinSpareServers    5
MaxSpareServers   20
ServerLimit      256
MaxClients       256
MaxRequestsPerChild  4000
</IfModule>

<IfModule worker.c>
StartServers         4
MaxClients         300
MinSpareThreads     25
MaxSpareThreads     75
ThreadsPerChild     25
MaxRequestsPerChild  0
</IfModule>

通过telnet 请求网页并测试是否为长连接

上一篇下一篇

猜你喜欢

热点阅读