mongodb - 作为服务运行时将 MongoDB 绑定(bind)到 IP 地址

标签 mongodb

我是 MongoDB 新手,请原谅我问一个基本问题,但是。

我正在 Windows PC 上运行 MongoDB(3.6,专业版)。我已成功将其添加为 Windows 服务以在启动时自动启动。

但是,它绑定(bind)到 127.0.0.1localhost

该电脑的 IP 是 192.168.1.10,我想从不同 LAN 电脑访问该服务器。

当我运行 Mongo 时,我得到:

WARNING: This server is bound to localhost. Remote systems will be unable to connect to this server. Start the server with --bind_ip to specify which IP addresses it should serve responses from, or with --bind_ip_all to bind to all interfaces. If this behavior is desired, start the server with --bind_ip 127.0.0.1 to disable this warning.

因此,我转到 Services.msc,添加 --bind_ip_all 作为参数,然后重新启动服务。但得到同样的警告。如何让我的 MongoDB 服务绑定(bind)到所有服务,或者更好的是 bind_ip = 127.0.0.1,192.168.1.10

最佳答案

我可能已经解决了这个问题,但不确定这是否是正确的方法。

  • 我删除了该服务。
  • 我重新创建了该服务,但添加了一个conf参数并提供了一个 我的配置文件的路径。

C:\Program Files\MongoDB\Server\3.6\bin>mongod --dbpath=C:\Storage\database\mongodb\data --logpath=C:\Storage\database\mongodb\logs --config "C:\Program Files\MongoDB\Server\3.6\bin\mongod.conf" --install

  • 我创建了一个配置文件:

Listen to local and LAN interfaces.

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,192.168.1.10  # Listen to local interface only, comment to listen on all interfaces.

看来我现在可以绑定(bind)到本地主机和我的 IP 地址..

关于mongodb - 作为服务运行时将 MongoDB 绑定(bind)到 IP 地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48876326/

相关文章:

javascript - 如何使用 meteorjs 和 iron 制作哈希标签 :router?

mongodb - 与 nosql 的多对多关系(mongodb 和 mongoose)

mongodb最佳实践: nesting

javascript - Meteor.js 使用 X509 证书身份验证连接到 Mongo

javascript - 如果用户存在于 mongo 上并创建用户,如何使用 nest js 抛出异常?

javascript - 使用 reduceRight 返回有条件的工作日

javascript - 如何使用参数设置 Express 路线

mongodb - 完成入口点脚本后停止容器

node.js - 如何在mongodb中组合对象数组结果

mysql - 组合 mysql mongodb