我正在尝试在我的服务器 Centos 5.6 上构建一个 mongo 副本集,该副本集将由装有 Ubuntu 8.10 和 mongodb 的 5 VB 设置。主要问题是我无法连接到虚拟机上的 mongo。
网络是通过带有转发端口的 NAT 设置的。
我有 Ubuntu 8.1 的镜像。下面是我创建框的方式
VBoxManage createvm --name "mongovb_03" --ostype Ubuntu --register
VBoxManage modifyvm "mongovb_03" --memory 2048 --acpi on --boot1 dvd --nic1 nat
VBoxManage modifyvm "mongovb_03" --pae on --cpus 2
VBoxManage storagectl "mongovb_03" --name "SATA Controller" --add sata --controller IntelAhci
VBoxManage storageattach "mongovb_03" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "ubuntu_8.vdi"
然后我使用 vboxtool 转发端口。
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2003-2812/GuestPort, Value: 2812
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2003-2812/HostPort, Value: 2003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2003-2812/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2023-22/GuestPort, Value: 22
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2023-22/HostPort, Value: 2023
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-2023-22/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-27003-27017/GuestPort, Value: 27017
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-27003-27017/HostPort, Value: 27003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-27003-27017/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-28003-28017/GuestPort, Value: 28017
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-28003-28017/HostPort, Value: 28003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-28003-28017/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-8083-80/GuestPort, Value: 80
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-8083-80/HostPort, Value: 8083
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-tcp-8083-80/Protocol, Value: TCP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2003-2812/GuestPort, Value: 2812
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2003-2812/HostPort, Value: 2003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2003-2812/Protocol, Value: UDP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2023-22/GuestPort, Value: 22
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2023-22/HostPort, Value: 2023
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-2023-22/Protocol, Value: UDP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-27003-27017/GuestPort, Value: 27017
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-27003-27017/HostPort, Value: 27003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-27003-27017/Protocol, Value: UDP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-28003-28017/GuestPort, Value: 28017
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-28003-28017/HostPort, Value: 28003
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-28003-28017/Protocol, Value: UDP
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-8083-80/GuestPort, Value: 80
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-8083-80/HostPort, Value: 8083
Key: VBoxInternal/Devices/e1000/0/LUN#0/Config/vboxtool-udp-8083-80/Protocol, Value: UDP
现在我可以通过 ssh 访问我的 vbox,如下所示:
ssh -p 2023 localhost
我也可以访问我的 Apache本地主机:8083或吟诵http://本地主机:8083/munin/index.html
问题是我无法访问 mongo。
我的 mongo.conf
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
port=27017
journal=true
bind_ip=127.0.0.1
因此,当我尝试连接到 mongo 时,我得到:
mongo 127:0.0.1:27003
MongoDB shell version: 1.8.1
connecting to: 127:0.0.1:27003/test
Wed Sep 21 14:33:31 getaddrinfo("127:0.0.1") failed: nodename nor servname provided, or not known
Wed Sep 21 14:33:31 Error shell/mongo.js:81
exception: connect failed
或者:
mongo localhost:27003
MongoDB shell version: 1.8.1
connecting to: localhost:27003/test
Wed Sep 21 14:34:04 DBClientCursor::init call() failed
Wed Sep 21 14:34:04 terminate() called in shell, printing stack:
0x2947 0x960d717a 0x960d71ba 0x960d72b8 0xbd752 0xe651d 0xf0777 0x2c9a0 0x14b0e4 0x1c960f 0x1cae2b 0x1d4e93 0x1c9fe5 0x18b379 0x18b2d0 0x18b1da 0x15598f 0x214da 0x13b979 0x9b82
0 mongo 0x00002947 _Z11myterminatev + 103
1 libstdc++.6.dylib 0x960d717a _ZN10__cxxabiv111__terminateEPFvvE + 10
2 libstdc++.6.dylib 0x960d71ba _ZN10__cxxabiv112__unexpectedEPFvvE + 0
3 libstdc++.6.dylib 0x960d72b8 _ZL23__gxx_exception_cleanup19_Unwind_Reason_CodeP17_Unwind_Exception + 0
4 mongo 0x000bd752 _ZN5mongo9uassertedEiPKc + 210
5 mongo 0x000e651d _ZN5mongo17DBClientInterface7findOneERKSsRKNS_5QueryEPKNS_7BSONObjEi + 1325
6 mongo 0x000f0777 _ZN5mongo20DBClientWithCommands10runCommandERKSsRKNS_7BSONObjERS3_i + 119
7 mongo 0x0002c9a0 _ZN5mongo10shellUtils9onConnectERNS_20DBClientWithCommandsE + 496
8 mongo 0x0014b0e4 _ZN5mongo26mongo_external_constructorEP9JSContextP8JSObjectjPlS4_ + 388
9 mongo 0x001c960f js_Invoke + 3275
10 mongo 0x001cae2b js_InvokeConstructor + 702
11 mongo 0x001d4e93 js_Interpret + 40685
12 mongo 0x001c9fe5 js_Execute + 774
13 mongo 0x0018b379 JS_EvaluateUCScriptForPrincipals + 167
14 mongo 0x0018b2d0 JS_EvaluateUCScript + 67
15 mongo 0x0018b1da JS_EvaluateScript + 108
16 mongo 0x0015598f _ZN5mongo7SMScope4execERKNS_10StringDataERKSsbbbi + 511
17 mongo 0x000214da _ZN5mongo10shellUtils9initScopeERNS_5ScopeE + 282
18 mongo 0x0013b979 _ZN5mongo12ScriptEngine8newScopeEv + 41
19 mongo 0x00009b82 _Z5_mainiPPc + 4850
这是我的虚拟盒上的 mongo 登录:
cat mongodb.log
Wed Sep 21 14:12:51 [initandlisten] MongoDB starting : pid=5033 port=27017 dbpath=/var/lib/mongodb 64-bit
Wed Sep 21 14:12:51 [initandlisten] db version v1.8.3, pdfile version 4.5
Wed Sep 21 14:12:51 [initandlisten] git version: c206d77e94bc3b65c76681df5a6b605f68a2de05
Wed Sep 21 14:12:51 [initandlisten] build sys info: Linux bs-linux64.10gen.cc 2.6.21.7-2.ec2.v1.2.fc8xen #1 SMP Fri Nov 20 17:48:28 EST 2009 x86_64 BOOST_LIB_VERSION=1_41
Wed Sep 21 14:12:51 [initandlisten] journal dir=/var/lib/mongodb/journal
Wed Sep 21 14:12:51 [initandlisten] recover : no journal files present, no recovery needed
Wed Sep 21 14:12:51 [initandlisten] waiting for connections on port 27017
Wed Sep 21 14:12:51 [websvr] web admin interface listening on port 28017
Wed Sep 21 14:13:51 [dur] lsn set 59540
Wed Sep 21 14:14:51 [dur] lsn set 119480
Wed Sep 21 14:15:45 [initandlisten] connection accepted from 127.0.0.1:48081 #1
Wed Sep 21 14:15:45 [conn1] end connection 127.0.0.1:48081
Wed Sep 21 14:15:51 [dur] lsn set 179021
Wed Sep 21 14:16:51 [dur] lsn set 238991
Wed Sep 21 14:17:02 [initandlisten] connection accepted from 127.0.0.1:48082 #2
Wed Sep 21 14:17:08 [conn2] end connection 127.0.0.1:48082
Wed Sep 21 14:17:51 [dur] lsn set 298802
Wed Sep 21 14:18:45 [initandlisten] connection accepted from 127.0.0.1:55467 #3
Wed Sep 21 14:18:45 [conn3] end connection 127.0.0.1:55467
Wed Sep 21 14:18:51 [dur] lsn set 358133
Wed Sep 21 14:19:51 [dur] lsn set 418033
Wed Sep 21 14:20:51 [dur] lsn set 477573
Wed Sep 21 14:21:45 [initandlisten] connection accepted from 127.0.0.1:55478 #4
Wed Sep 21 14:21:45 [conn4] end connection 127.0.0.1:55478
Wed Sep 21 14:21:51 [dur] lsn set 537524
Wed Sep 21 14:22:51 [dur] lsn set 597514
Wed Sep 21 14:23:51 [dur] lsn set 657484
Wed Sep 21 14:24:45 [initandlisten] connection accepted from 127.0.0.1:53699 #5
Wed Sep 21 14:24:45 [conn5] end connection 127.0.0.1:53699
Wed Sep 21 14:24:51 [dur] lsn set 717465
Wed Sep 21 14:25:51 [dur] lsn set 777015
Wed Sep 21 14:26:51 [dur] lsn set 836945
Wed Sep 21 14:27:45 [initandlisten] connection accepted from 127.0.0.1:53710 #6
Wed Sep 21 14:27:45 [conn6] end connection 127.0.0.1:53710
Wed Sep 21 14:27:51 [dur] lsn set 896856
Wed Sep 21 14:28:51 [dur] lsn set 956696
Wed Sep 21 14:29:51 [dur] lsn set 1016546
Wed Sep 21 14:30:45 [initandlisten] connection accepted from 127.0.0.1:42644 #7
Wed Sep 21 14:30:45 [conn7] end connection 127.0.0.1:42644
Wed Sep 21 14:30:51 [dur] lsn set 1075887
Wed Sep 21 14:31:51 [dur] lsn set 1135717
Wed Sep 21 14:32:51 [dur] lsn set 1195657
Wed Sep 21 14:33:45 [initandlisten] connection accepted from 127.0.0.1:51476 #8
Wed Sep 21 14:33:45 [conn8] end connection 127.0.0.1:51476
Wed Sep 21 14:33:51 [dur] lsn set 1255638
Wed Sep 21 14:34:51 [dur] lsn set 1315568
Wed Sep 21 14:35:51 [dur] lsn set 1375048
Wed Sep 21 14:36:45 [initandlisten] connection accepted from 127.0.0.1:51487 #9
Wed Sep 21 14:36:45 [conn9] end connection 127.0.0.1:51487
Wed Sep 21 14:36:51 [dur] lsn set 1435019
Wed Sep 21 14:37:51 [dur] lsn set 1495029
Wed Sep 21 14:38:51 [dur] lsn set 1555019
Wed Sep 21 14:39:45 [initandlisten] connection accepted from 127.0.0.1:46313 #10
Wed Sep 21 14:39:45 [conn10] end connection 127.0.0.1:46313
Wed Sep 21 14:39:51 [dur] lsn set 1614990
Wed Sep 21 14:40:51 [dur] lsn set 1674480
Wed Sep 21 14:41:51 [dur] lsn set 1734470
Wed Sep 21 14:42:45 [initandlisten] connection accepted from 127.0.0.1:46324 #11
Wed Sep 21 14:42:45 [conn11] end connection 127.0.0.1:46324
Wed Sep 21 14:42:51 [dur] lsn set 1794451
谢谢大家的帮助,我真的被困在这里了。
马立克·B
答案1
检查你的 mongodb.conf(在 ubuntu 上:/etc/mongodb.conf,不确定在 CentOS 上在哪里)并查看:
bind_ip = 127.0.0.1
如果是,请用“#”注释该行:
#bind_ip = 127.0.0.1
请注意,这可能会产生安全影响。
答案2
我不确定问题是什么,但这确实引起了我的注意
getaddrinfo("127:0.0.1")
那不应该是 127.0.0.1 吗?