Error: EMFILE, too many open files 'xxx.ejs'

来源:互联网 发布:厦门大学网络教育 编辑:程序博客网 时间:2024/06/04 20:01

node 服务挂掉了,优化如下:

编辑文件:/etc/sysctl.conf 加入以下:

net.ipv4.ip_local_port_range='1024 65000'
net.ipv4.tcp_tw_reuse='1'
net.ipv4.tcp_fin_timeout='15'
net.core.netdev_max_backlog='4096'
net.core.rmem_max='16777216'
net.core.somaxconn='4096'
net.core.wmem_max='16777216'
net.ipv4.tcp_max_syn_backlog='20480'
net.ipv4.tcp_max_tw_buckets='400000'
net.ipv4.tcp_no_metrics_save='1'
net.ipv4.tcp_rmem='4096 87380 16777216'
net.ipv4.tcp_syn_retries='2'
net.ipv4.tcp_synack_retries='2'
net.ipv4.tcp_wmem='4096 65536 16777216'
vm.min_free_kbytes='65536'


优化nginx代理设置,

keepalive_timeout  15;


keepalive 64; #设置存活时间。如果不设置可能会产生大量的timewait。

重新启动nginx



用netstat -nop | grep 3000|wc -l 或ss -s查看timewait 明显减少。

附nginx配置:

upstream nodejs__upstream {
        server 127.0.0.1:3001;
keepalive 64;
}
server {
        listen 80;
        server_name www.xxx.com xxx.com;
        access_log /data/var/log/nginx/xxx.log;
        location / {
                proxy_set_header   X-Real-IP            $remote_addr;
                proxy_set_header   X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header   Host                   $http_host;
                proxy_set_header   X-NginX-Proxy    true;
                proxy_set_header   Connection "";
                proxy_http_version 1.1;
                proxy_pass         http://nodejs__upstream;
        }
}

过了几天问题依旧:

vim /etc/security/limits.conf

加入下面两行

* soft nofile 10240
* hard nofile 10240

重启ssh,ulimit -n 查看。。生效。。

待观察。。


参考:

http://www.oschina.net/translate/optimising-nginx-node-js-and-networking-for-heavy-workloads?print

http://blog.fens.me/nodejs-nginx-log4js/

0 0
原创粉丝点击