在Linux中运行mongod命令时出错

在Linux中运行mongod命令时出错,linux,mongodb,terminal,linux-mint,mongo-shell,Linux,Mongodb,Terminal,Linux Mint,Mongo Shell,我正在尝试运行命令 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: 52fe0d21959e32a5bdbec

我正在尝试运行命令

  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: --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”被注释掉,并绑定,只是为了表明这些是您也可以在配置文件中为Mongod启动设置的选项。

尝试使用
Mongod--dbpath=/data/db
启动mongo。请注意/before data/db这里的问题是您没有像中那样明确指定路径:
--dbpath=/data/db
,因此现在它正在查找一些“本地化”到您调用命令的位置,如错误消息所示,端口27017上可能运行另一个mongod(或其他进程)。试着运行
ps-ef | grep mongod
来检查mongod是否已经在运行,并使用
kill
@AnandJayabalan杀死该进程。帖子中列出了两个进程,我应该杀死哪一个。
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