Env
Debian 9
# 使用通用二进制方式安装
# mongod --version
db version v3.4.21-2.19
git version: 2e0631f5e0d868dd51b71e1e55eb8a57300d00df
OpenSSL version: OpenSSL 1.0.2q 20 Nov 2018
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
An error
To connect given the database, the log display mongodb connection refused because too many open connections: 819
.
Preliminary determination is the number of connections mongodb fulfilled.
Troubleshooting Process
- View mongo connections
xxx:PRIMARY> db.serverStatus().connections
{ "current" : 819, "available" : 0, "totalCreated" : 1132 }
-> connections really full
2. Modify the number of connection attempts, increases mongo startup --maxConns 20000
parameters, restart mongo, a number will connect ran out and said some information is maximum 20,000, the default is 1024 * 0.8
3. Check ulimit -n, this value is 1048576, in line with expectations.
4. Modify the configuration supervisord minfds=1024
100,000, after the restart to see the number of connections, in line with expectations.
xx:PRIMARY> db.serverStatus().connections
{ "current" : 1220, "available" : 78780, "totalCreated" : 2158 }
to sum up
The number of connections is limited mongod
- ulimit -n system level
- supervisord minfds parameters
- mongo maxConns parameters
Eventually, only minfds parameter set, the parameter is not set maxConns, by a supervisor controlled so that the number of connections.