使用nginx负载均衡,webbench做压力测试出现的问题,求助

justblues 2014-09-15 08:17:21
台式机配置:双核4G内存
VM开了三个虚拟机:一个做nginx服务器,设memory1G,ip:10.10.21.134;两个做web服务器,使用的是自己装的Q2A网站,memory都是1G,ip分别为:10.10.21.135,10.10.21.138
nginx.conf主要内容:
worker_processes 2;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
#均衡
upstream webservers{
server 10.10.21.135 max_fails=3 fail_timeout=1s weight=1;
server 10.10.21.138 max_fails=3 fail_timeout=1s weight=1;
server 127.0.0.1:8080 backup;
#缓存
proxy_cache_path /nginx/cache/first levels=1:2:1 keys_zone=a:20m max_size=1g;
server {
listen 80;
server_name localhost;
location / {
proxy_pass http://webservers/;
proxy_set_header X-Real-IP $remote_addr;
proxy_connect_timeout 300;
proxy_read_timeout 300;
proxy_send_timeout 300;
proxy_cache a;
#js与css请求
location ~.*\.(gif|jpg|jpeg|png|bmp|swf|css|js)$
{
proxy_pass http://10.10.21.135;
}
}

}



apache2.conf的最主要配置:
Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 15
<IfModule mpm_prefork_module>
StartServers 5
MinSpareServers 5
MaxSpareServers 6
ServerLimit 550
MaxClients 500
MaxRequestsPerChild 10000
</IfModule>
HostnameLookups Off


使用webbench做测试时,60S并发1000时基本均衡,漏掉的请求也不是很多,60S并发1500做测试时,使用grep 'GET /' /var/log/nginx/access.log | grep '15/Sep/2014:19'|wc -l 命令对access.log做计算时结果如下:
nginx服务器:
两个web:

结果漏了很多请求

error.log内容:
nginx:2014/09/15 19:30:04 [error] 29561#0: *7668 connect() failed (110: Connection timed out) while connecting to upstream, client: 10.10.21.137, server: localhost, request: "GET / HTTP/1.0", upstream: "http://10.10.21.135:80/", host: "10.10.21.134"
135服务器:
[error] [client 10.10.21.134] PHP Notice: session_start(): ps_files_cleanup_dir: opendir(/var/lib/php5) failed: Permission denied (13) in /var/www/question2answer/qa-include/qa-app-users.php on line 150
138服务器:
[error] [client 10.10.21.134] request failed: error reading the headers


难道这就是极限了吗?还是我的配置数据有问题啊?
怎样优化nginx的配置呢?
寻求这位的帮助~~
...全文
944 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiongchangjing 2014-09-17
  • 打赏
  • 举报
回复
引用 5 楼 justblues 的回复:
[quote=引用 3 楼 xiongchangjing 的回复:] linux设置最大连接数 [root@localhost ~]# vi /etc/security/limits.conf 加入 * soft nofile 1048576 * hard nofile 1048576 vi /etc/sysctl.conf 加入 fs.file-max = 1048576 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_mem = 786432 2097152 3145728 net.ipv4.tcp_rmem = 4096 4096 16777216 net.ipv4.tcp_wmem = 4096 4096 16777216 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 /sbin/sysctl -p /etc/sysctl.conf 以前我测连接数也是到1000就 不行了,linux系统默认最大连接1024 你按照我的改下再测测试试
为什么我改完ulimit -n 还是1024呢?我reboot过[/quote] 你确定你vi 编辑完是:wq! 写入保存退出的??你source这个文件再看下
  • 打赏
  • 举报
回复
it sounds like an issue for apache instead of nginx. nginx just simply complaint that there was a problem to talk with apache. According to the error message in apache log, it should be a php issue: In your php.ini set session.gc_probability to 0. Essentially, the garbage collection is set up to be done by cron jobs on some systems (i.e. Ubuntu/Debian). Some php ini executables like php-cli also try to do garbage collection and that results in the error you got. You got tihs error because apache was experiencing some high volume concurrency, which is what u expected. So, php GC was triggered earlier than it used to be... http://stackoverflow.com/questions/2904862/issues-with-php-5-3-and-sessions-folder
justblues 2014-09-16
  • 打赏
  • 举报
回复
顶一顶!啊啊啊
justblues 2014-09-16
  • 打赏
  • 举报
回复
引用 3 楼 xiongchangjing 的回复:
linux设置最大连接数 [root@localhost ~]# vi /etc/security/limits.conf 加入 * soft nofile 1048576 * hard nofile 1048576 vi /etc/sysctl.conf 加入 fs.file-max = 1048576 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_mem = 786432 2097152 3145728 net.ipv4.tcp_rmem = 4096 4096 16777216 net.ipv4.tcp_wmem = 4096 4096 16777216 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 /sbin/sysctl -p /etc/sysctl.conf 以前我测连接数也是到1000就 不行了,linux系统默认最大连接1024 你按照我的改下再测测试试
为什么我改完ulimit -n 还是1024呢?我reboot过
justblues 2014-09-16
  • 打赏
  • 举报
回复
引用 1 楼 justblues 的回复:
顶一顶!啊啊啊
??
xiongchangjing 2014-09-16
  • 打赏
  • 举报
回复
linux设置最大连接数 [root@localhost ~]# vi /etc/security/limits.conf 加入 * soft nofile 1048576 * hard nofile 1048576 vi /etc/sysctl.conf 加入 fs.file-max = 1048576 net.ipv4.ip_local_port_range = 1024 65535 net.ipv4.tcp_mem = 786432 2097152 3145728 net.ipv4.tcp_rmem = 4096 4096 16777216 net.ipv4.tcp_wmem = 4096 4096 16777216 net.ipv4.tcp_tw_reuse = 1 net.ipv4.tcp_tw_recycle = 1 /sbin/sysctl -p /etc/sysctl.conf 以前我测连接数也是到1000就 不行了,linux系统默认最大连接1024 你按照我的改下再测测试试

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧