我已经在Tomcat容器中向Jelastic部署了一个简单的Clojure Web应用程序。 Clojure应用程序在端口7001上启动REPL。我已设置并运行Jelastic SSH Gate。我通过在本地计算机上的终端(其中XXX是数字)中运行该命令,通过端口转发将SSH连入tomcat节点:
ssh -L 7001:localhost:7001 XXXXX-XXXX@gate.paas.massivegrid.com -p 3022 -N -vv
然后在我运行的本地计算机上
lein repl :connect 7001
在本地计算机上,我看到:
Connecting to nREPL at 127.0.0.1:7001
ConnectException Connection refused (Connection refused)
我在tomcat节点终端窗口上看到
debug1: Connection to port 7001 forwarding to localhost port 7001 requested.
debug2: fd 10 setting TCP_NODELAY
debug1: channel 2: new [direct-tcpip]
channel 2: open failed: connect failed: Connection refused
debug2: channel 2: zombie
debug2: channel 2: garbage collecting
debug1: channel 2: free: direct-tcpip: listening port 7001 for localhost port 7001, connect from 127.0.0.1 port 57311 to 127.0.0.1 port 7001, nchannels 3
我在做什么错?这与Jelastic管理港口的方式有关吗?
====================
问题出在应用程序上。
作为参考,这是检查端口转发在Jelastic上是否起作用的方法。 Jelastic节点未安装netcat,因此您不能仅运行netcat -l 7001
。但是,它确实安装了perl,因此您可以编写一个perl脚本来创建侦听器套接字,然后在Jelastic服务器上运行该脚本:
(编辑2019_04_06:不用下面的perl脚本,只需使用python -m SimpleHTTPServer 7001
-查看注释)
use IO::Socket::INET;
# auto-flush on socket
$| = 1;
# creating a listening socket
my $socket = new IO::Socket::INET (
LocalHost => '0.0.0.0',
LocalPort => '7001',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);
die "cannot create socket $!\n" unless $socket;
print "server waiting for client connection on port 7777\n";
while(1)
{
# waiting for a new client connection
my $client_socket = $socket->accept();
# get information about a newly connected client
my $client_address = $client_socket->peerhost();
my $client_port = $client_socket->peerport();
print "connection from $client_address:$client_port\n";
# read up to 1024 characters from the connected client
my $data = "";
$client_socket->recv($data, 1024);
print "received data: $data\n";
# write response data to the connected client
$data = "ok";
$client_socket->send($data);
# notify client that response has been sent
shutdown($client_socket, 1);
}
$socket->close();
(here中的脚本)。
使用nano将上述内容写入Jelastic节点上的脚本listener.pl中,然后在该节点上运行perl listener.pl
。
在您的本地计算机上运行
ssh -L 7001:localhost:7001 XXXXX-XXXX@gate.paas.massivegrid.com -p 3022
然后在本地计算机上尝试curl localhost:7001
,在Jelastic节点的终端中,您应该看到类似
received data: GET / HTTP/1.1
Host: localhost:7777
User-Agent: curl/7.54.0
Accept: */*