[root@pc1 bin]# ./mongo
MongoDB shell version v4.0.4
connecting to: mongodb://127.0.0.1:27017
Implicit session: session { "id" : UUID("5047276c-0682-464d-9bc0-4fa82ebbe63a") }
MongoDB server version: 4.0.4
Server has startup warnings:
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten]
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten]
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** WARNING: This server is bound to localhost.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** Remote systems will be unable to connect to this server.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** Start the server with --bind_ip <address> to specify which IP
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** addresses it should serve responses from, or with --bind_ip_all to
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** bind to all interfaces. If this behavior is desired, start the
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten] ** server with --bind_ip 127.0.0.1 to disable this warning.
2018-12-03T13:02:10.391+0800 I CONTROL [initandlisten]
2018-12-03T13:02:10.392+0800 I CONTROL [initandlisten]
2018-12-03T13:02:10.392+0800 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 65536 files. Number of processes should be at least 32768 : 0.5 times number of files.
查看进程
[root@pc1 local]# ps -ef | grep mongod
root 11975 1 0 13:02 ? 00:00:57 ./bin/mongod -f mongodbStart.conf
root 12908 11930 0 17:53 pts/0 00:00:00 grep --color=auto mongod
查mongod进程的显示
[root@pc1 local]# cat /proc/11975/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 4096 4096 processes
Max open files 65536 131072 files
Max locked memory 65536 65536 bytes
Max address space unlimited unlimited bytes
Max file locks unlimited unlimited locks
Max pending signals 87653 87653 signals
Max msgqueue size 819200 819200 bytes
Max nice priority 0 0
Max realtime priority 0 0
Max realtime timeout unlimited unlimited us
标红处太低了,应适当的调大
修改 Max processes 或者 files ,有几种方法:
方法一:
修改配置文件 /etc/security/limits.d/90-nproc.conf
[root@pc1 local]# vi /etc/security/limits.d/90-nproc.conf
* soft nproc 1024
改为:
* soft nproc 32000
重启 mongod 服务:
[root@pc1 local]# service mongod restart (centos6)
/bin/systemctl restart mongod.service(centos7)
方法二:
修改配置文件 /etc/security/limits.conf,添加配置信息:
[root@pc1 local]# vi /etc/security/limits.conf
mongod soft nofile 64000
mongod hard nofile 64000
mongod soft nproc 32000
mongod hard nproc 32000
重启 mongod 服务:
[root@pc1 local]#service mongod restart(centos6)
/bin/systemctl restart mongod.service(centos7)
也可以查看 limits.conf 更多配置信息和使用方法:
[root@pc1 local]# man limits.conf
查看系统限制:
[[root@pc1 local]# 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
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
[root@pc1 local]# vi /etc/profile
[root@pc1 local]# source etc/profile
ref:https://blog.csdn.net/kk185800961/article/details/45613267