无法使用机器ip连接到mongodb [英] Cannot connect to mongodb using machine ip

查看:589
本文介绍了无法使用机器ip连接到mongodb的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用homebrew安装了Mongo.如果在外壳上键入mongo,它将连接到test.但是当我键入本地计算机的ip address而不是127.0.0.1

Installed Mongo using homebrew. If I type mongo on shell, it gets connected to test. But when I type the ip address of the local machine instead of 127.0.0.1

mongo --host 192.168.1.100 --verbose

它给我错误信息

MongoDB shell version: 2.4.6
Fri Aug 23 15:18:27.552 versionArrayTest passed
connecting to: 192.168.1.100:27017/test
Fri Aug 23 15:18:27.579 creating new connection to:192.168.1.100:27017 
Fri Aug 23 15:18:27.579 BackgroundJob starting: ConnectBG
Fri Aug 23 15:18:27.580 Error: couldn't connect to server 192.168.1.100:27017 at src/mongo/shell/mongo.js:147
Fri Aug 23 15:18:27.580 User Assertion: 12513:connect failed

尝试通过注释bind_ip或将IP地址从127.0.0.1更改为0.0.0.0来修改mongo.conf,但是没有运气.这应该很简单,但现在没有任何线索.使用Mac.

Have tried modifying the mongo.conf by commenting bind_ip or by changing the ip address from 127.0.0.1 to 0.0.0.0 but no luck. This should be simple but have no clue now. Using mac.

谢谢

更新:根据要求.我按照您的建议进行更改后,此方法才能起作用.

Update: As requested. This works after I have made the changes as you suggested.

ifconfig输出

ifconfig output

lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
   options=3<RXCSUM,TXCSUM>
   inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1 
   inet 127.0.0.1 netmask 0xff000000 
   inet6 ::1 prefixlen 128 
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
   options=b<RXCSUM,TXCSUM,VLAN_HWTAGGING>
   ether XX:XX:XX:
   media: autoselect (none)
   status: inactive
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
   ether XX:XX:XX:XX:01 
   inet6 XXXX:XXXX:XXXX: %en1 prefixlen 64 scopeid 0x5 
   inet 192.168.1.100 netmask 0xffffff00 broadcast 192.168.1.255
   media: autoselect
   status: active
 p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
   ether XX:XX:XX:XX:XX
   media: autoselect
   status: inactive
 fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
   lladdr XX:XX:XX:XX
   media: autoselect <full-duplex>
   status: inactive

执行命令mongo --host 192.168.1.100 --verbose

MongoDB shell version: 2.4.5
Fri Aug 23 16:42:09.806 versionArrayTest passed
connecting to: 192.168.1.100:27017/test
Fri Aug 23 16:42:09.837 creating new connection to:192.168.1.100:27017
Fri Aug 23 16:42:09.837 BackgroundJob starting: ConnectBG
Fri Aug 23 16:42:10.129 connected connection!
Server has startup warnings: 
Fri Aug 23 16:41:59.025 [initandlisten] 
Fri Aug 23 16:41:59.025 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000

文件mongod.conf

# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb

# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true

# Only accept local connections
bind_ip = 0.0.0.0`

推荐答案

我刚刚在Mac上使用Homebrew对它进行了测试,如果您更改绑定地址, 效果很好.我怀疑您可能只是没有获得正确的绑定配置?

I just tested this on my Mac with Homebrew, works fine if you change the bind address. I suspect you probably just didn't get the config for bind correct?

就这样,我们掌握了所有信息,您能粘贴ifconfig的输出吗?

Just so we have all the information, can you paste the output of ifconfig please?

默认情况下,MongoDB应该在所有接口上侦听,您不需要更改配置,但是Homebrew设置似乎会覆盖此设置(/usr/local/etc/mongod.conf):

By default, MongoDB should listen on all interfaces, you shouldn't need to change the configuration, however, the Homebrew setup seems to override this (/usr/local/etc/mongod.conf):

# Only accept local connections
bind_ip = 127.0.0.1

请杀死MongoDB并运行它(注意-v):

Please kill MongoDB and run this (note the -v):

$ mongod --bind_ip 0.0.0.0 -v
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
all output going to: /usr/local/var/log/mongodb/mongo.log

请仅粘贴您的输出内容?

Just paste your output for that please?

然后尝试:

$ mongo --host 192.168.43.2 --verbose
MongoDB shell version: 2.4.6
Sat Aug 24 09:07:14.556 versionArrayTest passed
connecting to: 192.168.43.2:27017/test
Sat Aug 24 09:07:14.657 creating new connection to:192.168.43.2:27017
Sat Aug 24 09:07:14.657 BackgroundJob starting: ConnectBG
Sat Aug 24 09:07:14.657 connected connection!
Server has startup warnings: 
Sat Aug 24 09:06:44.360 [initandlisten] 
Sat Aug 24 09:06:44.360 [initandlisten] ** WARNING: soft rlimits too low. Number of files     is 256, should be at least 1000
> 

显然用您的IP地址替换了它.让我们知道怎么回事.

Obviously replace it with your IP address. Let us know how that goes.

这篇关于无法使用机器ip连接到mongodb的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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