通过SSH golang连接到mongoDB

I need to connect to remote mongoDB server via ssh, i was doing this earlier with mysql and its looks like :

sshcon, err := ssh.Dial("tcp", fmt.Sprintf("%s:%d", sshHost, sshPort), sshConfig)
    if err == nil {
        defer sshcon.Close()
        mysql.RegisterDial("mysql+tcp", (&ViaSSHDialer{sshcon}).Dial)

Is there a similar function like mysql.RegisterDial in mgo package?

ssh
dongwu8653
dongwu8653 我需要挖洞
大约一年之前 回复
dpkrbe395930
dpkrbe395930 您需要隧道传输还是只是想拥有穷人版本的TLS?
大约一年之前 回复

1个回答



在您的代码中添加隧道功能确实没有意义。 一个简单的包装程序外壳脚本使您不必重新发明轮子:</ p>

 #!/ bin / bash 

ssh $ USER @ $ MONGO_HOST -L $ LOCAL_PORT:127.0.0.1:27017
./yourApplication“ $ *”
</ code> </ pre>

这样,您可以通过 像往常一样包装。</ p>
</ div>

展开原文

原文

It really does not make sense to add the tunneling function into your code. A simple wrapper shell script prevents you from the necessity to reinvent the wheel:

#!/bin/bash

ssh $USER@$MONGO_HOST -L $LOCAL_PORT:127.0.0.1:27017
./yourApplication "$*"

With this, you can call your program via the wrapper as usual.

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问