mongodb报错:connection refused because too many open connections: 819

感谢原作者,很受用

 

问题:

发现mongodb无法连接,查看mongodb日志,出现大量的如下报错:

[initandlisten] connection refused because too many open connections: 819

mongodb的连接数到达819后,就无法增加,所以无法连接上去。

分析解决:

1、maxConns 限制

默认情况下,在Linux系统中,mongodb的最大连接数为819。

可以修改mongodb的最大连接数,修改其配置文件mongod.conf:

maxConns=20000  #官方指定,mongodb最大连接数设置,不能超过20000

重启mongodb服务,让配置生效。

2、ulimit 限制

如果调大了maxConns,还是出现 too many open connections 的报错,也可能跟系统的ulimit限制有关。

Linux系统默认每个进程的文件句柄限制open files 为1024,这数值一般过小,需要调大。

查看系统当前所有的limit信息 # ulimit -a core file size (blocks, -c) 0 data seg size (kbytes, -d) unlimited scheduling priority (-e) 0 file size (blocks, -f) unlimited pending signals (-i) 7672 max locked memory (kbytes, -l) 64 max memory size (kbytes, -m) unlimited open files (-n) 1024 pipe size (512 bytes, -p) 8 POSIX message queues (bytes, -q) 819200 real-time priority (-r) 0 stack size (kbytes, -s) 10240 cpu time (seconds, -t) unlimited max user processes (-u) 1024 virtual memory (kbytes, -v) unlimited file locks (-x) unlimited

使用 ulimit -n 修改 open files 限制:(当前session生效)

# ulimit -n 102400

更改系统限制,修改 /etc/security/limits.conf ,添加如下行: (永久生效)

* soft nofile 102400
* hard nofile 102400  

 

https://cloud.tencent.com/developer/article/1508179

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值