![错误:dbpath 不存在](https://linux22.com/image/1100219/%E9%94%99%E8%AF%AF%EF%BC%9Adbpath%20%E4%B8%8D%E5%AD%98%E5%9C%A8.png)
我dbpath
在 mongodb 配置文件中设置:
#dbpath=/var/lib/mongodb
dbpath=~/data/db
然后尝试启动 mongodb 但出现错误:
ERROR: dbpath (~/data/db) does not exist.
尽管我可以检查~/data/db
简单的存在:
# cd ~/data/db
user@server:~/data/db# pwd
/root/data/db
当我运行它时...
# mongod --dbpath ~/data/db
...得到输出:
Tue Oct 15 05:05:49.040 [initandlisten] MongoDB starting : pid=3786 port=27017 dbpath=/root/data/db 64-bit host=callzone2
Tue Oct 15 05:05:49.040 [initandlisten] db version v2.4.6
Tue Oct 15 05:05:49.040 [initandlisten] git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
Tue Oct 15 05:05:49.041 [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 Oct 15 05:05:49.041 [initandlisten] allocator: tcmalloc
Tue Oct 15 05:05:49.041 [initandlisten] options: { dbpath: "/root/data/db" }
Tue Oct 15 05:05:49.044 [initandlisten] exception in initAndListen std::exception: locale::facet::_S_create_c_locale name not valid, terminating
Tue Oct 15 05:05:49.044 dbexit:
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: going to close sockets...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: lock for final commit...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: final commit...
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: closing all files...
Tue Oct 15 05:05:49.044 [initandlisten] closeAllFiles() finished
Tue Oct 15 05:05:49.044 [initandlisten] shutdown: removing fs lock...
Tue Oct 15 05:05:49.044 dbexit: really exiting now
客户端显示服务器未启动:
# mongo
MongoDB shell version: 2.4.6
connecting to: test
Tue Oct 15 05:08:22.139 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
exception: connect failed
当我以这种方式奔跑时……
# sudo service mongodb restart
...在 Mongo 日志文件中得到输出:
*********************************************************************
ERROR: dbpath (~/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
Tue Oct 15 05:10:39.311 dbexit:
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to close listening sockets...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to flush diaglog...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: going to close sockets...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: waiting for fs preallocator...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: lock for final commit...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: final commit...
Tue Oct 15 05:10:39.311 [initandlisten] shutdown: closing all files...
Tue Oct 15 05:10:39.311 [initandlisten] closeAllFiles() finished
Tue Oct 15 05:10:39.311 dbexit: really exiting now
所以无法改变dbpath
。
我的ubuntu版本:
# uname -a
Linux hostName 3.2.0-23-virtual #36-Ubuntu SMP Tue Apr 10 22:29:03 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux
答案1
我解决了这个问题:
sudo mongod --dbpath=/var/lib/mongodb
然后mongo
访问 mongodb Shell。
答案2
MongoDB 作为服务运行在哪些用户身上?
它通常是mongod
或mongodb
,而不是 root - 事实上,您通常不应该以 root 身份运行它。Ubuntudbpath
中的默认设置是,/var/lib/mongodb
因此您似乎已在配置文件中将其更改为~/mongodb/db
。
如果您这样做,~
将扩展为运行该服务的用户的主文件夹。因此,您需要创建/home/mongodb/db
或/home/mongod/db/
,而不是/root/db
,并确保它由相关用户拥有才能使用该设置。
我建议使用完整路径来消除混淆。创建一个类似/data/mongodb/db
或类似的文件夹,并确保它具有正确的所有权(请参阅这个答案有关适当设置权限的更多信息)。
答案3
根据我的经验,mongodb 对语言环境非常挑剔,我遇到了同样的问题,请尝试:
export LANGUAGE=en_US.UTF-8
export LANG=en_US.UTF-8
export LC_ALL=en_US.UTF-8
locale-gen en_US.UTF-8
sudo service mongodb restart