How to use JProfiler over two-hop SSH tunnel

2019-05-21 06:30发布

I'm trying to connect JProfiler to a JVM running on a server that I'll call remote. This server is only accessible from my workstation (local) via another server that I'll call middle. My plan for connecting JProfiler to remote was this:

  1. Install the JProfiler instrumentation on remote

  2. Establish SSH tunnel from local, through middle, to remote:

    ssh -v -N -L 8849:[remote's private address (192.168... etc)]:8849 [middle]

  3. Establish a new JProfiler session on localhost:8849, choosing "Startup immediately, connect later with JProfiler GUI"

However, I end up getting an error:

Connection error

Either an old version of the native library is used or another application is listening on port 8849. Please check your DYLD_LIBRARY_PATH environment variable and your port configuration

I don't have any other programs bound to local port 8849, aside from my SSH tunnel, and I have confirmed that the SSH tunnel itself should be working correctly - I'm able to forward connections for a test HTTP server from remote to local via a similarly configured tunnel.

I found this similar question, but no solution was provided.

What am I missing from my configuration?

1条回答
时光不老,我们不散
2楼-- · 2019-05-21 07:14

A direct tunnel is established with

ssh -t user@remote -L [localPort]:localhost:[remotePort] -N

A 2-hop tunnel is built with chained ssh commands:

ssh -t user@middle -L [localPort]:localhost:[remotePort] \
ssh -t user@remote -L [remotePort]:localhost:[remotePort] -N

where localPort is the port you want to use locally, and remotePort is the port that the profiling agent is listening on. All of this is executed in a single command on your local machine. More hops can be added with additional ssh calls like in the first line. There must by exactly one trailing -N for the entire command.

This approach works with JProfiler.

If the tunnels fails or if the profiling agent is not listening, you will get the message that you mentioned because of the way that the connection fails in the case of an SSH tunnel.

查看更多
登录 后发表回答