Apache工作模式切换

 2023-02-26    500  

一、apache运行模式切换

apache比较常用的工作模式有worker以及prefork两种方式

1、编译安装:

如果在编译时候不指定,系统默认的是prefork模式。如果需要换成worker模式,需要在编译的时候带上编译参数:–with-mpm=worker

查看apache用的是那种工作模式:在apache安装目录的bin目录下运行:apachectl -l或者httpd -l,如下图:

Apache工作模式切换

从图中可以看出apache是work模式

2、yum安装:

yum安装apache默认也是prefork模式,如下图:

Apache工作模式切换

如果需要换成work模式,应该按如下步骤操作

1、cd /usr/sbin

2、mv httpd httpd.prefork

3、mv httpd.work httpd

4、service httpd restart

改成work模式后,重启apache可能会报错,如下图:

Apache工作模式切换

解决办法是安装php-zts

Apache工作模式切换

安装完成后再次重启apache不会报错

再次查看apache运行模式:httpd -l

Apache工作模式切换

二、通过server-status监控性能

不管是编译安装还是yum安装,操作方法都是一样的,步骤如下:

1、加载mod_status.so 模块
   在httpd.conf中打开LoadModule status_module modules/mod_status.so

   Apache工作模式切换

2、添加监听

在httpd.conf添加如下内容

<location /server-status> //server-status 这个名字可以任意的取
  SetHandler server-status
  Order Deny,Allow
  Deny from nothing //禁止的访问地址,nothing 表示没有禁止访问的地址
  Allow from all //表示允许的地址访问;all 表示所有的地址都可以访问
</location>
ExtendedStatus On //表示的是待会访问的时候能看到详细的请求信息
<Location /server-info>
  SetHandler server-info
  Order allow,deny
  Deny from nothing
  Allow from all
</Location>

3、重启apache

4、访问

http://IP地址:端口/server-status

http://IP地址:端口/server-info

http://IP地址:端口/server-status ?refresh=N

N将表示访问状态页面可以每N秒自动刷新一次

如下图:

server-status

Apache工作模式切换

server-info

Apache工作模式切换

以上所述是小编给大家介绍的Apache工作模式切换,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对77isp云服务器技术网的支持!

原文链接:https://77isp.com/post/34487.html

=========================================

https://77isp.com/ 为 “云服务器技术网” 唯一官方服务平台,请勿相信其他任何渠道。