0%

macOS brew安装mongo遇见的一些坑和报错

brew 安装mongo

  • brew 安装mongo 遇见的一些坑和报错

    1. WiredTiger Permission denied

    2. Found an invalid featureCompatibilityVersion document

    3. Data directory /data/db not found., terminating

  • 从2019年9月2日开始 ,HomeBrew 也从核心仓库 (#43770) 当中移除了mongodb 模块 ,MongoDB 已经宣布不再开源;
  • 若果想继续使用 brew install mongodb,MongoDB 官方提供了一个单独的 HomeBrew 的社区版本安装:https://github.com/mongodb/homebrew-brew

开始安装

  • brew tap mongodb/brew
    很遗憾brew tap 的源无法加速,是从 mongodb.org 官方下载的安装包,等待一会吧

  • brew install mongodb-community@4.2

  • brew tap mongodb/brew

  • 配置文件:/usr/local/etc/mongod.conf

  • 日志目录路径:/usr/local/var/log/mongodb

  • 数据目录路径:/usr/local/var/mongodb

启动mongo

  • brew services start mongodb-community@4.2

  • brew services stop mongodb-community@4.2

  • brew services restart mongodb-community@4.2

报错 1

1
wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
1
2
3
4
5
6
7
8
9
10
11
2020-04-13T14:20:17.647+0800 I  STORAGE  [initandlisten] Detected data files in /usr/local/var/mongodb created by the 'wiredTiger' storage engine, so setting the active storage engine to 'wiredTiger'.
2020-04-13T14:20:17.647+0800 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=7680M,cache_overflow=(file_max=0M),session_max=33000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000,close_scan_interval=10,close_handle_minimum=250),statistics_log=(wait=0),verbose=[recovery_progress,checkpoint_progress],
2020-04-13T14:20:18.200+0800 E STORAGE [initandlisten] WiredTiger error (13) [1586758818:200112][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied Raw: [1586758818:200112][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
2020-04-13T14:20:18.200+0800 E STORAGE [initandlisten] WiredTiger error (13) [1586758818:200395][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied Raw: [1586758818:200395][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
2020-04-13T14:20:18.200+0800 E STORAGE [initandlisten] WiredTiger error (13) [1586758818:200599][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied Raw: [1586758818:200599][27741:0x109869dc0], wiredtiger_open: __posix_open_file, 667: /usr/local/var/mongodb/WiredTiger.turtle: handle-open: open: Permission denied
2020-04-13T14:20:18.200+0800 W STORAGE [initandlisten] Failed to start up WiredTiger under any compatibility version.
2020-04-13T14:20:18.200+0800 F STORAGE [initandlisten] Reason: 13: Permission denied
2020-04-13T14:20:18.200+0800 F - [initandlisten] Fatal Assertion 28595 at src/mongo/db/storage/wiredtiger/wiredtiger_kv_engine.cpp 860
2020-04-13T14:20:18.200+0800 F - [initandlisten]

***aborting after fassert() failure

将数据目录路径/usr/local/var/mongodb目录赋值权限777sudo chmod -R 777 /usr/local/var/mongodb

ddd

报错 2

1
Found an invalid featureCompatibilityVersion document   If the current featureCompatibilityVersion is below 4.0, see the documentation on upgrading at http://dochub.mongodb.org/core/4.0-upgrade-fcv.
1
2
2020-04-13T15:16:24.375+0800 F  CONTROL  [initandlisten] ** IMPORTANT: UPGRADE PROBLEM: Found an invalid featureCompatibilityVersion document (ERROR: BadValue: Invalid value for version, found 3.6, expected '4.2' or '4.0'. Contents of featureCompatibilityVersion document in admin.system.version: { _id: "featureCompatibilityVersion", version: "3.6" }. See http://dochub.mongodb.org/core/4.0-feature-compatibility.). If the current featureCompatibilityVersion is below 4.0, see the documentation on upgrading at http://dochub.mongodb.org/core/4.0-upgrade-fcv.
2020-04-13T15:16:24.375+0800 I NETWORK [initandlisten] shutdown: going to close listening sockets...

在这里插入图片描述

只需将数据目录路径/usr/local/var/mongodb里面内容清空在重新启动mongo即可

其他错误

  1. 以mongod 启动,报错/data/db文件夹不存在

    1
    2
    2020-04-13T15:16:24.375+0800 F STORAGE  [initandlisten] exception in initAndListen: 29 Data directory /data/db not found., terminating

    原因是:macOS 10.15版本不能创建/data/db

    1
    2
    sudo mkdir -p /data/db
    mkdir: /data/db: Read-only file system
  2. 可以mongod指定数据目录启动mongod --dbpath '/Users/neo/data/db'

  3. 可以编辑配置文件vim ~/.zshrc
    在末尾添加以下内容,以后使用mongod启动

    1
    alias mongod="mongod --dbpath '/Users/neo/data/db'"

欢迎关注我的其它发布渠道