Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
909 views
in Technique[技术] by (71.8m points)

permissions - 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:

By default MongoDB will store data in /data/db, but it won't automatically create that directory. 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.

MongoDB will only start if I run sudo mongod - if I try and run just mongod I get the error:

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?

question from:https://stackoverflow.com/questions/5300861/mongodb-only-works-when-run-as-root-on-ubuntu-data-directory-issue

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You created /data/db as root so it has those permissions. You can change the permissions to your user account, or whatever you have mongo running as.

chown -R username /data/db

or /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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...