0

我正在尝试运行命令

  mongod --dbpath=data/db

当我收到此错误时:

  mongod --dbpath=data/db
 [initandlisten] MongoDB starting : pid=10161 port=27017 dbpath=data/db 64-bit host=anr   
 [initandlisten] db version v2.4.9
 [initandlisten] git version: 52fe0d21959e32a5bdbecdc62057db386e4e029c
 [initandlisten] build info: Linux ip-10-2-29-40 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_49
 [initandlisten] allocator: tcmalloc
 [initandlisten] options: { dbpath: "data/db" }
 [initandlisten] exception in initAndListen: 10296 
 *********************************************************************
 ERROR: dbpath (data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
 *********************************************************************

 , terminating
 dbexit: 
[initandlisten] shutdown: going to close listening sockets...
[initandlisten] shutdown: going to flush diaglog...
[initandlisten] shutdown: going to close sockets...
[initandlisten] shutdown: waiting for fs preallocator...
[initandlisten] shutdown: lock for final commit...
[initandlisten] shutdown: final commit...
[initandlisten] shutdown: closing all files...
[initandlisten] closeAllFiles() finished
dbexit: really exiting now

这是我的 /data/db:

.:
total 4
drwxrwxrwx 3 root root 4096 Mar 26 11:24 db

./db:
total 81928
drwxr-xr-x 2 anr anr     4096 Mar 26 16:07 journal
-rw------- 1 anr anr 67108864 Mar 26 16:07 local.0
-rw------- 1 anr anr 16777216 Mar 26 16:07 local.ns
-rwxr-xr-x 1 anr anr        0 Mar 26 16:07 mongod.lock

./db/journal:
total 3145740
-rw------- 1 anr anr 1073741824 Mar 26 16:07 prealloc.0
-rw------- 1 anr anr 1073741824 Mar 25 17:36 prealloc.1
-rw------- 1 anr anr 1073741824 Mar 25 17:36 prealloc.2

更新:

修改了我的 /data/db 路径,这是错误:

 [initandlisten] allocator: tcmalloc
 [initandlisten] options: { dbpath: "/data/db" }
 [initandlisten] journal dir=/data/db/journal
 [initandlisten] recover : no journal files present, no recovery needed
 [initandlisten] ERROR: listen(): bind() failed errno:98 Address already in use for   
 socket: 0.0.0.0:27017
 [initandlisten] ERROR:   addr already in use 
 [initandlisten] now exiting
 [websvr] ERROR: listen(): bind() failed errno:98 Address already in use for socket:   
 0.0.0.0:28017
 [websvr] ERROR:   addr already in use

更新2:

 mongodb  10172     1  0 16:11 ?        00:00:27 /usr/bin/mongod --config 
 /etc/mongodb.conf
 anr      10865  5108  0 17:07 pts/0    00:00:00 grep --colour=auto mongod
4

1 回答 1

1

--db-path 命令不使用 = 符号。它只是 --db-path 例如:

mongod --db-path /data/db

您可能会考虑使用配置文件来简化操作。

根据您的 Linux 风格,您将需要以下命令之一从配置文件运行 Mongod 进程:

mongod --config /etc/mongodb.conf
mongod -f /etc/mongodb.conf

请注意,conf 文件的位置可以在任何您想要的位置,您只需要确保运行 Mongod 的用户对其具有适当的权限。

配置文件允许您指定运行进程所需的大部分选项,包括 dbpath 的位置、日志路径、端口和(重要的)将进程分叉到它自己的后台线程中。示例配置文件可能如下所示:

dbpath = /data/db
logpath = /var/logs/mongo.log
logappend = true
#bind ip = 127.0.0.1
port = 27111
fork = true
rest = true
verbose = true
#auth = true
#noauth = true

'auth' 和 'noauth' 被注释掉以及 bind 只是为了表明这些是你也可以在配置文件中为 Mongod 启动设置的选项。

于 2014-03-26T13:34:36.703 回答