如何使用多个IP地址设置mongod.conf bind_ip [英] How to set mongod.conf bind_ip with multiple ip address

查看:1047
本文介绍了如何使用多个IP地址设置mongod.conf bind_ip的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是设置服务器环境和mongoDB的新手.这听起来很简单,但是,我真的需要您的帮助.

I am a newbie for setting up the server environment and mongoDB. This may sounds something really simple, however, I really need your help on it.

我正在尝试连接到从本地计算机运行mongodb实例的虚拟机,我相信当我在单独的远程服务器上运行该虚拟机时,该虚拟机应该与生产环境类似.

I am trying to connect to my virtual machine which runs the mongodb instance from the local machine, which I believe should be similar to the production environment when I run it on a separate remote server.

环境如下:

  • 虚拟机的专用IP: 192.168.184.155

本地计算机和虚拟机的公共IP: 96.88.169.145

Public IP for both local machine and virtual machine: 96.88.169.145


我从

更改了/etc/mongod.conf文件中的 bind_ip

bind_ip = 127.0.0.1

bind_ip = 127.0.0.1,192.168.184.155,96.88.169.145

重新启动mongod服务后,虚拟机和本地计算机都无法通过mongodb命令访问mongodb,并给我以下错误.

After I restarted the mongod service, neither the virtual machine nor the local machine can access mongodb through mongodb command and giving me the following error.

MongoDB shell version: 3.0.1
connecting to: test
2015-03-17T16:02:22.705-0400 W NETWORK  Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2015-03-17T16:02:22.707-0400 E QUERY    Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed
    at connect (src/mongo/shell/mongo.js:179:14)
    at (connect):1:6 at src/mongo/shell/mongo.js:179
exception: connect failed

但是,如果我更改

bind_ip = 192.168.184.155

并重新启动服务,它可以正常工作,我可以从本地计算机上使用mongo进行访问.似乎不适用于多个IP地址.我试图在mongodb文档中进行查找,但是,他们确实提到bind_ip带有逗号分隔的列表,这确实让我感到困惑.

and restart the service, it works and I can access using mongo from my local machine. It seems just not work with multiple ip addresses. I tried to do look up in the mongodb document, however, they does mention that bind_ip takes a comma separated list, which really confused me.

谢谢您的帮助.

推荐答案

在mongo 3.2.7中,用方括号将逗号分隔的Ips包裹起来适用于我:

Wrap the comma-separated-Ips with brackets works in mongo 3.2.7 for me:

bindIp = [127.0.0.1, 192.168.184.155, 96.88.169.145]

这篇关于如何使用多个IP地址设置mongod.conf bind_ip的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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