mongodb 无法启动/启动本地 mongo db
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12514119/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Unable to start/launch local mongo db
提问by mpuncel
I'm new to MongoDB. I currently have a dump of a mongo db (i.e. directory of .bson files) and am trying to import that into mongo.
我是 MongoDB 的新手。我目前有一个 mongo db 的转储(即 .bson 文件的目录),我正在尝试将其导入 mongo。
I installed mongo as per the instructions on http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/.
我按照http://docs.mongodb.org/manual/tutorial/install-mongodb-on-os-x/上的说明安装了 mongo 。
I'm currently trying to test starting a local mongo instance by running mongod --dbpath /path/to/my/mongodata (which is an empty directory).
我目前正在尝试通过运行 mongod --dbpath /path/to/my/mongodata (这是一个空目录)来测试启动本地 mongo 实例。
I get the following in stdout:
我在标准输出中得到以下信息:
Thu Sep 20 09:46:01 [initandlisten] MongoDB starting : pid=1065 port=27017 dbpath=/path/to/my/mongodata/ 64-bit host=dhcp-18-111-28-92.dyn.mit.edu
Thu Sep 20 09:46:01 [initandlisten]
Thu Sep 20 09:46:01 [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 266 processes, 2560 files. Number of processes should be at least 1280 : 0.5 times number of files.
Thu Sep 20 09:46:01 [initandlisten] db version v2.2.0, pdfile version 4.5
Thu Sep 20 09:46:01 [initandlisten] git version: f5e83eae9cfbec7fb7a071321928f00d1b0c5207
Thu Sep 20 09:46:01 [initandlisten] build info: Darwin bs-osx-106-x86-64-1.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:33:36 PDT 2011; root:xnu-1504.15.3~1/RELEASE_I386 i386 BOOST_LIB_VERSION=1_49
Thu Sep 20 09:46:01 [initandlisten] options: { dbpath: "/path/to/my/mongodata/" }
Thu Sep 20 09:46:01 [initandlisten] journal dir=/path/to/my/mongodata/journal
Thu Sep 20 09:46:01 [initandlisten] recover : no journal files present, no recovery needed
Thu Sep 20 09:46:01 [websvr] admin web console waiting for connections on port 28017
Thu Sep 20 09:46:01 [initandlisten] waiting for connections on port 27017
At this point, it just hangs there and does nothing. Seems like it's waiting for something to happen on localhost, but I don't know mongo well enough to understand what's going on. Any help?
此时,它只是挂在那里,什么也不做。似乎它正在等待本地主机上发生的事情,但我不太了解 mongo 以了解发生了什么。有什么帮助吗?
回答by Mattias
There is nothing wrong, you have started the server, it is running and listening on port 27017
. Now you can start to interact with the server, for example just open a new terminal tab and run mongo
,which will open mongo's interactive console and connects to the default server(localhost:27017
)
没有错,您已经启动了服务器,它正在运行并侦听端口27017
。现在您可以开始与服务器交互,例如只需打开一个新的终端选项卡并运行mongo
,这将打开 mongo 的交互控制台并连接到默认服务器(localhost:27017
)
If you want to run mongod as a background process (to get back the console) you can use --forkcommand option. This requires you to use some sort of logging.
如果您想将 mongod 作为后台进程运行(以返回控制台),您可以使用--fork命令选项。这需要您使用某种日志记录。
Eg. mongod --dbpath /path/to/my/mongodata --fork --logpath /path/to/my/mongod.log
例如。 mongod --dbpath /path/to/my/mongodata --fork --logpath /path/to/my/mongod.log
If you want to restore a bsonexport you will probably use the mongorestorecommand
如果你想恢复一个 bsonexport 你可能会使用mongorestore命令
回答by Bobby fox
Add the below in the configuration file and call it using monogd
, make sure your bind_ip
is configured as per your requirement and use the below link to add few more replica sets:
在配置文件中添加以下内容并使用调用它monogd
,确保bind_ip
根据您的要求进行配置,并使用以下链接添加更多副本集:
https://docs.mongodb.org/manual/tutorial/deploy-replica-set/
https://docs.mongodb.org/manual/tutorial/deploy-replica-set/
Step 1:
第1步:
vi /etc/mongod.conf
replication: replSetName: rs01
Step 2:
第2步:
mongod --config /etc/mongod.conf
Output:
输出:
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
about to fork child process, waiting until server is ready for connections.
forked process: 30012
child process started successfully, parent exiting
回答by Rajat Sharda
You need to follow the below 2 steps:
您需要按照以下 2 个步骤操作:
Step 1:Open CMD and enter mongod
. This will run the mongo server
第一步:打开CMD,输入mongod
。这将运行 mongo 服务器
Step 2:Open another Command Prompt, move to the location of file and type
第 2 步:打开另一个命令提示符,移动到文件所在的位置并键入
mongorestore -d db_name -c collection_name file.bson
回答by immirza
Copied from official documentation
复制自官方文档
This starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.
这将启动主 MongoDB 数据库进程。控制台输出中的等待连接消息表明 mongod.exe 进程运行成功。
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/
回答by isLishude
pressing ctrl+c or ctrl+z will stop mongod service,and just run sudo servie mongod start
按 ctrl+c 或 ctrl+z 将停止 mongod 服务,只需运行 sudo servie mongod start