如何解决错误:MongoDB中不存在dbpath(/ data / db /)

时间:2012-09-13 06:44:08

标签: mongodb ubuntu

我已经在我的Ubuntu 10.04中安装了mongodb。

我知道当使用命令“ mongod ”启动mongodb服务器时,它需要/ data / db文件夹,并且可以通过创建“/ data / db /”轻松解决它”。另一种方法是使用mongod --dbpath“path”提供自己的路径,当我们打算为db提供自己的自定义路径时。

但是在浏览http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/链接时,我发现有一个配置文件。

我对它进行了以下更改。

#mongodb.conf

dbpath=/EBS/Work/mongodb/data/db/


logpath=/EBS/Work/mongodb/mongodb.log

logappend=true

但是当我尝试使用“mongod”启动服务器时,它会抛出同样的错误 即错误:dbpath(/ data / db /)不存在。 我想知道如何永久地将我的dbpath重定向到我自己的自定义文件夹,因为每次你不想使用“mongod --dbpath path”键入路径。我们希望在配置文件中进行一些更改。

5 个答案:

答案 0 :(得分:56)

假设您已按照说明安装packaged version of MongoDB,则应使用mongod启动并停止service

开始mongod

 sudo service mongodb start

停止mongod

 sudo service mongodb stop

如果使用service命令启动和停止,则应使用配置文件:/etc/mongodb.conf

从命令行

开始mongod

如果您直接运行mongod而不是使用服务定义,则还需要将配置文件指定为command line parameter,如果您想要使用它:

mongod --config /etc/mongodb.conf

答案 1 :(得分:7)

以下是我如何解决这个问题,只需遵循他们的官方文件即可。 HERE

从teminal(运行ubuntu)一步一步:

  1. cd into / srv folder =>> cd /srv/
  2. make directory =>> mkdir -p mongodb
  3. 从/ srv /中为新创建的mongodb文件夹提供正确的权限和组......
  4. 最后,运行this => mongod --dbpath /srv/mongodb/
  5. “一步一步”终端的副本...... :)

     ~$ mongod 
        Tue Jun  3 20:27:39.564 [initandlisten] MongoDB starting : pid=5380 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
        Tue Jun  3 20:27:39.564 [initandlisten] db version v2.4.10
        Tue Jun  3 20:27:39.564 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
        Tue Jun  3 20:27:39.564 [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
        Tue Jun  3 20:27:39.564 [initandlisten] allocator: tcmalloc
        Tue Jun  3 20:27:39.564 [initandlisten] options: { dbpath: "/srv/mongodb/" }
        Tue Jun  3 20:27:39.565 [initandlisten] exception in initAndListen: 10296 
        *********************************************************************
         ERROR: dbpath (/srv/mongodb/) does not exist.
         Create this directory or give existing directory in --dbpath.
         See http://dochub.mongodb.org/core/startingandstoppingmongo
        *********************************************************************
        , terminating
        Tue Jun  3 20:27:39.565 dbexit: 
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: going to close listening sockets...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: going to flush diaglog...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: going to close sockets...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: waiting for fs preallocator...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: lock for final commit...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: final commit...
        Tue Jun  3 20:27:39.565 [initandlisten] shutdown: closing all files...
        Tue Jun  3 20:27:39.565 [initandlisten] closeAllFiles() finished
        Tue Jun  3 20:27:39.565 dbexit: really exiting now
             ~$ mongod --dbpath /srv/mongodb/
        Tue Jun  3 20:27:55.616 [initandlisten] MongoDB starting : pid=5445 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
        Tue Jun  3 20:27:55.616 [initandlisten] db version v2.4.10
        Tue Jun  3 20:27:55.616 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
        Tue Jun  3 20:27:55.616 [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
        Tue Jun  3 20:27:55.616 [initandlisten] allocator: tcmalloc
        Tue Jun  3 20:27:55.616 [initandlisten] options: { dbpath: "/srv/mongodb/" }
        Tue Jun  3 20:27:55.617 [initandlisten] exception in initAndListen: 10296 
    
         ~$ sudo service mongodb start
    start: Job is already running: mongodb
         ~$ sudo service mongodb stop
    mongodb stop/waiting
         ~$ cd /srv/
         ~$~$/srv$ ls
         ~$ /srv$ mkdir mongodb
         ~$ sudo chgrp   /srv
         ~$ sudo chmod 775 /srv
         ~$ cd /srv/
         /srv$ ls
         /srv$ mkdir mongodb
         /srv$ ls mongodb
         /srv$ cd
         ~$ mongod --dbpath /srv/mongodb/
    Tue Jun  3 20:40:57.457 [initandlisten] MongoDB starting : pid=6018 port=27017 dbpath=/srv/mongodb/ 64-bit host= -SVE1411EGXB
    Tue Jun  3 20:40:57.457 [initandlisten] db version v2.4.10
    Tue Jun  3 20:40:57.457 [initandlisten] git version: e3d78955d181e475345ebd60053a4738a4c5268a
    Tue Jun  3 20:40:57.457 [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
    Tue Jun  3 20:40:57.457 [initandlisten] allocator: tcmalloc
    Tue Jun  3 20:40:57.457 [initandlisten] options: { dbpath: "/srv/mongodb/" }
    Tue Jun  3 20:40:57.520 [initandlisten] journal dir=/srv/mongodb/journal
    Tue Jun  3 20:40:57.521 [initandlisten] recover : no journal files present, no recovery needed
    Tue Jun  3 20:41:00.545 [initandlisten] preallocateIsFaster=true 36.86
    Tue Jun  3 20:41:03.489 [initandlisten] preallocateIsFaster=true 35.06
    Tue Jun  3 20:41:07.456 [initandlisten] preallocateIsFaster=true 34.44
    Tue Jun  3 20:41:07.456 [initandlisten] preallocateIsFaster check took 9.935 secs
    Tue Jun  3 20:41:07.456 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.0
    Tue Jun  3 20:41:10.009 [initandlisten]         File Preallocator Progress: 985661440/1073741824    91%
    Tue Jun  3 20:41:22.273 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.1
    Tue Jun  3 20:41:25.009 [initandlisten]         File Preallocator Progress: 933232640/1073741824    86%
    Tue Jun  3 20:41:37.119 [initandlisten] preallocating a journal file /srv/mongodb/journal/prealloc.2
    Tue Jun  3 20:41:40.093 [initandlisten]         File Preallocator Progress: 1006632960/1073741824   93%
    Tue Jun  3 20:41:52.450 [FileAllocator] allocating new datafile /srv/mongodb/local.ns, filling with zeroes...
    Tue Jun  3 20:41:52.450 [FileAllocator] creating directory /srv/mongodb/_tmp
    Tue Jun  3 20:41:52.503 [FileAllocator] done allocating datafile /srv/mongodb/local.ns, size: 16MB,  took 0.022 secs
    Tue Jun  3 20:41:52.517 [FileAllocator] allocating new datafile /srv/mongodb/local.0, filling with zeroes...
    Tue Jun  3 20:41:52.537 [FileAllocator] done allocating datafile /srv/mongodb/local.0, size: 64MB,  took 0.02 secs
    Tue Jun  3 20:41:52.538 [websvr] admin web console waiting for connections on port 28017
    Tue Jun  3 20:41:52.538 [initandlisten] waiting for connections on port 27017
    

答案 2 :(得分:1)

更改新数据目录的用户:

  

chown mongodb [rute_directory] ​​

并尝试另一次启动mongo服务

  

service mongodb start

我用这个解决了同样的问题。

答案 3 :(得分:0)

  1. 从根系统文件夹中查找mongo日志文件
  2. sudo find / -name“mongodb.log”-type f

    结果: /var/log/mongodb/mongodb.log

    1. 打开/var/log/mongodb/mongodb.log

    2. 搜索最后一个“例外”字

    3. 尝试纠正异常

    4. 在我的情况下,例外是下一个: 2015-07-30T15:09:15.806 + 0300 initAndListen中的[initandlisten]异常:当日志/文件存在时,13597无法启动--journal,终止

      我做了下一个:

      1. cd / var / lib / mongodb
      2. rm -r journal /

答案 4 :(得分:0)

如果您使用的是Mac Catalina:

mongod --dbpath = /用户/用户/数据/数据库 离开这个窗口

然后您可以在另一个窗口中键入。

mongo

显示数据库