使用sequelpro可以很容易地连接到AWS上的远程mysql服务器,但是我在mongodb上做同样的事情很费劲。
我尝试通过命令行设置ssh隧道,如下所示:
ssh -fN -l root -i path/to/id_rsa -L 9999:host.com:27017 host.com
我也尝试用IP地址替换主机
这个想法是将端口9999上的所有mongodb连接转发到端口27101上的主机上的连接。但是当我运行命令时:
mongo --host localhost --port 9999
连接失败,我得到这个代替:
MongoDB shell version: 2.6.0
connecting to: localhost:9999/test
channel 2: open failed: connect failed: Connection timed out
channel 3: open failed: connect failed: Connection timed out
2014-05-22T14:42:01.372+0300 DBClientCursor::init call() failed
2014-05-22T14:42:01.374+0300 Error: DBClientBase::findN: transport error: localhost:9999 ns: admin.$cmd query: { whatsmyuri: 1 } at src/mongo/shell/mongo.js:148
exception: connect failed
如果我运行,则会sudo netstat -plnt
得到以下信息(按顺序显示):
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 4242/node
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1342/httpd2-prefork
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2552/sshd
tcp 0 0 0.0.0.0:25 0.0.0.0:* LISTEN 2505/master
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 11719/mongod
tcp 0 0 127.0.0.1:6379 0.0.0.0:* LISTEN 16561/redis-server
知道我在做什么错吗?
更新: 这是最终功能命令的样子(贷记给kenster):
ssh -fN -i ~/path/to/id_rsa -L 6666:localhost:27017 root@remote.server.com
该-fN
命令使该命令在后台运行
-L
似乎与ssh手册页相抵触:-L [bind_address:]port:host:hostport Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.
它明确表示这host
是远程服务器的主机..您是否将其用于本地?