mongodb3.4启动警告 WARNING: soft rlimits too low

时间:2022-11-07 00:50:06

启动警告如下:

# mongo
MongoDB shell version: 3.4.14
connecting to: test
Server has startup warnings:
2020-05-09T12:34:19.688-0700 I CONTROL [initandlisten]
2020-05-09T12:34:19.688-0700 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 1024 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.
>

mongodb当前限制:1024 processes, 64000 files

mongodb建议要求:processes = 0.5*files=32000(至少)

所以需要将 processes  从1024 改为 32000 或更大.

1.查看当前mongodb进程信息

ps -ef | grep mongod
mongod   24283     1  0 12:35 ?        00:00:04 /usr/bin/mongod -f /etc/mongod.conf  
root 24240 22049 0 12:45 pts/2 00:00:00 grep mongod

2.查看限制:Max processes,Max open files 

cat /proc/24283/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 10485760 unlimited bytes
Max core file size 0 unlimited bytes
Max resident set unlimited unlimited bytes
Max processes 1024 32000 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 14833 14833 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us

3.修改 Max processes 或者 files ,有几种方法

(1).方法一

修改配置文件 /etc/security/limits.d/90-nproc.conf 

vi /etc/security/limits.d/90-nproc.conf
*          soft    nproc     1024  
改为:
* soft nproc 32000

重启 mongodb 服务

service mongodb restart
(2).方法二

修改配置文件 /etc/security/limits.conf,添加配置信息

vi /etc/security/limits.conf
mongod soft nofile 64000  
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000

重启 mongod 服务

service mongod restart

也可以查看 limits.conf 更多配置信息和使用方法

man limits.conf

4.查看系统限制

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) 14833
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) 14833
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited

5.mongodb推荐设置

-f (file size): unlimited  
-t (cpu time): unlimited
-v (virtual memory): unlimited
-n (open files): 64000
-m (memory size): unlimited
-u (processes/threads): 64000

直接在当前shell中设置:ulimit -n <value>

ulimit -f unlimited  
ulimit -t unlimited
ulimit -v unlimited
ulimit -n 64000
ulimit -m unlimited
ulimit -u 64000

若要系统启动时在所有生效,将上面的 ulimit 添加到 /etc/profile