升级到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
不幸的是,除了苹果的 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上的说明进行操作利用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
配置文件,否则changestreams将不起作用:
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屋!