作为服务运行时将 MongoDB 绑定到 IP 地址 [英] Bind MongoDB to IP address when running as Service

查看:156
本文介绍了作为服务运行时将 MongoDB 绑定到 IP 地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 MongoDB 的新手,所以请原谅我的一个基本问题.

我在 Windows PC 上运行 MongoDB(3.6,专业版).我已设法将其添加为 Windows 服务,以便在启动时自动启动.

但是,它绑定到 127.0.0.1localhost.

那台PC上的IP是192.168.1.10,我想从不同的局域网PC访问服务器.

当我运行 Mongo 时,我得到:

<块引用>

警告:此服务器绑定到本地主机.远程系统将无法连接到此服务器.使用 --bind_ip 启动服务器指定哪个IP地址它应该提供来自或使用 --bind_ip_all 的响应绑定到所有接口.如果需要此行为,请启动使用 --bind_ip 127.0.0.1 禁用此警告的服务器.

于是我去了Services.msc,添加了--bind_ip_all作为参数,重启了服务.但得到同样的警告.我怎样才能让我的 MongoDB 服务绑定到所有,或者更好的是,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"--安装

  • 我创建了一个配置文件:
<块引用>

侦听本地和 LAN 接口.

# 个网络接口网:端口:27017bindIp: 127.0.0.1,192.168.1.10 # 只监听本地接口,注释监听所有接口.

看来我现在可以同时绑定到本地主机和我的 IP 地址..

I am new to MongoDB, so excuse me for a basic question but.

I am running MongoDB (3.6, Professional) on a Windows PC. I have managed to add it as a Windows Service to start automatically on Startup.

However, it binds to 127.0.0.1 or localhost.

The IP on that PC is 192.168.1.10 and I would like to access the server from different LAN PCs.

When I run Mongo, I get:

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.

So I went to Services.msc, and added --bind_ip_all as a parameter, and restarted the service. But get the same warning. How can I get my MongoDB service to bind to all, or better yet, bind_ip = 127.0.0.1,192.168.1.10?

解决方案

I may have resolved this, but not sure if it's the right way.

  • I removed the service.
  • I recreated the service, but added a conf parameter and provided a path to my config file.

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

  • I created a config file:

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.

It seems I can now bind to both localhost and my IP address..

这篇关于作为服务运行时将 MongoDB 绑定到 IP 地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆