apache怎么从worker切换为prefork

2025-05-12 01:28:44
推荐回答(2个)
回答(1):

在Redhat Linux的主要版本as4上,apache版本为httpd-2.0.5x,
默认为prefork模式,主要是考虑到稳定性的原因。
要切换到worker模式,则需要登录到linux上,进行如下操作:

进入/usr/sbin目录
cd /usr/sbin

将当前的prefork模式启动文件改名
mv httpd httpd.prefork

将worker模式的启动文件改名
mv httpd.worker httpd

修改配置文件vi /etc/httpd/conf/httpd.conf
找到里边的如下一段,可适当修改负载等参数:

StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0


重新启动服务
/etc/init.d/httpd restart

即可换成worker方式启动apache2

注意这里可能会遇到错误:
Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. Pre-configuration failed!
解决方法是将/etc/httpd/conf.d/php.conf文件中的LoadModule开头的那行代码注释掉。
--------------------------

注意:处于稳定性和安全性考虑,不建议更换apache2的运行方式,使用系统默认prefork即可
另外很多php模块不能工作在worker模式下,例如redhat linux自带的php也不能支持线程安全
所以最好不要切换工作模式。
=========================================
# /etc/init.d/httpd stop
[root@web ~]# which apachectl
/usr/sbin/apachectl
[root@web ~]# which httpd
/usr/sbin/httpd
[root@web ~]# cd /usr/sbin/
[root@web ~]# mv httpd httpd.prefork
# mv httpd.worker httpd
# httpd -k start

回答(2):

步骤如下:
在Redhat Linux的主要版本as4上,apache版本为httpd-2.0.5x,
默认为prefork模式,主要是考虑到稳定性的原因。
要切换到worker模式,则需要登录到linux上,进行如下操作:

进入/usr/sbin目录
cd /usr/sbin

将当前的prefork模式启动文件改名
mv httpd httpd.prefork

将worker模式的启动文件改名
mv httpd.worker httpd

修改配置文件vi /etc/httpd/conf/httpd.conf
找到里边的如下一段,可适当修改负载等参数:

StartServers 2
MaxClients 150
MinSpareThreads 25
MaxSpareThreads 75
ThreadsPerChild 25
MaxRequestsPerChild 0


重新启动服务
/etc/init.d/httpd restart

即可换成worker方式启动apache2

注意这里可能会遇到错误:
Apache is running a threaded MPM, but your PHP Module is not compiled to be threadsafe. You need to recompile PHP. Pre-configuration failed!
解决方法是将/etc/httpd/conf.d/php.conf文件中的LoadModule开头的那行代码注释掉。
--------------------------

注意:处于稳定性和安全性考虑,不建议更换apache2的运行方式,使用系统默认prefork即可
另外很多php模块不能工作在worker模式下,例如redhat linux自带的php也不能支持线程安全
所以最好不要切换工作模式。
=========================================
# /etc/init.d/httpd stop
[root@web ~]# which apachectl
/usr/sbin/apachectl
[root@web ~]# which httpd
/usr/sbin/httpd
[root@web ~]# cd /usr/sbin/
[root@web ~]# mv httpd httpd.prefork
# mv httpd.worker httpd