linux - mongodb WARNING rlimit too low?
黄舟
黄舟 2017-04-17 15:02:19
0
3
909

启动mongodb,连接之后提示警告

2016-06-02T18:31:22.635+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 14794 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.

根据网上提示修改了多处地方

vi /etc/security/limits.conf 
#2016-6-2 modified
* soft nofile 65536
* hard nofile 65536
* soft nproc 65536
* hard nproc 65536
# End of file
vi /etc/security/limits.d/90-nproc.conf
# Default limit for number of user's processes to prevent
# accidental fork bombs.
# See rhbz #432903 for reasoning.

*          soft    nproc     65536
root       soft    nproc     unlimited

修改完配置文件都重启过系统,并且重启mongodb,仍然无效
根据进程id查看mongod加载的limit参数始终没能修改成功

[root@localhost ~]# ps -ef|grep mongod
root      3140  2604  0 18:31 ?        00:00:04 /appdev/mongodb/bin/mongod --config /data/mongodb0/conf/mongodb0.conf -quiet
root      3238  3112  0 18:32 pts/0    00:00:00 /appdev/mongodb/bin/mongo 192.168.1.205:29001
root      3260  3208  0 18:39 pts/1    00:00:00 grep mongod
[root@localhost ~]# 
[root@localhost ~]# cat /proc/3140/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        unlimited            unlimited            bytes     
Max resident set          unlimited            unlimited            bytes     
Max processes             14794                14794                processes 
Max open files            65536                65536                files     
Max locked memory         65536                65536                bytes     
Max address space         unlimited            unlimited            bytes     
Max file locks            unlimited            unlimited            locks     
Max pending signals       14794                14794                signals   
Max msgqueue size         819200               819200               bytes     
Max nice priority         0                    0                    
Max realtime priority     0                    0                    
Max realtime timeout      unlimited            unlimited            us        
[root@localhost ~]# 

Max processes始终都是“14794”,而不是修改之后的“65536”

这是什么原因,求解答!

modify by 2016-06-03 10:15
后来各方面排查了一下,也根据一楼的答案检查过了;发现问题不在于mongodb,而是在supervisord
我的mongodb是用supervisord来管理的,使用supervisord来启动mongodb之后,mongodb的进程始终加载不了最新修改过的max process,如果直接用mongod命令启动mongodb则可以正常加载到最新修改的max process,supervisord配置是用root用户启动mongodb的,mongod命令也是一样用的root用户启动

supervisord配置:
[program:mongodb]
command = /appdev/mongodb/bin/mongod --config /data/mongodb0/conf/mongodb0.conf -quiet
autostart = true
autorestart = true
redirect_stderr=true 
user = root
priority=9
startsecs=30
stdout_logfile=/data/log/log4supervisord/console_mongodb.log
stdout_logfile_maxbytes=50MB
environment=NLS_LANG="AMERICAN_AMERICA.UTF8",LANG="en_US.UTF-8"
[root@localhost ~]# 

实在不解,为何supervisord来管理mongodb,无法加载limits

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

reply all(3)
迷茫

The final solution is to modify the startup parameters of supervisord (/etc/init.d/supervisord) and add two lines:

ulimit -n65536
ulimit -u 65536

Supervisord has always been unable to load the system's /etc/security/limit.conf, and the ulimit and other parameters of the process monitored by supervisord cannot exceed supervisord itself, so we can only increase the upper limit of supervisord first, and then mongodb It can be adjusted.
Thank you very much to the two hosts for their answers, they are both very helpful.

左手右手慢动作

Log in to the user who started the mongo process
ulimit -a to see if it is successful. If successful, directly start the mongo process with this user and see if the changes have been made
If not, pam_limit.so has not been loaded. , just modify the /etc/pam.d/login file and add pam_limit.so

左手右手慢动作

Try adding minfds=64000 to the supervisord configuration

You can also try
command=bash -c "ulimit -n 64000;ulimit -u 64000; exec /appdev/mongodb/bin/mongod --config /data/mongodb0/conf/mongodb0.conf -quiet"

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template