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

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
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值