如果你的Linux没有Mongo最新的包,可以按官方说明添加上去,方法如下:
#新建Mogo的仓库的配置: ~$ vi /etc/yum.repos.d/mongodb-org-3.2.repo #添加下面内容 [mongodb-org-3.2] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ gpgcheck=0 enabled=1 #使用下面安装最新Mongodb ~$ sudo yum install -y mongodb-org
安装完成,启动测试:
~$ /etc/init.d/mongod start Starting mongod: [ OK ] ~$ ps aux |grep mongo mongod 13084 2.7 0.8 394988 65700 ? Sl 03:33 0:00 /usr/bin/mongod -f /etc/mongod.conf root 13103 0.0 0.0 103304 848 pts/1 S+ 03:33 0:00 grep mongo
链接测试:
~$ mongo localhost MongoDB shell version: 3.2.0 connecting to: localhost Welcome to the MongoDB shell. For interactive help, type "help". For more comprehensive documentation, see http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user Server has startup warnings: 2015-12-23T03:33:40.179+0000 I CONTROL [initandlisten] 2015-12-23T03:33:40.179+0000 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.
解决WARNING: soft rlimits too low.
~$ /etc/security/limits.d/99-mongodb-nproc.conf mongod soft nofile 64000 mongod hard nofile 64000 mongod soft nproc 32000 mongod hard nproc 32000 #保存重启 ~$ service mongod restart Stopping mongod: [ OK ] Starting mongod: [ OK ] #链接测试: ~$ mongo localhost MongoDB shell version: 3.2.0 connecting to: localhost >
设置开机自启动:
~$ chkconfig --list |grep mongo mongod 0:off 1:off 2:off 3:on 4:off 5:on 6:off ~$ chkconfig --level 345 mongod on
更多参考:
https://docs.mongodb.org/manual/reference/ulimit/
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/#install-mongodb
http://blog.csdn.net/kk185800961/article/details/45613267