简述:机器为一台虚拟机 两个cpu(Intel(R) Xeon(R) CPU           E5410  @ 2.33GHz)、2G内存。

     并发小于3w。用一台机器应该足以抗住。

配置:nginx 1.06 + php_cgi (PHP 5.2.13) +mysql (5.1.42-log MySQL Community Server)


1.问题截图:php_cgi消耗cpu过高导致机器很卡 查看内存也不足。

php-cgi消耗cpu过多导致机器负责过高

2.做出调整:

1. nginx少开两个进程:

 

user  nobody nobody;
worker_processes  2;
worker_rlimit_nofile 51200;

2.调整php_cgi的子进程数:

 

/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 1026 -C 12 -u nobody -f /usr/local/php-fcgi/bin/php-cgi
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 1027 -C 12 -u nobody -f /usr/local/php-fcgi/bin/php-cgi

3.重启php_cgi和nginx发现效果 不佳。查资料发现有可能eAccelerater模块不兼容,(http://zhangxugg-163-com.iteye.com/blog/873378)

4.修改/usr/local/php-fcgi/lib/php.ini 禁止eaccelerator模块 改为apc加速:

 

[apc]
extension = "apc.so"
apc.enabled = 1
apc.cache_by_default = on
apc.shm_segments = 1
apc.shm_size = 128M
apc.ttl = 7200
apc.user_ttl = 7200
apc.num_files_hint = 1024
apc.write_lock = On
apc.gc_ttl=3600
apc.ttl=0
apc.mmap_file_mask=/tmp/apc.XXXXXX

 5.重启nginx和php_cgi

 

[[email protected] sbin]# cat restart.sh
#!/bin/sh
killall -9 nginx
killall -9 php-cgi
ulimit -HSn 655350
ulimit -a
sleep 3
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 1026 -C 12 -u nobody -f /usr/local/php-fcgi/bin/php-cgi
/usr/local/nginx/sbin/spawn-fcgi -a 127.0.0.1 -p 1027 -C 12 -u nobody -f /usr/local/php-fcgi/bin/php-cgi
/usr/local/nginx/sbin/nginx

6.效果图:

php-cgi消耗cpu过多导致机器负责过高

转载于:https://blog.51cto.com/netspace/1361695

相关文章:

  • 2021-06-02
  • 2021-10-17
  • 2021-05-23
  • 2022-12-23
  • 2021-10-27
  • 2021-08-15
  • 2021-08-25
猜你喜欢
  • 2022-12-23
  • 2021-06-11
  • 2022-12-23
  • 2021-07-05
  • 2022-02-16
  • 2022-12-23
相关资源
相似解决方案