3

我在我的 Ubuntu 13.04 上安装了 MondoDB 并尝试通过输入mongodor来运行它的守护进程sudo mongod,但我遇到了以下消息:

mongod --help for help and startup options
Thu Jun 27 05:11:02 [initandlisten] MongoDB starting : pid=11685 port=27017 dbpath=/data/db/ 64-bit host=myhost
Thu Jun 27 05:11:02 [initandlisten] db version v2.2.4, pdfile version 4.5
Thu Jun 27 05:11:02 [initandlisten] git version: nogitversion
Thu Jun 27 05:11:02 [initandlisten] build info: Linux batsu 3.2.0-37-generic #58-Ubuntu SMP Thu Jan 24 15:28:10 UTC 2013 x86_64 BOOST_LIB_VERSION=1_49
Thu Jun 27 05:11:02 [initandlisten] options: {}
Thu Jun 27 05:11:02 [initandlisten] journal dir=/data/db/journal
Thu Jun 27 05:11:02 [initandlisten] recover : no journal files present, no recovery needed
Thu Jun 27 05:11:02 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
Thu Jun 27 05:11:02 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:28017
Thu Jun 27 05:11:02 [websvr] ERROR:   addr already in use
Thu Jun 27 05:11:02 [initandlisten] ERROR:   addr already in use
Thu Jun 27 05:11:02 [initandlisten] now exiting
Thu Jun 27 05:11:02 dbexit: 
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close listening sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to flush diaglog...
Thu Jun 27 05:11:02 [initandlisten] shutdown: going to close sockets...
Thu Jun 27 05:11:02 [initandlisten] shutdown: waiting for fs preallocator...
Thu Jun 27 05:11:02 [initandlisten] shutdown: lock for final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: final commit...
Thu Jun 27 05:11:02 [initandlisten] shutdown: closing all files...
Thu Jun 27 05:11:02 [initandlisten] closeAllFiles() finished
Thu Jun 27 05:11:02 [initandlisten] journalCleanup...
Thu Jun 27 05:11:02 [initandlisten] removeJournalFiles
Thu Jun 27 05:11:02 [initandlisten] shutdown: removing fs lock...
Thu Jun 27 05:11:02 dbexit: really exiting now

但是,当我尝试通过键入mongo甚至不运行其守护程序来运行 MongoDB 时,似乎我可以成功使用 MongoDB。我没有启动任何守护程序,而且我的终端中只有一个窗口,因此不可能同时运行守护程序和主 mongo 程序......

所以问题是,为什么我可以在不启动任何守护进程的情况下使用 MongoDB?当我在 OS X 上使用 MongoDB 时,我总是必须在使用 MongoDB 之前运行守护程序。为了您的信息,我在我的 OS X 10.8 上通过 Parallels 8 安装了 Ubuntu 13.04,并按照官方文档解释的相同路线安装了 MongoDB。

或者因为我在 OS X 上的 27017 端口使用 MongoDB,我不必在 Virtual Ubuntu 上运行守护进程?(虽然我现在不在 OS X 上运行守护进程......)

4

3 回答 3

9

当您安装 mongo 时,它应该已经为您运行了服务器。

这可以通过它说“addr 已在使用”(这意味着某些东西正在 mongod 端口上运行)以及您可以成功使用它的事实得到证实。

您还可以通过运行ps wuax | grep mongo并在结果列表中查找 mongod 来测试这一点 - 该列表列出了您计算机上运行的所有进程,然后从该列表中删除任何未提及 mongo 的进程。您可能还会看到一行包含“grep”的行 - 这是您当前正在运行的命令,您可以忽略它。

当我在我的电脑上运行它时,它显示:

mongodb  22394  9.1  1.0 109244 33592 ?        Dsl  08:29   0:01 /usr/bin/mongod --config /etc/mongodb.conf
1001     22423  0.0  0.0   9436   904 pts/3    S+   08:29   0:00 grep --color=auto mongo
于 2013-06-26T20:26:33.970 回答
0

Mongod service is running, try to stop it and init mongod with sudo command

sudo service mongodb stop
sudo mongod
于 2014-09-27T23:07:15.293 回答
0

Start mongod Processes

By default, MongoDB stores data in the /data/db directory. On Windows, MongoDB stores data in C:\data\db. On all platforms, MongoDB listens for connections from clients on port 27017.

To start MongoDB using all defaults, issue the following command at the system shell:

mongod

Stop mongod Processes

In a clean shutdown a mongod completes all pending operations, flushes all data to data files, and closes all data files. Other shutdowns are unclean and can compromise the validity of the data files.

To ensure a clean shutdown, always shutdown mongod instances using one of the following methods:

Use shutdownServer()

Shut down the mongod from the mongo shell using the db.shutdownServer() method as follows:

use admin
db.shutdownServer()

Calling the same method from a init script accomplishes the same result.

For systems with authorization enabled, users may only issue db.shutdownServer() when authenticated to the admin database or via the localhost interface on systems without authentication enabled.

Use --shutdown

From the Linux command line, shut down the mongod using the --shutdown option in the following command:

mongod --shutdown

于 2016-01-08T00:08:25.913 回答