【发布时间】:2019-05-31 04:29:30
【问题描述】:
我们有一个弹性搜索设置,只能从跳转框获得。我想建立一个 ssh 隧道,这样我就可以从我的笔记本电脑或 Docker 容器中查询。 当我直接或通过“系统”运行 ssh 时,隧道工作并且我的帖子获取数据。当我尝试使用 net-ssh 设置隧道时,我得到一个 RestClient::Exceptions::ReadTimeout。我不确定 net-ssh 配置中缺少什么。我提供了一个简化的代码示例。
尝试在 Windows 上使用 Cygwin 以及在运行 Centos7 的 Docker 容器中运行它。
require 'json'
require 'net/ssh'
require 'rest-client'
def fetchData
indexName = "REDACTED"
url = "http://localhost:9999/#{indexName}/_search?pretty"
body = '{"size":1, "query":{"match_all":{}}}'
resp = RestClient.post url, body, :content_type => :json, :accept => :json
return JSON.parse(resp)
end
begin
userName = 'REDACTED'
privateKey = 'id_rsa'
jumpBoxUrl = 'REDACTED.com'
elasticUrl = 'REDACTED.com'
# this works
system("ssh -fN -o StrictHostKeyChecking=no -i ~/.ssh/#{privateKey} #{userName}@#{jumpBoxUrl} -p 22 -L 9999:#{elasticUrl}:9200 sleep 10 >> logfile")
puts fetchData
# wait for the ssh to time out
sleep 5
# Timed out reading data from server (RestClient::Exceptions::ReadTimeout) - WHY?!
#
Net::SSH.start(jumpBoxUrl, userName, :port=>22, :forward_agent=>true, :verbose=>:info, :keys=>["~/.ssh/#{privateKey}"]) do |session|
session.forward.local(9999, elasticUrl, 9200)
# this works - able to authenticate to the shell box
puts session.exec!("ls -la")
# this times out - data is not returned
puts fetchData
end
end
我希望帖子在使用 net-ssh 时返回与使用 ssh 时相同的数据。
感谢我在 net-ssh 设置中缺少的任何帮助。
【问题讨论】:
标签: ruby rest-client ssh-tunnel net-ssh