mongodb 在 Mac 上尝试 mkdir /data/db 时的只读文件系统

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/58034955/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 21:01:56  来源:igfitidea点击:

Read-only file system when attempting mkdir /data/db on Mac

mongodbmacosterminal

提问by David Pina

I am trying to create a new folder in the main directory

我正在尝试在主目录中创建一个新文件夹

Tried all kinds of examples

尝试了各种例子

sudo mkdir /data/db

sudo mkdir /data/db

sudo mkdir -p /data/db

sudo mkdir -p /data/db

I keep getting

我不断得到

mkdir: /data: Read-only file system

mkdir: /data: 只读文件系统

回答by David Pina

If you have Mac and updated to Catalina than the root folder is no longer writable.

如果您有 Mac 并更新到 Catalina,则根文件夹不再可写。

I just changed the directory somewhere else.

我只是在其他地方更改了目录。

Been using this command for now

现在一直在使用这个命令

mongod --dbpath=/Users/user/data/db

回答by Will Abule

from the official docs https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

来自官方文档https://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/

install homebrewand run the following commands

安装自制软件并运行以下命令

sudo chown -R $(whoami) $(brew --prefix)/*

sudo chown -R $(whoami) $(brew --prefix)/*

then

然后

brew tap mongodb/brew

brew tap mongodb/brew

then

然后

brew install [email protected]

brew install [email protected]

and

brew services start mongodb-community

brew services start mongodb-community

or

或者

mongod --config /usr/local/etc/mongod.conf

mongod --config /usr/local/etc/mongod.conf

then

然后

ps aux | grep -v grep | grep mongod

ps aux | grep -v grep | grep mongod

and

mongo

mongo

to verify you can run show dbsin the mongo shell

验证您可以show dbs在 mongo shell 中运行

回答by Jirik

To make a permanent change of the path of mongod dbfolder.

永久更改 mongoddb文件夹的路径。

Following these docsthey say roughly this. If mongod is started with brew services:

遵循这些文档,他们大致说了这一点。如果 mongod 是用 brew 服务启动的:

$ brew services start [email protected]

It will use config file at path /usr/local/etc/mongod.conf

它将在路径中使用配置文件 /usr/local/etc/mongod.conf



To fix this, edit the config file:

要解决此问题,请编辑配置文件:

$ vim /usr/local/etc/mongod.conf

And change the dbPathe.g. to your home directory like this:

并将dbPatheg更改为您的主目录,如下所示:

systemLog:
  destination: file
  path: /usr/local/var/log/mongodb/mongo.log
  logAppend: true
storage:
  dbPath: /Users/<username>/data/db
net:
  bindIp: 127.0.0.1 

Save the file and restart mongod with brew:

保存文件并使用 brew 重新启动 mongod:

$ brew services restart [email protected]

回答by Eugène Beliaev

With the new macOS Catalina update, the folder "/data/db"becomes read-only, you cannot modify it. Follow this procedure to create a DB in another folder:

随着新的 macOS Catalina 更新,该文件夹"/data/db"变为只读,您无法对其进行修改。按照以下步骤在另一个文件夹中创建一个数据库:

1) Change mongoddirectory :

1)更改mongod目录:

sudo mongod --dbpath /System/Volumes/Data/data/db 

2) Give it an alias :

2)给它一个别名:

alias mongod="sudo mongod --dbpath/System/Volumes/Data/data/db"

3) Just type mongodin your terminal, it should work.

3)只需输入mongod您的终端,它应该可以工作。

Extra=> If you need to give it current user rights, use this line of code :

额外=> 如果您需要为其授予当前用户权限,请使用以下代码行:

sudo chown -R $(whoami) /System/Volumes/Data/data/db

须藤 chown -R $(whoami) /System/Volumes/Data/data/db

(Just for info -> $(whoami)is just a variable that returns your current user)

(仅供参考 ->$(whoami)只是一个返回当前用户的变量)

回答by Anjum....

If you are on mac and facing the issue then below command is useful, whoamivariable will get the current user

如果您使用的是 mac 并且面临这个问题,那么下面的命令很有用, whoami变量将获取当前用户

mongod --dbpath=/Users/$(whoami)/data/db

回答by ümit ünver

With macOS Catalina, you can no longer store files or data in the read-only system volume, nor can you write to the "root" directory ( / ) from the command line, such as with Terminal.

使用 macOS Catalina,您无法再将文件或数据存储在只读系统卷中,也无法从命令行写入“根”目录 ( / ),例如使用终端。

回答by Radu S.

This is what worked for me as I was undergoing a Udemy course: 1. Install HomeBrew by typing this into your terminal

当我正在接受 Udemy 课程时,这对我有用: 1. 通过在终端中输入以下内容来安装 HomeBrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  1. Move your old /data/db folder (if you want to backup your current dbs) into a non root folder and proceed with the next step

  2. Run in Terminal a) brew uninstall mongodbb) If needed run brew uninstall --force mongodbc) brew tap mongodb/brewd) brew install mongodb-communitye) brew services start mongodb/brew/mongodb-community

  3. All you need now is to run mongo in the Terminal and you'll see the mongo shell symbol >.

  1. 将旧的 /data/db 文件夹(如果要备份当前的 dbs)移动到非根文件夹中,然后继续下一步

  2. 在终端运行 a) brew uninstall mongodbb) 如果需要运行brew uninstall --force mongodbc) brew tap mongodb/brewd) brew install mongodb-communitye)brew services start mongodb/brew/mongodb-community

  3. 您现在所需要做的就是在终端中运行 mongo,您将看到 mongo shell 符号 >。

Please let me know if this works ;) It took me almost 2 hours to figure it out, based on this article: https://apple.stackexchange.com/questions/362883/mongodb-doesnt-work-after-update-to-macos-catalina-10-15

请让我知道这是否有效;) 根据这篇文章,我花了将近 2 个小时才弄明白:https: //apple.stackexchange.com/questions/362883/mongodb-doesnt-work-after-update-to -macos-catalina-10-15

Cheers, Radu

干杯,拉杜

回答by jvarela

You cannot create a /data/directory. That is reserved for the APFS filesystem. Check Bombich'sblog about this issue.

您不能创建/data/目录。这是为 APFS 文件系统保留的。检查Bombich 的博客关于这个问题。

回答by RobKohr

Mac version Catalina made the root folder is no longer writable.

Mac 版 Catalina 使根文件夹不再可写。

Brew has an updated version of mongodb to use a new path (which it creates itself), /usr/local/var/mongodband following these instructions will fix the issue:

Brew 有一个更新版本的 mongodb 来使用一个新路径(它自己创建),/usr/local/var/mongodb按照这些说明将解决这个问题:

Guide to installing updated mongodb-community-edition

安装更新的 mongodb-community-edition 指南

brew install mongodb-community@VERSIONwhere the first VERSION with the fix is 4.2

brew install mongodb-community@VERSION带有修复的第一个版本是 4.2

回答by franfonse

I did this:

我这样做了:

mkdir -p usr/local/var/mongodb/data/db

since the new path that is "usr/local/var/mongodb".

因为新路径是“usr/local/var/mongodb”。