升级到 Mac OS 10.15 (Catalina) 后 MongoDB 找不到数据目录 [英] MongoDB can't find data directory after upgrading to Mac OS 10.15 (Catalina)
问题描述
我今天更新到 MacOS 10.15 (Catalina).当我在终端中运行 mongod
时,它找不到 /data/db
目录:
I updated to MacOS 10.15 (Catalina) today. When I run mongod
in the terminal it cannot find the /data/db
directory:
➜ /Users/william > mongod
2019-10-08T17:02:44.183+0800 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] MongoDB starting : pid=43162 port=27017 dbpath=/data/db 64-bit host=Williams-MacBook-Pro-6.local
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] db version v4.0.3
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] git version: 7ea530946fa7880364d88c8d8b6026bbc9ffa48c
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] allocator: system
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] modules: none
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] build environment:
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] distarch: x86_64
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] target_arch: x86_64
2019-10-08T17:02:44.209+0800 I CONTROL [initandlisten] options: {}
2019-10-08T17:02:44.211+0800 I STORAGE [initandlisten] exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
2019-10-08T17:02:44.211+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2019-10-08T17:02:44.211+0800 I NETWORK [initandlisten] removing socket file: /tmp/mongodb-27017.sock
2019-10-08T17:02:44.211+0800 I CONTROL [initandlisten] now exiting
2019-10-08T17:02:44.211+0800 I CONTROL [initandlisten] shutting down with code:100
➜ /Users/william >
我尝试使用 brew
安装 MongoDB:
I tried to install MongoDB with brew
:
brew install mongodb
➜ /Users/william > brew install mongodb
Updating Homebrew...
Error: mongodb: unknown version :mountain_lion
有什么帮助吗?
推荐答案
这是主要错误:
initAndListen 中的异常:NonExistentPath:未找到数据目录/data/db.,正在终止
exception in initAndListen: NonExistentPath: Data directory /data/db not found., terminating
Catalina 有一个令人惊讶的变化:它不允许更改根目录(这在 论坛主题):
Catalina has a surprise change: it won't allow changes to the root directory (this was discussed in a forum thread as well):
% sudo mkdir -p /data/db
mkdir: /data/db: Read-only file system
不幸的是,这在 Apple 的 Catalina 发行说明中没有明确说明,除了Catalina 功能中的简短提及:
Unfortunately, this is not spelled out explicitly in Apple's Catalina release notes, other than a brief mention in Catalina features:
macOS Catalina 在专用的只读系统卷中运行
macOS Catalina runs in a dedicated, read-only system volume
由于目录 /data/db
被编码为 MongoDB 默认,解决方法是指定一个不同的 dbpath
不在根目录中.例如:
Since the directory /data/db
is coded as MongoDB default, a workaround is to specify a different dbpath
that is not located on the root directory. For example:
mongod --dbpath ~/data/db
这会将 MongoDB 的数据放在您的主目录中.只需确保路径 ~/data/db
实际存在.
This will place MongoDB's data in your home directory. Just make sure that the path ~/data/db
actually exists.
替代方法
另一种方法是按照安装 MongoDB 中的说明进行操作macOS 上的社区版,利用 brew
:
An alternative method is to follow the instructions at Install MongoDB Community Edition on macOS by leveraging brew
:
brew tap mongodb/brew
brew install mongodb-community
这将默认创建一些额外的文件:
This will create some additional files by default:
- 配置文件(/usr/local/etc/mongod.conf)
- 日志目录路径(/usr/local/var/log/mongodb)
- 数据目录路径(/usr/local/var/mongodb)
要运行 mongod
,您可以:
从命令行手动运行命令(为方便起见,可以使用别名):
Run the command manually from the command line (this can be aliased for convenience):
mongod --config /usr/local/etc/mongod.conf
使用 brew services
将 MongoDB 作为服务运行.请注意,这会将 MongoDB 作为独立节点(而不是副本集)运行,因此依赖于 oplog 的功能,例如除非您修改 mongod
配置文件,否则更改流将无法工作:
Run MongoDB as a service using brew services
. Note that this will run MongoDB as a standalone node (not a replica set), so features that depends on the oplog e.g. changestreams will not work unless you modify the mongod
configuration file:
brew services start mongodb-community
这篇关于升级到 Mac OS 10.15 (Catalina) 后 MongoDB 找不到数据目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!