提问者:小点点

使用和运行brew服务时出现问题mongodb-community@4.2


我有MacOS Catalina版本10.15.5,我按照他们网站上指示的步骤安装了mongoDBhttps://docs.mongodb.com/manual/tutorial/install-mongodb-on-os-x/使用Homebrew。当我检查我的mongoDB是否正确安装时,我使用,mongo命令,我得到/usr/local/bin/mongo响应。当我使用mongo--versionmongod--version时,我得到:

MongoDB shell version v4.2.7
git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

db version v4.2.7
git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
allocator: system
modules: none
build environment:
    distarch: x86_64
    target_arch: x86_64

尊重,我认为这意味着它的正确安装,应该工作。

但是当我打开终端并运行命令brew services startmongodb-community@4.2时,我得到了:

Error: undefined method `resolve_alias' for Formula:Class
/usr/local/bin/brew-services.rb:154:in `service'
/usr/local/bin/brew-services.rb:203:in `check'
/usr/local/bin/brew-services.rb:193:in `run!'
/usr/local/bin/brew-services.rb:397:in `<top (required)>'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'
/usr/local/Homebrew/Library/Homebrew/utils.rb:81:in `require?'
/usr/local/Homebrew/Library/Homebrew/brew.rb:112:in `<main>'

注意:我的brew已成功更新和升级!

我在网上搜索了任何解决方案,但我找不到任何解决问题的方法…如果有人遇到过类似的问题,请一步一步地详细解释你是如何解决的?!?!

如果我直接运行命令mongod我得到:

2020-06-04T01:19:41.351+0200 I  CONTROL  [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-06-04T01:19:41.355+0200 W  ASIO     [main] No TransportLayer configured during NetworkInterface startup
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] MongoDB starting : pid=24712 port=27017 dbpath=/data/db 64-bit host=Air-de-Ruslan.home
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] db version v4.2.7
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] git version: 51d9fe12b5d19720e72dcd7db0f2f17dd9a19212
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] allocator: system
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] modules: none
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] build environment:
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten]     distarch: x86_64
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten]     target_arch: x86_64
2020-06-04T01:19:41.355+0200 I  CONTROL  [initandlisten] options: {}
2020-06-04T01:19:41.355+0200 E  NETWORK  [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2020-06-04T01:19:41.355+0200 F  -        [initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 684
2020-06-04T01:19:41.355+0200 F  -        [initandlisten] 

***aborting after fassert() failure

如果我直接运行命令mongo我得到:

MongoDB shell version v4.2.7
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-04T01:21:20.317+0200 E  QUERY    [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-06-04T01:21:20.320+0200 F  -        [main] exception: connect failed
2020-06-04T01:21:20.320+0200 E  -        [main] exiting with code 1

共3个答案

匿名用户

解决了

我必须用命令移除 /usr/local/bin/brew-services.rb

rm /usr/local/bin/brew-services.rb它可以请求权限,所以添加sudo rm /usr/local/bin/brew-services.rb。

之后,我尝试运行brew服务启动mongodb-community@4.2

成功地启动了mongoDB社区(标签:hombrew. mxcl.mongoDB社区,但是当我把mongo从不同的终端启动shell时,我得到了Socket异常错误,所以我也检查了mongood.log文件,我看到这是一个套接字问题,所以我尝试了

ls-ls /tmp/mongodb-27017.sock我得到了

0 srwx------ 1 root root 0 June 04 14:51 /tmp/mongodb-27017.sock这意味着所有者是root,MongoDB无法访问它,所以我这样做了

sudo rm-rf /tmp/mongodb-27017.sock

删除文件,然后用

brew服务开始mongodb-community@4.2创建新的. sock文件,其所有者直接是mongoDB或实际用户whoami,当我再次检查

lsah /tmp/mongodb-27017.sock

我证明了我是所有者,然后我可以打开新的终端并运行mongo并启用连接并使用shell!

匿名用户

在macos上测试Big Surmongodb-community@5.0.1

如果您正在使用自制软件并升级到mongodb-community@5.0,则在启动mongoDB社区服务时可能会遇到错误。

使用rm-rf /usr/local/var/mongodb删除先前的dbpath文件夹(如果存在),然后使用cd再次创建它 /usr/local/var

然后brew服务启动mongoDB社区应该可以正常工作。

匿名用户

在MacOS Big Sur(mongodb-community@5.0测试)上,以下内容总是返回错误(这意味着mongoDB社区服务将自动加载):

~ brew services start mongodb-community

mongodb-community error zaffer /Users/zaffer/Library/LaunchAgents/homebrew.mxcl.mongodb-community.plist

默认情况下,mongoDB社区配置存储在/usr/local/etc/mongood. conf

默认情况下,dbpath参数设置为/usr/local/var/mongoDB

在分析日志时,我发现问题主要与此文件夹/usr/local/var/mongoDB的权限有关

以下对我有用:

~ cd /usr/local/var/mongodb
~ sudo chown -R $(whoami) .
~ cd ..
~ sudo chown -R $(whoami) mongodb
~ brew services restart mongodb-community

如果您仍然面临问题,我建议更改此文件夹(/usr/local/var/mongoDB)所有文件的文件权限:

~ chmod -R 777 /usr/local/var/mongodb
~ brew services restart mongodb-community

或在权限被拒绝时使用sudo

~ sudo chmod -R 777 /usr/local/var/mongodb
~ brew services restart mongodb-community

如果您仍然面临问题,请使用以下方法之一将mongod作为后台进程运行时观察错误:

~ mongod
~ mongod --dbpath /usr/local/var/mongodb
~ mongod --config /usr/local/etc/mongod.conf

从mongoDB社区的较低版本升级时,您也可能会遇到问题,例如从3.6升级到5.0,在我的情况下,我倾向于保存现有数据库,否则我可以为mongoDB数据创建一个新文件夹,并更新/usr/local/etc/mongos. conf配置文件中的dbpath。

推荐的方法是进行增量升级,即从3.6升级到4.0,然后从4.0升级到4.4,然后从4.4升级到5.0。这是为了设置将数据从一个版本迁移到另一个版本的推荐兼容性版本。您可以使用(为此,您需要一个工作的mongob服务器)从mongob shell手动设置兼容性版本:

> db.adminCommand( { setFeatureCompatibilityVersion: <version> } )

文档链接:https://docs.mongodb.com/manual/reference/command/setFeatureCompatibilityVersion/