MongoDB WARNING: soft rlimits too low
2016-04-12T08:33:33.801+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
0x00 limits
limits可以对cpu、文件数等进行限制,通过它可以针对某个用户或全部进行限制。limits分为soft limit和hard limit。soft limit可以超过,而不能超过hard limit (除非有root权限)。
ulimit -Sn 查看soft limit
ulimit -Hn 查看hard limit
0x01 MongoDB 建议设置
从这条warning来看,process建议设置至少为0.5倍的文件数(0.5x32000=16000)。
MongoDB ulimit建议设置:https://docs.mongodb.org/manual/reference/ulimit/#memory-size
0x02 ulimit 设置
修改配置文件 /etc/security/limits.conf
mongod soft fsize unlimited
mongod hard fsize unlimited
mongod soft cpu unlimited
mongod hard cpu unlimited
mongod soft as unlimited
mongod hard as unlimited
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 64000
mongod hard nproc 64000
MongoDB推荐设置:
limit fsize unlimited unlimited # (file size)
limit cpu unlimited unlimited # (cpu time)
limit as unlimited unlimited # (virtual memory size)
limit nofile 64000 64000 # (open files)
limit nproc 64000 64000 # (processes/threads)
重启MongoDB服务:
systemctl restart mongod
0x03 查看 MongoDB limits
ps -ef | grep mongod
mongod 14795 1 1 09:02 ? 00:00:02 /usr/bin/mongod -f /etc/mongod.conf
cat /proc/14795/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 64000 64000 processes
Max open files 64000 64000 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 1883 1883 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0