今天下午,测试组同事模拟800个用户同时发起请求,nginx开始报错,
"Too Many Open Files"
 我们使用的是Dell R430服务器,2个物理CPU,每个CPU包含6个内核;
解决方法:
1. 修改系统最大连接数配置:
echo "fs.file-max = 70000" >> /etc/sysctl.conf  &&  echo "nginx soft nofile 10000" >>  /etc/security/limits.conf && echo "nginx hard nofile 30000" >> /etc/security/limits.conf && sysctl -p && sed -i '3a\worker_rlimit_nofile 30000;' /etc/nginx/nginx.conf
 
2. 修改nginx配置文件/etc/nginx/nginx.conf
 

user nginx;
worker_processes 6;
worker_rlimit_nofile 30000;

error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;

events {
  worker_connections 10240;
}

http {
  include /etc/nginx/mime.types;
  default_type application/octet-stream;

  log_format main '$remote_addr - $remote_user [$time_local] "$request" '
          '$status $body_bytes_sent "$http_referer" '
          '"$http_user_agent" "$http_x_forwarded_for"';

          access_log /var/log/nginx/access.log main;

          sendfile on;
          #tcp_nopush on;
          keepalive_timeout 65;
          #gzip on;
          upstream epgservers{
                server 192.168.89.211:81 max_fails=3 fail_timeout=5s;
                server 192.168.89.212:81 max_fails=3 fail_timeout=5s;
                server 192.168.89.213:81 max_fails=3 fail_timeout=5s;
          }

          include /etc/nginx/conf.d/*.conf;

}

/etc/nginx/conf.d/default.conf

server {
  listen 80;
  server_name localhost;

  #charset koi8-r;

  #access_log logs/host.access.log main;

  location / {
    client_max_body_size 300m;
    client_body_buffer_size 128k;
    proxy_connect_timeout 300;
    proxy_read_timeout 300;
    proxy_send_timeout 300;
    proxy_buffer_size 64k;
    proxy_buffers 4 32k;
    proxy_busy_buffers_size 64k;
    proxy_temp_file_write_size 64k;

    proxy_pass http://epgservers;
  }
}

/etc/nginx/conf.d/http.conf

server {
  listen 81;
  server_name localhost;

  #charset koi8-r;

  #access_log logs/host.access.log main;

  location / {
    root /var/www/html;
    index index.html index.htm index.php;
  }

  #error_page 404 /404.html;

  # redirect server error pages to the static page /50x.html
  #
  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
    root html;
  }

  # proxy the PHP scripts to Apache listening on 127.0.0.1:80
  #
  #location ~ \.php$ {
  # proxy_pass http://127.0.0.1;
  #}

  # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
  #

  location ^~ /image/ {
    proxy_redirect off;
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    if ($request_uri ~ /image/(\d+).(\d+).(\d+).(\d+)/(\d+)/(.+))
    {
      set $ip $1.$2.$3.$4;
      set $port $5;
      set $path $6;
    }
    proxy_pass http://$ip:$port/$path;
  }

  location ~ \.php$ {

    root /var/www/html;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
       fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_connect_timeout 150;
    fastcgi_read_timeout 150;
    fastcgi_send_timeout 150;
    fastcgi_buffer_size 64k;
    fastcgi_buffers 4 32k;
    fastcgi_busy_buffers_size 64k;
    fastcgi_temp_file_write_size 64k;
    include fastcgi_params;
    client_max_body_size 10240m;
    client_body_buffer_size 10m;

  }
  

      location /vod{

    alias /usr/local/content  ;

  }


  
#image server rewrite
  rewrite /imgfs/weed/(.*) /app/Imgfs.php?fid=$1 last;
  rewrite ^/sunboss/(\d+)/(.+)  /sunboss/$2?hostid=$1 last;

  
  # deny access to .htaccess files, if Apache's document root
  # concurs with nginx's one
  #
  #location ~ /\.ht {
  # deny all;
  #}
  }

3. 重启nginx
service nginx restart
 
4. 检查确认:
 
ps -ef|grep nginx
root      58651      1  0 18:23 ?        00:00:00 nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
nginx     58652  58651  0 18:23 ?        00:00:06 nginx: worker process
nginx     58653  58651  0 18:23 ?        00:00:03 nginx: worker process
nginx     58654  58651  0 18:23 ?        00:00:05 nginx: worker process
nginx     58655  58651  0 18:23 ?        00:00:05 nginx: worker process
root      68259  34657  0 18:26 pts/0    00:00:00 tailf /var/log/nginx/error.log
root      83634  82399  0 18:27 pts/2    00:00:02 tailf /var/log/nginx/access.log
root     146535  55465  0 18:54 pts/1    00:00:00 grep --color=auto nginx
 
 
cat /proc/58655/limits 
Limit                     Soft Limit           Hard Limit           Units     
Max cpu time              unlimited            unlimited            seconds   
Max file size             unlimited            unlimited            bytes     
Max data size             unlimited            unlimited            bytes     
Max stack size            8388608              unlimited            bytes     
Max core file size        0                    unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             127387               127387               processes 
Max open files            30000                30000                files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       127387               127387               signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us    
 
 
第二台应用节点绑定epgservice虚拟IP, 三台应用节点都要修改;

nginx高并发下配置参数的更多相关文章

  1. Nginx高并发简单配置

    https://www.cnblogs.com/sunjianguo/p/8298283.html 停用除SSH外的所有服务,仅保留nginx,优化思路主要包括两个层面:系统层面+nginx层面. 1 ...

  2. Keepalived+Nginx高可用架构配置

    1.yum install -y libnfnetlink-devel2.yum -y install libnl libnl-devel 3.yum -y install openssl-devel ...

  3. 针对Properties中实时性要求不高的配置参数,用Java缓存起来

    Properties常用于项目中参数的配置,当项目中某段程序需要获取动态参数时,就从Properties中读取该参数,使程序是可配置的.灵活的. 有些配置参数要求立即生效,有些则未必: 一.实时性要求 ...

  4. [效果不错] nginx 高并发参数配置及linux内核参数优化,完整的内核优化设置。PHP-FPM高负载解决办法。

    背景:对vps小资源的实践中对,https://justwinit.cn/post/7536/ 的再优化,再实践,再优化,特别是Nginx,PHP,内核: 零)Nginx: error_log /da ...

  5. 高并发下的 Nginx 优化与负载均衡

    高并发下的 Nginx 优化   英文原文:Optimizing Nginx for High Traffic Loads 过去谈过一些关于Nginx的常见问题; 其中有一些是关于如何优化Nginx. ...

  6. 高并发下的Nginx优化

    高并发下的Nginx优化 2014-08-08 13:30 mood Nginx    过去谈过一些关于Nginx的常见问题; 其中有一些是关于如何优化Nginx. 很多Nginx新用户是从Apach ...

  7. Nginx配置upstream实现负载均衡及keepalived实现nginx高可用

    (原文链接:http://www.studyshare.cn/blog-front//blog/details/1159/0 ) 一.准备工作 1.准备两个项目,发布到不同的服务器上,此处使用2个虚拟 ...

  8. nginx 配置参数优化

    nginx作为高性能web服务器,即使不特意调整配置参数也可以处理大量的并发请求.以下的配置参数是借鉴网上的一些调优参数,仅作为参考,不见得适于你的线上业务. worker进程 worker_proc ...

  9. tengine编译安装及nginx高并发内核参数优化

    Tengine Tengine介绍 Tengine是由淘宝网发起的Web服务器项目.它在Nginx的基础上,针对大访问量网站的需求,添加了很多高级功能和特性. Tengine的性能和稳定性已经在大型的 ...

随机推荐

  1. Humble Numbers HDU - 1058 2分dp

    JGShining's kingdom consists of 2n(n is no more than 500,000) small cities which are located in two ...

  2. https 不会被中间人攻击——因为中间人即使拿到了数据,也是加密的

    只要你登陆了一个使用 HTTPS 数据加密的网站,浏览的页面的内容如果被人中途看见,将会是一团乱码.它也能保证,你浏览的页面就是你想浏览的,不会被黑客在中途修改,网站收到的数据包也是你最初发的那个,不 ...

  3. python3+ftplib实现ftp客户端

    一.程序说明 1.1 程序实现关键点 python实现ftp客户端,主要会遇到以下四个问题: 第一个问题是使用什么包实现----我们这里是使用标准库中的ftplib 第二个问题是怎么连接登录ftp服务 ...

  4. cpu占用过高排查

    top命令是Linux下常用的性能分析工具,能够实时显示系统中各个进程的资源占用状况,类似于Windows的任务管理器 内容解释: PID:进程的ID USER:进程所有者 PR:进程的优先级别,越小 ...

  5. suffix word ality ally an ancy ance an aneity out ~1

    1● ality 状态,性质   2● ally al+ly ~地   3● an ~地方 ,~人       1★ ance=ancy 性质 ,状态   2★ant ~人,~剂,~的   3★ an ...

  6. bzoj4237

    题解: cdq分治 二位变成一维 二分一下 代码: #include<bits/stdc++.h> using namespace std; typedef long long LL; ; ...

  7. SpringBoot技术点细解

    SpringBoot(主流) SpringBoot简介核心点:1.敏捷开发,轻量级框架 , 弊端:封装太完美,不方便扩展 (但是高版本中的springboot是可以自定义的)2.无需tomcat (j ...

  8. java 实现单向链表

    package cn.com.factroy2; /** * 可以看做是操作链表的工具类,链表的核心结构就是节点的数据结构 * @author wanjn * */ public class Sing ...

  9. vue-4-Class 与 Style 绑定

    v-if <h1 v-if="ok">Yes</h1> 切换多个元素://最终的渲染结果不会包含 <template> 元素 <templ ...

  10. 7.6 C++基本序列式容器效率比较

    参考:http://www.weixueyuan.net/view/6403.html 总结: 对于vector而言,它只是一个可以伸缩长度的数组 对于deque而言,它是一个可以操作头部和尾部的并且 ...