mongodb shell无法启动,data / db不存在

时间:2013-12-22 11:59:42

标签: mongodb debian

当我开始mongod trowed错误。有什么问题?

root@cs12867:~# mongod
mongod --help for help and startup options
Sun Dec 22 15:37:44.081 [initandlisten] MongoDB starting : pid=18415 port=27017 dbpath=/data/db/ 64-bit host=cs12867
Sun Dec 22 15:37:44.081 [initandlisten] db version v2.4.6
Sun Dec 22 15:37:44.081 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Sun Dec 22 15:37:44.081 [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
Sun Dec 22 15:37:44.081 [initandlisten] allocator: tcmalloc
Sun Dec 22 15:37:44.081 [initandlisten] options: {}
Sun Dec 22 15:37:44.081 [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
Sun Dec 22 15:37:44.081 dbexit:
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to close listening sockets...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to flush diaglog...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to close sockets...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: waiting for fs preallocator...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: lock for final commit...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: final commit...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: closing all files...
Sun Dec 22 15:37:44.081 [initandlisten] closeAllFiles() finished
Sun Dec 22 15:37:44.081 dbexit: really exiting now

我设置--dbpath

root@cs12867:~# mongod --dbpath /var/lib/mongodb/data/db
Sun Dec 22 15:29:25.121 [initandlisten] MongoDB starting : pid=17739 port=27017 dbpath=/var/lib/mongodb/data/db 64-bit host=cs12867
Sun Dec 22 15:29:25.121 [initandlisten] db version v2.4.6
Sun Dec 22 15:29:25.121 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Sun Dec 22 15:29:25.121 [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
Sun Dec 22 15:29:25.121 [initandlisten] allocator: tcmalloc
Sun Dec 22 15:29:25.121 [initandlisten] options: { dbpath: "/var/lib/mongodb/data/db" }
Sun Dec 22 15:29:25.121 [initandlisten]
Sun Dec 22 15:29:25.121 [initandlisten] ** WARNING: Readahead for /var/lib/mongodb/data/db is set to 2048KB
Sun Dec 22 15:29:25.121 [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
Sun Dec 22 15:29:25.121 [initandlisten] **          http://dochub.mongodb.org/core/readahead
Sun Dec 22 15:29:25.123 [initandlisten] journal dir=/var/lib/mongodb/data/db/journal
Sun Dec 22 15:29:25.123 [initandlisten] recover : no journal files present, no recovery needed
Sun Dec 22 15:29:25.134 [initandlisten] waiting for connections on port 27017
Sun Dec 22 15:29:25.134 [websvr] admin web console waiting for connections on port 28017
Sun Dec 22 15:29:26.179 [initandlisten] connection accepted from 127.0.0.1:37164 #1 (1 connection now open)
Sun Dec 22 15:29:26.179 [FileAllocator] allocating new datafile /var/lib/mongodb/data/db/Tester.ns, filling with zeroes...
Sun Dec 22 15:29:26.179 [FileAllocator] creating directory /var/lib/mongodb/data/db/_tmp
Sun Dec 22 15:29:26.181 [FileAllocator] done allocating datafile /var/lib/mongodb/data/db/Tester.ns, size: 16MB,  took 0 secs
Sun Dec 22 15:29:26.181 [FileAllocator] allocating new datafile /var/lib/mongodb/data/db/Tester.0, filling with zeroes...
Sun Dec 22 15:29:26.181 [FileAllocator] done allocating datafile /var/lib/mongodb/data/db/Tester.0, size: 64MB,  took 0 secs
Sun Dec 22 15:29:26.182 [FileAllocator] allocating new datafile /var/lib/mongodb/data/db/Tester.1, filling with zeroes...
Sun Dec 22 15:29:26.182 [FileAllocator] done allocating datafile /var/lib/mongodb/data/db/Tester.1, size: 128MB,  took 0 secs
Sun Dec 22 15:29:26.184 [conn1] build index Tester.user { _id: 1 }
Sun Dec 22 15:29:26.184 [conn1] build index done.  scanned 0 total records. 0 secs
Sun Dec 22 15:29:26.184 [conn1] end connection 127.0.0.1:37164 (0 connections now open)
Sun Dec 22 15:29:26.192 [initandlisten] connection accepted from 127.0.0.1:37165 #2 (1 connection now open)
Sun Dec 22 15:29:26.732 [initandlisten] connection accepted from 127.0.0.1:37166 #3 (2 connections now open)
Sun Dec 22 15:29:26.733 [conn3] end connection 127.0.0.1:37166 (1 connection now open)
Sun Dec 22 15:29:26.740 [initandlisten] connection accepted from 127.0.0.1:37167 #4 (2 connections now open)
Sun Dec 22 15:29:26.740 [conn4] end connection 127.0.0.1:37167 (1 connection now open)
Sun Dec 22 15:29:26.834 [initandlisten] connection accepted from 127.0.0.1:37168 #5 (2 connections now open)
Sun Dec 22 15:29:26.835 [conn5] end connection 127.0.0.1:37168 (1 connection now open)
Sun Dec 22 15:29:26.843 [initandlisten] connection accepted from 127.0.0.1:37169 #6 (2 connections now open)
Sun Dec 22 15:29:27.252 [initandlisten] connection accepted from 127.0.0.1:37170 #7 (3 connections now open)
Sun Dec 22 15:29:27.253 [conn7] end connection 127.0.0.1:37170 (2 connections now open)
Sun Dec 22 15:29:27.304 [initandlisten] connection accepted from 127.0.0.1:37171 #8 (3 connections now open)
Sun Dec 22 15:29:27.304 [conn8] end connection 127.0.0.1:37171 (2 connections now open)
Sun Dec 22 15:29:28.332 [initandlisten] connection accepted from 127.0.0.1:37173 #9 (3 connections now open)
Sun Dec 22 15:29:28.333 [conn9] end connection 127.0.0.1:37173 (2 connections now open)
Sun Dec 22 15:29:28.352 [initandlisten] connection accepted from 127.0.0.1:37174 #10 (3 connections now open)
Sun Dec 22 15:29:28.842 [conn10] end connection 127.0.0.1:37174 (2 connections now open)
Sun Dec 22 15:29:28.862 [initandlisten] connection accepted from 127.0.0.1:37176 #11 (3 connections now open)
Sun Dec 22 15:29:28.863 [conn11] end connection 127.0.0.1:37176 (2 connections now open)
Sun Dec 22 15:29:30.362 [initandlisten] connection accepted from 127.0.0.1:37178 #12 (3 connections now open)
Sun Dec 22 15:29:30.363 [initandlisten] connection accepted from 127.0.0.1:37179 #13 (4 connections now open)
Sun Dec 22 15:29:30.364 [conn13] end connection 127.0.0.1:37179 (3 connections now open)
Sun Dec 22 15:37:36.523 [signalProcessingThread] shutdown: closing all files...
Sun Dec 22 15:37:36.523 [signalProcessingThread] closeAllFiles() finished
Sun Dec 22 15:37:36.523 [signalProcessingThread] journalCleanup...
Sun Dec 22 15:37:36.523 [signalProcessingThread] removeJournalFiles
Sun Dec 22 15:37:36.525 [signalProcessingThread] shutdown: removing fs lock...
Sun Dec 22 15:37:36.525 dbexit: really exiting now

然后再说:

root@cs12867:~# mongod
mongod --help for help and startup options
Sun Dec 22 15:37:44.081 [initandlisten] MongoDB starting : pid=18415 port=27017 dbpath=/data/db/ 64-bit host=cs12867
Sun Dec 22 15:37:44.081 [initandlisten] db version v2.4.6
Sun Dec 22 15:37:44.081 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Sun Dec 22 15:37:44.081 [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
Sun Dec 22 15:37:44.081 [initandlisten] allocator: tcmalloc
Sun Dec 22 15:37:44.081 [initandlisten] options: {}
Sun Dec 22 15:37:44.081 [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
Sun Dec 22 15:37:44.081 dbexit:
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to close listening sockets...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to flush diaglog...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: going to close sockets...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: waiting for fs preallocator...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: lock for final commit...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: final commit...
Sun Dec 22 15:37:44.081 [initandlisten] shutdown: closing all files...
Sun Dec 22 15:37:44.081 [initandlisten] closeAllFiles() finished
Sun Dec 22 15:37:44.081 dbexit: really exiting now

3 个答案:

答案 0 :(得分:15)

mongodb的默认数据库路径为/data/db/

所以当你跑:

mongod

MongoDB检查/ data / db /是否存在以及用户是否有权访问它。在您的情况下,没有这样的目录,因此错误。

但是,您可以使用mongod的--dbpath参数覆盖默认数据库路径(或使用配置文件)。

mongod --dbpath /var/lib/mongodb/data/db

在这种情况下,而不是检查/ data / db / mongoDB检查/ var / lib / mongodb / data / db。在您的情况下,您拥有指定的目录,并且您可以访问它,因此它会运行。

这样做不会启动mongo shell。要启动shell,请如上所述首先启动mongod并使其保持运行状态。然后在另一个终端执行

mongo

这将启动mongo shell。

答案 1 :(得分:2)

正如我从问题中看到的那样,创建data / db目录将解决您的问题。

创建它然后如果在c盘中有目录路径则添加如下。

mongod --dbpath "c://data/db"

设置dbpath后,您应该将mongodb作为服务启动。

sudo service mongodb start

答案 2 :(得分:1)

该问题的另一个解决方案可能是:

删除 / data / journal / / data / db / journal /

内的文件

特别是如果您的数据库在不干净的重启/崩溃后停止工作。似乎日志文件可能被破坏并阻止mongo服务启动。 请记住先备份文件以防万一。

关注这些帖子:

https://stackoverflow.com/a/16323101

https://jira.mongodb.org/browse/SERVER-5380