apache httpd 配置详解

MPM:多路并发响应模型(Multipath Process Module)

            perfork:多进程模型,一个进程响应一个请求(高并发环境下不常用)

            worker:多线程模型(多进程生成,一个进程生成多个线程),一个线程响应一个请求

            event:事件驱动模型(一个线程响应多个请求)

CentOS 6: httpd 2.2 不支持同时编译多个模块,所以只能编译时选定一个,RPM安装包提供三个二进制文件,分别用于实现对不同MPM机制的支持

            查看:rpm -ql httpd

                        /usr/sbin/httpd              #perfork

                        /usr/sbin/httpd.event

                        /usr/sbin/httpd.worker

            查看httpd内核编译了那些模块

                        [root@node6~]# httpd -l

                        Compiledin modules:

                         core.c              #核心模块

                         prefork.c         #perfork模块

                         http_core.c      #功能核心模块

                         mod_so.c         #模块动态装载

                        [root@node6conf]# httpd.worker -l

                        Compiledin modules:

                          core.c

                          worker.c

                          http_core.c

                          mod_so.c

                        [root@node6conf]# httpd.event -l

                        Compiledin modules:

                          core.c

                          event.c

                          http_core.c

                          mod_so.c

            查看httpd静态和动态模块

                        [root@node6~]# httpd -M

                        LoadedModules:

                        core_module (static)#静态模块

                        mpm_prefork_module(static)

                         http_module (static)

                         so_module (static)

                        auth_basic_module(shared)#动态模块

                        auth_digest_module(shared)

                        authn_file_module(shared)

                        authn_alias_module(shared)

            更换使用的httpMPM二进制程序:

                        [root@node6~]# vim /etc/sysconfig/httpd

                        默认:HTTPD=/usr/sbin/httpd  (perfork)

                        HTTPD=/usr/sbin/httpd.worker

                        servicehttpd restart

                        psaux httpd

                        [root@node6~]# ps aux | grep httpd

                        root       4277 0.0  1.0 139212  4904 pts/0   T    08:18   0:00 vim httpd.conf

                        root       4740 0.0  1.0 139244  4932 pts/0   S+   09:15   0:00 vim httpd.conf

                        root       4845 0.0  0.8 184064  3944 ?       Ss   09:38   0:00 /usr/sbin/httpd.worker

                        apache     4848 0.0  0.6 528324  3328 ?       Sl   09:38   0:00 /usr/sbin/httpd.worker

                        apache     4850 0.0  0.6 528324  3332 ?       Sl   09:38   0:00 /usr/sbin/httpd.worker

                        apache     4851 0.0  0.6 528324  3332 ?       Sl   09:38   0:00 /usr/sbin/httpd.worker

                        root       4970 0.0  0.1 103316   840 pts/1   S+   09:39   0:00 grep httpd

 

            MPMPerfork配置文件:一个进程响应一个请求

                        <IfModuleprefork.c>

                        StartServers       8      #服务启动时,启动8个服务器进程

                        MinSpareServers    5    #最少空闲进程数

                        MaxSpareServers   20   #最大空闲进程数

                        ServerLimit      256      #服务器最大允许的进程数量

                        MaxClients       256    #最多只允许256个客户端同时请求资源

                        ServerLimit和MaxClients一般数值相同

                        MaxRequestsPerChild  4000      #一个服务器进程最多可以响应多少次请求,超过来会kill掉进程,启动一个新进程

                        </IfModule>    

            MPMWorker配置文件:(多进程生成,一个进程生成多个线程),一个线程响应一个请求

                        <IfModuleworker.c>

                        StartServers         4   #服务启动时,启动8个服务器进程

                        MaxClients         300#服务器端最大启动的线程数

                        MinSpareThreads     25           #最少空闲线程数

                        MaxSpareThreads     75           #最大空闲线程数

                        ThreadsPerChild     25#每个进程所能启动的线程数

                        MaxRequestsPerChild  0            #每个线程所能响应的最大请求数量

                        </IfModule>    

 

并发服务器响应请求:

            单进程I/O模型

            多进程I/O模型

            复用的I/O模型

                        多线程模型

                        事件驱动

            复用的多进程I/0模型

 

httpd(2)

            版本区别不大

            CentOS6: httpd 2.2

            CentOS7: httpd 2.4

 

 

            安装方式:

                        rpm:

                        yum:安装:

                                    rpm-ql httpd    #查看安装生成的文件

                                    rpm-qc httpd   #查看httpd的配置文件路径

                       

            编译安装:

                       

           

            程序环境:

                        配置文件:

                                    /etc/httpd/conf/httpd.conf

                                    /etc/httpd/conf.d/*.conf

 

                        服务脚本:

                                    /etc/rc.d/init.d/httpd

                                    脚本配置文件:

                                                /etc/sysconfig/httpd

                        主程序文件:

                                    /usr/sbin/httpd

                                   

                        日志文件:

                                    /var/log/httpd/

                                                access_log:访问日志

                                                error_log:错误日志

 

                        站点文档目录:

                                    /var/www/html/

                        配置文件指令的格式:

                                    directivevalue

                                    directive:不区分字符大小写

                                    value:为路径时,取决于文件系统

                                   

                        yum挂载本地文件:

                                    cd/etc/yum.repos.d/

                                    vimCentOS_Local.repo

                                                [CentOS7base]

                                                name=CentOS7

                                                baseurl=file:///media/cdrom

                                                gpgcheck=0

                                                enable=1

                                               

                                                                       

                                    mkdir/media/cdrom

                                    mount-r /dev/cdrom  /media/cdrom

                                    yumrepolist

                                    yumclean all

 

                        配置文件的组成:

                                    修改监听端口:

                                                Listen[IP:] PORT

                                                Listen80          #监听本机上所有的IP地址

                                                Listen192.168.2.119:8000 #监听指定的IP和端口

                                                servicehttpd restart

[root@node6 conf]# ss -tnl

State     Recv-Q Send-Q                              LocalAddress:Port                               Peer Address:Port

LISTEN    0      128                                192.168.2.119:8000                                           *:*    

LISTEN    0      128                                192.168.2.119:10050        

                                               

持久连接:

                                    PersistentConnection:连接建立,每个资源获取完成后不会断开连接,而是继续等待其它的请求完成

                                    如何断开?

                                                数量限制:100

                                                时间限制:可配置

                                    副作用:对并发访问量较大的服务器,持久连接功能会使得有些请求得不到响应

                                    折衷方式:使用较短的持久连接时间:

                                                http-2.4支持毫秒级持久时间

                                    非持久连接:

                                     

                                    配置方式:

                                                KeepAliveOn|Off

                                                MaxKeepAliveRequests100|#

                                                KeepAliveTimeout15|#

 

                                    测试:所有的文本格式的协议都可以通过telnetip  port 的方式来访问

                                                telnetHOST  PORT

                                                GET/URL  HTTP/1.1

                                                Host:HOSTNAME OR IP

                                                非持久连接:KeepAliveOff 测试:

                                                [root@node6~]# telnet 192.168.2.119 80

                                                            Trying192.168.2.119...

                                                            Connectedto 192.168.2.119.

                                                            Escapecharacter is '^]'.

                                                            GET /HTTP/1.1       #请求的方式,路径,HTTP协议

                                                            Host:192.168.2.119  #请求的主机

                                                            HTTP/1.1403 Forbidden

                                                            Date:Fri, 30 Jun 2017 00:53:18 GMT

                                                            Server:Apache/2.2.15 (CentOS)

                                                            Accept-Ranges:bytes

                                                            Content-Length:4961

                                                            Connection:close

                                                            Content-Type:text/html; charset=UTF-8

 

                                                            Connectionclosed by foreign host.                     #一次连接后就断开了连接

                                                持久连接:KeepAliveOn  KeepAliveTimeout 15 测试:

                                                [root@node6~]# telnet 192.168.2.119 80

                                                            Trying192.168.2.119...

                                                            Connectedto 192.168.2.119.

                                                            Escapecharacter is '^]'.

                                                            GET /HTTP/1.1       #请求的方式,路径,HTTP协议

                                                            Host:192.168.2.119  #请求的主机

                                                            HTTP/1.1403 Forbidden

                                                            Date:Fri, 30 Jun 2017 00:53:18 G

YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS