“brew services restart mongodb-community”在 brew services list 下抛出错误状态。这是什么错误?

Kev*_* T. 3 homebrew mongodb

我最近完成了 Mongo 大学的 m001 基础课程,使用连接字符串连接到 Atlas 没有问题。通过实验,我搞砸了,现在我无法启动 mongo。我遵循的步骤是(从我的根目录):

  1. brew doctor --verbose

确保 Homebrew 正常运行并且没有问题。

HomeBrew 版本3.0.1

macOS : 11.1 ,

Homebrew Cask 暂存位置/usr/local/Caskroom

Homebrew Cask Taps : /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask (3823 桶)

/usr/bin/xattr

  1. brew cleanup

  2. brew update

  3. brew tap mongodb/brew Mongo 文档安装

  4. brew install mongodb-community@4.4

已下载:/Users/kevinturney/Library/Caches/Homebrew/downloads/269692f6b2d908000ecd7602021f4826947a782576c1fea760d25ece5ccbb521--mongodb-64-x4gz4

  1. brew services start mongodb-community@4.4

服务mongodb-community已经启动,用于brew services restart mongodb-community重启。

  1. brew services restart mongodb-community

==> 成功停止mongodb-community(标签:homebrew.mxcl.mongodb-community)

==> 成功启动mongodb-community(标签:homebrew.mxcl.mongodb-community)

  1. 凯文图尼 / $ brew services list

这是错误:

姓名 地位 用户 列表
mongodb-社区 错误 凯文图尼 /Users/kevinturney/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist
mysql 停止
PostgreSQL 停止
Redis 停止
未绑定 停止

我检查了进程,

MongDB大学-进程

  1. ps -ef | grep mongo

501 10770 81999 0 10:34AM ttys007 0:00.00 grep mongo

  1. ps -ef | grep mongod

501 10776 81999 0 10:34AM ttys007 0:00.00 grep mongod

  1. ps -ef | grep mongos

01 10781 81999 0 10:34AM ttys007 0:00.00 grep mongos

  1. mongo --version

MongoDB shell 版本 v4.2.2
git 版本:a0bbbff6ada159e19298d37946ac8dc4b497eadf
分配器:系统
模块:企业
构建环境:
distarch:x86_64
target_arch:x86_64

  1. mongod --version

db 版本 v4.2.2
git 版本:a0bbbff6ada159e19298d37946ac8dc4b497eadf
分配器:系统
模块:企业
构建环境:
distarch:x86_64
target_arch:x86_64

当我运行 brew services start mongodb-community它成功启动然后

mongo 这是结果:

kevinturney / $ brew services start mongodb-community

==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-community)

kevinturney / $ mongo

MongoDB shell version v4.2.2<br/>
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb<br/>
2021-02-17T11:37:32.192-0500 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, <br/>connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17<br/>
@(connect):2:6
2021-02-17T11:37:32.195-0500 F  -        [main] exception: connect failed
2021-02-17T11:37:32.195-0500 E  -        [main] exiting with code 1
Run Code Online (Sandbox Code Playgroud)

我遵循了一个非常相似的StackOverflow 问题,通过 mongo 文档,卸载,重新安装,另外,尝试了这篇很棒的帖子,我不知道接下来要尝试什么。

Sun*_*mar 5

如果您使用的是 macOS Catalina / BigSur 以上此修复程序将起作用:

转到命令行并执行这些命令,您需要使用 SUDO 否则这将不起作用。

我们首先删除文件夹mongodb,

sudo rm -rf /usr/local/var/mongodb
Run Code Online (Sandbox Code Playgroud)

然后,我们手动添加它,

cd /usr/local/var && mkdir mongodb
Run Code Online (Sandbox Code Playgroud)

现在,我们运行 brew 服务如下,请在最后提及 mongodb 版本,如下:

brew services start mongodb-community@5.0
Run Code Online (Sandbox Code Playgroud)

如果您收到以下响应,请重新启动服务,

Service `mongodb-community` already started, use `brew services restart mongodb-community` to restart.
Run Code Online (Sandbox Code Playgroud)

下面重启服务使用,请在最后提及mongodb版本:

brew services restart mongodb-community@5.0

Stopping `mongodb-community`... (might take a while)
==> Successfully stopped `mongodb-community` (label: homebrew.mxcl.mongodb-commu
==> Successfully started `mongodb-community` (label: homebrew.mxcl.mongodb-commu
Run Code Online (Sandbox Code Playgroud)

现在我们列出所有服务,使用以下命令:

brew services list
Run Code Online (Sandbox Code Playgroud)

输出:

Name              Status  User       Plist
mongodb-community started xxx         homebrew.mxcl.mongodb-community.plist
Run Code Online (Sandbox Code Playgroud)

打开您的终端并键入mongod –version以验证您的安装。

  • 这将删除任何现有数据库,问题在于数据文件夹 /usr/local/var/mongodb 的权限,可以使用 chmod 和 chown 命令修复。 (5认同)
  • 对于 M1 Mac 上的用户,请对“/opt/homebrew/var”文件夹执行此操作,而不是“/usr/local/var”。 (4认同)