如何解决错误:dbpath (/data/db/) 在 MongoDB 中不永久存在
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12400808/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to resolve error :dbpath (/data/db/) does not exist permanently in MongoDB
提问by Abhinav
I have installed mongodb in my Ubuntu 10.04.
我已经在我的 Ubuntu 10.04 中安装了 mongodb。
I know that when it comes to start the mongodb server with the command "mongod",then it expects /data/db folder and it can be easily resolved by creating "/data/db/". One more way is to provide your own path using mongod --dbpath "path",when we intend to give our own custom path for db.
我知道当使用命令“ mongod”启动mongodb服务器时,它需要/data/db文件夹,可以通过创建“/data/db/”轻松解决。另一种方法是使用 mongod --dbpath "path" 提供您自己的路径,当我们打算为 db 提供我们自己的自定义路径时。
But while going through http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/link i found that there is a configuration file.
但是在浏览http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/链接时,我发现有一个配置文件。
I made the following changes to it.
我对其进行了以下更改。
# mongodb.conf
# mongodb.conf
dbpath=/EBS/Work/mongodb/data/db/
logpath=/EBS/Work/mongodb/mongodb.log
logappend=true
But still when I try to start the server with "mongod"it throws the same error i.e error :dbpath (/data/db/) does not exist. I wanted to know that how can I permanently redirect my dbpath to my own custom folder cause everytime you don't want to type the path using "mongod --dbpath path".Rather we look to make some changes in configuration file.
但是当我尝试使用“mongod”启动服务器时,它仍然会抛出相同的错误,即错误 :dbpath (/data/db/) does not exist。我想知道如何将我的 dbpath 永久重定向到我自己的自定义文件夹,因为每次您不想使用“mongod --dbpath path”键入路径时。相反,我们希望在配置文件中进行一些更改。
回答by Stennie
Assuming you have followed the instructions to install a packaged version of MongoDB, you should be starting and stopping mongod
using service
.
假设您已按照说明安装了MongoDB的打包版本,您应该开始和停止mongod
使用service
.
To start mongod
:
开始mongod
:
sudo service mongodb start
To stop mongod
:
停止mongod
:
sudo service mongodb stop
If you use the service command to start and stop, it should be using the configuration file: /etc/mongodb.conf
.
如果使用service命令启动和停止,应该使用配置文件:/etc/mongodb.conf
.
Starting mongod
from the command line
启动mongod
命令行
If you run mongod
directly instead of using the service definition, you will also have to specify a configuration file as a command line parameterif you want one to be used:
如果你mongod
直接运行而不是使用服务定义,你还必须指定一个配置文件作为命令行参数,如果你想使用一个:
mongod --config /etc/mongodb.conf
回答by zee
Here is how I got this resolved, simply by following their official Doc . HERE.
这是我解决这个问题的方法,只需遵循他们的官方 Doc 。在这里。
Step by step from teminal (running ubuntu) :
逐步从终端(运行 ubuntu):
- cd into /srv folder =>>
cd /srv/
- make directory =>>
mkdir -p mongodb
- From within /srv/ give the newly created mongodb folder the right permissions and group ......
- Lastly, run this =>
mongod --dbpath /srv/mongodb/
- cd到/srv文件夹=>>
cd /srv/
- 制作目录=>>
mkdir -p mongodb
- 从 /srv/ 中为新创建的 mongodb 文件夹赋予正确的权限和组......
- 最后,运行这个 =>
mongod --dbpath /srv/mongodb/
"step by step" Copy of the terminal ...... :)
《一步一步》复制终端...... :)
~$ 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
回答by Raugaral
Change the user of the new data directory:
更改新数据目录的用户:
chown mongodb [rute_directory]
chown mongodb [rute_directory]
And try another time to start the mongo service
再试一次启动mongo服务
service mongodb start
服务 mongodb 启动
I solve the same problem with this.
我用这个解决了同样的问题。
回答by 1nstinct
- Find mongo log file from root system folder
- 从根系统文件夹中查找 mongo 日志文件
sudo find / -name "mongodb.log" -type f
sudo find / -name "mongodb.log" -type f
result: /var/log/mongodb/mongodb.log
结果:/var/log/mongodb/mongodb.log
open /var/log/mongodb/mongodb.log
search for last "exception" word
try to correct exception
打开/var/log/mongodb/mongodb.log
搜索最后一个“例外”词
尝试纠正异常
In my case exception was the next: 2015-07-30T15:09:15.806+0300 [initandlisten] exception in initAndListen: 13597 can't start without --journal enabled when journal/ files are present, terminating
在我的情况下异常是下一个: 2015-07-30T15:09:15.806+0300 [initandlisten] initAndListen 异常:13597 can't start without --journal enabled when journal/ files are present,终止
I made the next:
我做了下一个:
- cd /var/lib/mongodb
- rm -r journal/
- cd /var/lib/mongodb
- rm -r 日志/
回答by Prakash Singh
If you are using mac catalina:
如果您使用的是 mac catalina:
mongod --dbpath=/Users/user/data/db leave this window
mongod --dbpath=/Users/user/data/db 离开这个窗口
then you can type in another window.
然后你可以在另一个窗口中输入。
mongo
蒙戈
show dbs
显示数据库