简体   繁体   English

MongoDB仅在Ubuntu上以root身份运行时才起作用 - 数据目录问题

[英]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.

相关问题 Ubuntu全局变量仅适用于root用户 - Ubuntu global variable works only for root mongodb数据目录怎么改成ubuntu - How to change mongodb data directory ubuntu MongoDB,不是root用户的Ubuntu用户,并将PID文件存储在/ var / run / mongodb中 - MongoDB, an Ubuntu user other than root, and storing the PID file in /var/run/mongodb echo -e在ubuntu上由root运行在脚本中时的行为不同 - echo -e acts differently when run in a script by root on ubuntu Ubuntu:使用root用户运行upstart服务时,它将返回未知作业 - Ubuntu: When upstart service is run with user root, it returns Unknown job Linux Ubuntu目录根目录? 家? - Linux Ubuntu directory root? home? MySql在Ubuntu根目录下安装问题 - MySql Install on Ubuntu root issue 更改 docker 数据目录的数据根后,Docker 覆盖/容器在 Ubuntu 文件的管理器中可见 - Docker overlays/containers are visible in Ubuntu file's manager after changing data-root of docker data directory 如何在Ubuntu 10.04的“ root-directory / cgi-bin”中的“ root-directory / sub-directory / cgi-bin”中设置服务器以运行perl脚本? - How to set server to run the perl script in “root-directory/sub-directory/cgi-bin” from “root-directory/cgi-bin” in Ubuntu 10.04? mongodb 问题安装在 ubuntu 20.04 - issue with mongodb install on ubuntu 20.04
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM