简体   繁体   English

如何通过 ssh 隧道将数据保存到远程 mongoDB? (拒绝连接)

[英]How to save data to remote mongoDB via ssh tunnel? (connection refused)

I have two computers: Ubuntu1 and Ubuntu2.我有两台电脑:Ubuntu1 和 Ubuntu2。 Ubuntu1 runs MongoDB with database Sacred3. Ubuntu1 使用数据库 Sacred3 运行 MongoDB。 I want to connect from U2 to U1 via ssh and store there my experiment results.我想通过 ssh 从 U2 连接到 U1 并将我的实验结果存储在那里。

What I tried and failed: 1. I installed mongo DB, created sacred3, I have ssh key to it.我尝试过但失败了: 1. 我安装了 mongo DB,创建了神圣3,我有 ssh 密钥。 I edited /etc/mongod.conf adding:我编辑了/etc/mongod.conf添加:

# network interfaces net: port: 27017 bindIp: 0.0.0.0

Then I enabled port forwarding with然后我启用了端口转发

ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:localhost:27017 ubuntu@106.969.696.969 // (with proper ip) ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:localhost:27017 ubuntu@106.969.696.969 //(使用正确的 ip)

so, as I undertstand, if I connect to my localhost:6666 it will be forwarded to 106.969.696.969:27017所以,据我所知,如果我连接到我的 localhost:6666 它将被转发到 106.969.696.969:27017

So after that, I'm runnig an experiment with Sacred framework :因此,在那之后,我正在使用Sacred 框架进行实验:

python exp1.py -m localhost:6666:sacred3 python exp1.py -m localhost:6666:sacred3

and this should write experiment to remote DB, HOWEVER i I get:这应该将实验写入远程数据库,但是我得到:

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

which is driving me mad.这让我发疯。 please help!请帮忙!

# #

below contents of exp1.py: exp1.py 的以下内容:

 from sacred import Experiment from sacred.observers import MongoObserver ex = Experiment() ex.observers.append(MongoObserver.create()) def compute(): summ = layer1 - layer2 return summ @ex.config def my_config(): hp_list = [{"neurons": [32,32], "dropout": 1.0}, {"neurons": [32,32], "dropout": 0.7}, {"neurons": [32,16], "dropout": 0.9}, {"neurons": [24,16], "dropout": 0.9}, {"neurons": [24,8], "dropout": 0.9}, {"neurons": [16,8], "dropout": 0.9}, {"neurons": [64,64], "dropout": 0.9}, {"neurons": [64,64], "dropout": 0.7}, {"neurons": [64,32], "dropout": 0.9}, {"neurons": [64,32], "dropout": 0.7}, {"neurons": [48,32], "dropout": 0.9}, {"neurons": [48,32], "dropout": 0.7}, {"neurons": [48,16], "dropout": 0.9}, {"neurons": [48,16], "dropout": 0.7},] n_epochs = 2 @ex.capture def training_loop(hp_list, n_epochs): for j in hp_list: print("Epoch: ", n_epochs) # layer1 = random.randint(18,68) # layer2 = random.randint(18,68) # layer3 = random.randint(18,68) layer1 = j["neurons"][0] layer2 = j["neurons"][1] dropout_ratio = j["dropout"] print("WHATS UUUUUP",j, layer1, layer2, dropout_ratio, sep="_") # vae_training_loop_NN_DO(i, layer1, layer2, dropout_ratio ) @ex.automain def my_main(): training_loop()

According to the documentation supplied , it looks like you're creating two observers, or overriding the connection argument you passed with -m , with the MongoObserver.create() specified in the code which uses the default mongo host and port localhost:27017 .根据提供的文档,看起来您正在创建两个观察者,或者覆盖您使用-m传递的连接参数,并在使用默认 mongo 主机和端口localhost:27017的代码中指定了MongoObserver.create() You either supply the observer connection via the -m argument or in code, not both.您可以通过-m参数或在代码中提供观察者连接,而不是两者都提供。

Try removing the MongoObserver.create() line altogether, or hardcoding the connection arguments: MongoObserver(url='localhost:6666', db_name='sacred3')尝试完全删除MongoObserver.create()行,或硬编码连接 arguments: MongoObserver(url='localhost:6666', db_name='sacred3')

Also, it looks like your mongo host is not liking the binding to localhost so you should also replace localhost in your ssh command with 127.0.0.1 or [::1] , eg ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:127.0.0.1:27017 ubuntu@106.969.696.969 or ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:[::1]:27017 ubuntu@106.969.696.969此外,看起来您的 mongo 主机不喜欢绑定到 localhost ,因此您还应该将 ssh 命令中的localhost替换为127.0.0.1[::1] ,例如ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:127.0.0.1:27017 ubuntu@106.969.696.969ssh -fN -i ~/.ssh/sacred_key-pair.pem -L 6666:[::1]:27017 ubuntu@106.969.696.969

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM