分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 教程案例

马哥linux高薪中级-web服务器(续一)

发布时间:2023-09-06 01:13责任编辑:郭大石关键词:web服务器

2、工作模式切换

httpd支持三种模型,即perfork、worker、event模型。

三种模型的启动方法是不同的,perfork是默认的启动模型,通过httpd命令即可启动,可以通过rpm -ql |grep bin来看到有httpd、http.worker、http.event三个命令。

一般来说,apache的2.2版本之前并不支持event模型,在2.4以后才开始支持event模型。

2.1、修改配置文件

[root@37-test ~]# vi /etc/sysconfig/httpd


2.2、去掉以下注释,并重启服务

HTTPD=/usr/sbin/httpd.worker


2.3、查看启动情况

[root@37-test ~]# ps -aux |grep http

Warning: bad syntax, perhaps a bogus ‘-‘? See /usr/share/doc/procps-3.2.8/FAQ

root 58440.00.0 1755363844 ? Ss08:310:00 /usr/sbin/httpd.worker

apache 58470.00.0 5197965300 ? Sl08:310:00 /usr/sbin/httpd.worker

apache 58570.00.0 5197965288 ? Sl08:310:00 /usr/sbin/httpd.worker

apache 58840.00.0 5197965288 ? Sl08:310:00 /usr/sbin/httpd.worker


3、常用命令

3.1、httpd命令的帮助

[root@37-test ~]# httpd -h

Usage: httpd [-D name] [-d directory] [-f file]

[-C "directive"] [-c "directive"]

[-k start|restart|graceful|graceful-stop|stop]

[-v] [-V] [-h] [-l] [-L] [-t] [-S]

Options:

-D name : define a name for use in <IfDefine name> directives

-d directory : specify an alternate initial ServerRoot

-f file : specify an alternate ServerConfigFile

-C "directive" : process directive before reading config files

-c "directive" : process directive after reading config files

-e level : show startup errors of level (see LogLevel)

-E file : log startup errors to file

-v : show version number

-V : show compile settings

-h : list available command line options (this page)

-l : list compiled in modules

-L : list available configuration directives

-t -D DUMP_VHOSTS: show parsed settings (currently only vhost settings)

-S : a synonym for -t -D DUMP_VHOSTS

-t -D DUMP_MODULES : show all loaded modules

-M : a synonym for -t -D DUMP_MODULES

-t : run syntax check for config files


3.2、查看httpd支持的核心模块有哪些?

[root@37-test ~]# httpd -l

Compiled in modules:

core.c

prefork.c

http_core.c

mod_so.c


3.3、http -D DUMP_MODULES:显示模块支持的扩展模块

[root@37-test ~]# httpd -D DUMP_MODULES

httpd: apr_sockaddr_info_get() failed for 37-test

httpd: Could not reliably determine the server‘s fully qualified domain name, using 127.0.0.1 for ServerName

Loaded Modules:

core_module (static)

mpm_prefork_module (static)##使用prefork模型

http_module (static)

so_module (static)

auth_basic_module (shared)

auth_digest_module (shared)

authn_file_module (shared)

authn_alias_module (shared)

authn_anon_module (shared)

authn_dbm_module (shared)

authn_default_module (shared)

authz_host_module (shared)

authz_user_module (shared)

authz_owner_module (shared)

authz_groupfile_module (shared)

authz_dbm_module (shared)

authz_default_module (shared)

ldap_module (shared)

authnz_ldap_module (shared)

include_module (shared)

log_config_module (shared)

logio_module (shared)

env_module (shared)

ext_filter_module (shared)

mime_magic_module (shared)

expires_module (shared)

deflate_module (shared)

headers_module (shared)

usertrack_module (shared)

setenvif_module (shared)

mime_module (shared)

dav_module (shared)

status_module (shared)

autoindex_module (shared)

info_module (shared)

dav_fs_module (shared)

vhost_alias_module (shared)

negotiation_module (shared)

dir_module (shared)

actions_module (shared)

speling_module (shared)

userdir_module (shared)

alias_module (shared)

substitute_module (shared)

rewrite_module (shared)

proxy_module (shared)

proxy_balancer_module (shared)

proxy_ftp_module (shared)

proxy_http_module (shared)

proxy_ajp_module (shared)

proxy_connect_module (shared)

cache_module (shared)

suexec_module (shared)

disk_cache_module (shared)

cgi_module (shared)

version_module (shared)

Syntax OK


3.4、httpd -l:显示http模块的核心

[root@37-test ~]# httpd -l

Compiled in modules:

core.c

prefork.c

http_core.c

mod_so.c


3.5、httpd.worker -l

[root@37-test ~]# httpd.worker -l

Compiled in modules:

core.c

worker.c

http_core.c

mod_so.c


3.6、httpd.event -l

[root@37-test ~]# httpd.event -l

Compiled in modules:

core.c

event.c

http_core.c

mod_so.c


4、配置详解

4.1、服务运行脚本:/etc/rc.d/init.d/httpd

4.2、运行目录:/etc/httpd

4.3、配置文件:/etc/httpd/conf/

主配置文件 httpd.conf

扩展配置文件: /etc/httpd/conf.d/*.conf (优先级高于主配置文件)

4.4、目录结构

[root@37-test ~]# tree /etc/httpd/

/etc/httpd/

├── conf

│ ├── httpd.conf

│ └── magic

├── conf.d

│ └── README

├── logs -> ../../var/log/httpd

├── modules -> ../../usr/lib64/httpd/modules

└── run -> ../../var/run/httpd


5 directories, 3 files


外挂模块:/usr/lib(64)/httpd/modules/、/etc/httpd/modules/

强行刷新网页信息(绕过本地缓存,重新读取服务器信息):shift+f5

错误信息配置目录:/var/www/error/

apache提供的图标位置:/var/www/icons/

可执行CGI程序的位置:/var/www/cgi-bin/

httpd日志位置:/var/log/httpd/

设置httpd的账户和密码:/usr/bin/htpasswd

[root@37-test ~]# tree /var/www/ -L 1

/var/www/

├── cgi-bin

├── error

├── html

└── icons


4 directories, 0 files


5、如何配置httpd的工作属性:

5.1、基本语法

指令不区分字符大小写,但通常单词首字母大写。

但指令的值区分大小写。参数间用空白字符隔开。

5.2、配置文件的结构

主服务器和虚拟主机不能同时启用。

全局配置:对主服务器或者虚拟机都有效,且有些功能是服务器自身属性。

主服务器;主站属性 主服务器和虚拟主机不可并存,至少关闭一个。

虚拟主机:虚拟主机及属性定义

5.3、配置文件语法测试:

1、service httpd configtest

2、httpd -t

注意:大多数配置通过service httpd reload即可生效,如果修改端口需要重启服务。

五、全局配置

1、配置监听的端口和地址 ,可以配置多个端口,但端口能重复。

listen 192.168.1.5:8080

2、配置所选的mpm的属性

默认情况下,APACHE启动的是prefork模型,虽然worker模型使用多线程,可以实现资源共享,但是linux其实是不支持多线程的,这里的多线程就是轻量级进程。

切换到worker模型

[root@37-test ~]# more /etc/sysconfig/httpd#进入/etc/sysconfig/httpd文件

# Configuration file for the httpd service.


#

# The default processing model (MPM) is the process-based##默认使用profork模型

# ‘prefork‘ model.A thread-based model, ‘worker‘, is also

# available, but does not work with some modules (such as PHP).

# The service must be stopped before changing this variable.

#

HTTPD=/usr/sbin/httpd.worker##取消掉此注释


查看进程状态

[root@37-test ~]# ps axu |grep httpd

root 182290.00.0 1776124044 ? Ss09:490:00 /usr/sbin/httpd.worker ##主进程,派发任务

apache183430.00.0 5874085340 ? Sl09:490:00 /usr/sbin/httpd.worker ##辅助进程,生成线程



mpm:多道处理模块

perfork:一个进程响应一个请求

(1)绑定特权端口

(2)派发或回收子进程

(3)读取分析主配置文件

<IfModule prefork.c>

StartServers 8 //起始空闲进程
MinSpareServers 5 //最小空闲进程
MaxSpareServers 20 //最大空闲进程
ServerLimit 256 //最多并发访问的进程数量
MaxClients 256 //服务器最大接受访问的客户端数量,不要超过系统内存最大承载能力。
MaxRequestsPerChild 4000 /单个程序能够请求的最大传输次数要求

worker:一个进程生成多个线程,用户请求线程,linux的worker工作不如perfork工作效果好。

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved