Mongod身份验证使GCP VM无法访问

时间:2020-04-04 17:50:22

标签: mongodb authentication google-cloud-platform

我正在使用GCP VM运行MongoDB实例。

它很好用,关闭了身份验证,但是一旦我通过编辑将其启用为“启用” sudo vi /etc/mongod.conf,然后使用sudo service mongod restart重新启动服务。

执行完此操作并尝试使用凭据连接到我的数据库后,mongo出现以下错误:

mongo mongodb://<gcp vm statcic ip>:<mongodb static port>

导致:

connecting to: mongodb://<myservererIP>:<mongodbport>
2020-04-04T19:30:36.644+0200 E QUERY    [js] Error: couldn't connect to server
 <myservererIP>:<mongodbport>, connection attempt failed: SocketException:
 Error connecting to <myservererIP>:<mongodbport> :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed

我的VM IP是静态的,并且mongo中的帐户是根据mongoDB文档创建的,即使没有,它们也可以,我想我应该具有“需要授权”之类的东西,并且不拒绝连接或建立网络无法访问。

1 个答案:

答案 0 :(得分:0)

我实际上已经找到问题了。

/etc/mongod.conf中,我以为#security:是为了提供信息,用于文件结构化,但实际上您还必须与authentication: enable一起取消注释。

否则,mongod会将mongod.conf文件检测为损坏/错误的格式,并在没有该文件的情况下运行(可能使用默认的conf)。

我来自:

#security:
    authorization: enabled

security:
   authorization: enabled

初学者可能犯了一个非常糟糕的错误,但我会保留在这里,也许会对别人有帮助。