我花了一两个星期的时间研究和设置我的服务器来运行Worker MPM和FCID。 我试图优化它,以允许可能的最并发的连接。 在工人MPM上find好的信息一直是个噩梦。
服务器 – 具有1GB内存的VPS(Apache仅使用约150MB的内存)我希望Apache具有约750MB的内存使用CAP – 这样我的服务器永远不会耗尽内存。
我已经运行了大约2年的服务器没有任何问题 – 但我们最近开始streamMP3,这需要更多的并发连接。 服务器也有一些小的DDOS攻击 – 所以我整理了大量的设置,以防止服务器内存不足 – 我还添加了一些防火墙规则来限制速度。
我现在的设置看起来像它的工作 – 但我得到一些分段错误
[Sat Mar 23 03:19:50 2013] [notice] child pid 28351 exit signal Segmentation fault (11) [Sat Mar 23 03:56:20 2013] [notice] child pid 29740 exit signal Segmentation fault (11) *** glibc detected *** /usr/sbin/httpd.worker: malloc(): memory corruption: 0xb83abdd8 ***
还有一些内存不足的错误
Out of memory during array extend.
这是我目前的设置,我真的很感激一些build议。
Apache设置:
Timeout 30 KeepAlive On MaxKeepAliveRequests 100 KeepAliveTimeout 2 ##################### # Spawn 2 child processes, spawning 25 threads for each child process. # So, a pool of 50 threads is left up and sleeping, ready to serve incoming requests. # If more requests will come in, apache will spawn new child processes, each one spawning 25 threads, # enlarging the thread pool until the total number of threads become 50. In that case, apache begin # to cleanly drop processes, trying to reach 25 threads. # New processes and its threads are spawned in case of a large spike of requests, until 200 parallel # client requests are reached, then apache will no longer accept new incoming connections. # When the load calm down, and requests come back under 200 parallel connections, apache will continue # to accept connections. After 25, 000 requests served by a child, q. 1000 per thread, the process # get closed by the father to ensure no memory leak is fired. <IfModule worker.c> ServerLimit 16 StartServers 2 MaxClients 400 MinSpareThreads 25 MaxSpareThreads 50 ThreadsPerChild 25 MaxRequestsPerChild 1000 ThreadLimit 64 ThreadStackSize 1048576 </IfModule> #####################
然后在fcgid.conf中进行一些设置
FcgidMinProcessesPerClass 0 FcgidMaxProcessesPerClass 8 FcgidMaxProcesses 25 FcgidIdleTimeout 60 FcgidProcessLifeTime 120 FcgidIdleScanInterval 30
按要求输出/etc/my.cnf
的[mysqld] DATADIR =的/ var / lib中/ MySQL的 sockets=的/ var / lib中/ MySQL的/的mysql.sock 用户= MySQL的 #跳过InnoDB的 connect_timeout = 10 max_connections = 300 符号链接= 0 innodb_file_per_table = 1 myisam_sort_buffer_size = 8M read_rnd_buffer_size = 512K net_buffer_length = 8K read_buffer_size = 256K sort_buffer_size = 512K table_cache = 32 max_allowed_packet = 1M key_buffer = 16k query_cache_type = 1 query-cache-size = 32M thread_cache_size = 16 net_buffer_length = 2K thread_stack = 256K wait_timeout = 300 slow_query_log #login慢查询= /无功/日志/ mysql /下慢queries.log slow_query_log = /无功/日志/ MySQL的/慢queries.log long_query_time = 1 [mysqld_safe的] 对数误差=的/ var /数/ mysqld.log PID文件= / var / run中/ mysqld的/ mysqld.pid
和PHP memory_limit = 64M
这些设置都是关于平衡的,你可以获得多高的内存,而不用担心内存不足和服务器崩溃,或者让你的进程被vps父母杀死,这也是你为什么要获得SegFaults的原因。
通常,当我优化一台服务器时,我将运行mysql tuning-primer.sh脚本来了解最大MySQL能够使用多less内存:
https://launchpad.net/mysql-tuning-primer
然后,为了prefork,我会乘上php memory_limit MaxClients,以了解Apache + PHP在最大可以使用多less内存。 这些粗略估计,但一旦你做了这么多,你有一种感觉。
我试图保持这些2的权利总是围绕服务器的最大内存,如果你的VPS没有交换分区,我一定会尝试保持它低于最大RAM有几个原因:
1)服务器上的其他进程将使用内存
2)服务器上的一些php脚本可能正在使用ini_set来改变自己的memory_limit。
如果你可以提供/etc/my.cnf和php memory_limit,我可能会为你提供一些很好的设置。
编辑:我只是想提到我知道你使用的工人,而不是prefork,同样的概念适用,但工人必须处理线程,而不仅仅是MaxClients所以prefork是一个更好的例子。 获取所需信息后,我将不得不查看设置,以便给出好的build议