[英]MongoDB only works when run as root on Ubuntu - data directory issue
I installed MongoDB with the official packages (mongodb-stable), and followed the Quickstart guide which includes: 我使用官方软件包 (mongodb-stable)安装了MongoDB,并按照快速入门指南进行了操作 ,其中包括:
By default MongoDB will store data in
/data/db
, but it won't automatically create that directory.默认情况下,MongoDB会将数据存储在
/data/db
,但它不会自动创建该目录。 To create it, do:要创建它,请执行:
$ sudo mkdir -p /data/db/ $ sudo chown `id -u` /data/db
You can also tell MongoDB to use a different data directory, with the
--dbpath
option.您还可以使用
--dbpath
选项告诉MongoDB使用不同的数据目录。
MongoDB will only start if I run sudo mongod
- if I try and run just mongod
I get the error: MongoDB只会在我运行
sudo mongod
启动 - 如果我尝试运行mongod
我得到错误:
Mon Mar 14 15:27:07 [initandlisten] couldn't open /data/db/test.ns errno:13 Permission denied
Mon Mar 14 15:27:07 [initandlisten] couldn't open file /data/db/test.ns terminating
Mon Mar 14 15:27:07 dbexit:
What gives? 是什么赋予了?
You created /data/db
as root so it has those permissions. 您以root身份创建了
/data/db
,因此它具有这些权限。 You can change the permissions to your user account, or whatever you have mongo running as. 您可以更改您的用户帐户的权限,或任何您运行mongo的权限。
chown -R username /data/db
or /data
或
/data
You can also set a group 您也可以设置一个组
chown -R username.groupname
The -R
does it recursively, so it will affect all the files you've created running mongoDB as root already. -R
递归方式执行,因此它将影响您以root身份运行mongoDB的所有文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.