代理的代码在这里
/**
* CustomAgent.java
* https://blogs.oracle.com/jmxetc/entry/connecting_through_firewall_using_jmx
*/
package example.rmi.agent;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import java.net.InetAddress;
import java.rmi.registry.LocateRegistry;
import java.util.HashMap;
import javax.management.MBeanServer;
import javax.management.remote.JMXConnectorServer;
import javax.management.remote.JMXConnectorServerFactory;
import javax.management.remote.JMXServiceURL;
/**
* This CustomAgent will start an RMI COnnector Server using only
* port "example.rmi.agent.port".
*
* @author dfuchs
*/
public class CustomAgent {
private CustomAgent() { }
public static void premain(String agentArgs)
throws IOException {
// Ensure cryptographically strong random number generator used
// to choose the object number - see java.rmi.server.ObjID
//
System.setProperty("java.rmi.server.randomIDs", "true");
// Start an RMI registry on port specified by example.rmi.agent.port
// (default 3000).
//
final int port= Integer.parseInt(
System.getProperty("example.rmi.agent.port","3000"));
System.out.println("Create RMI registry on port "+port);
LocateRegistry.createRegistry(port);
// Retrieve the PlatformMBeanServer.
//
System.out.println("Get the platform's MBean server");
MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
// Environment map.
//
System.out.println("Initialize the environment map");
HashMap<String,Object> env = new HashMap<String,Object>();
// This where we would enable security - left out of this
// for the sake of the example....
//
// Create an RMI connector server.
//
// As specified in the JMXServiceURL the RMIServer stub will be
// registered in the RMI registry running in the local host on
// port 3000 with the name "jmxrmi". This is the same name the
// out-of-the-box management agent uses to register the RMIServer
// stub too.
//
// The port specified in "service:jmx:rmi://"+hostname+":"+port
// is the second port, where RMI connection objects will be exported.
// Here we use the same port as that we choose for the RMI registry.
// The port for the RMI registry is specified in the second part
// of the URL, in "rmi://"+hostname+":"+port
//
System.out.println("Create an RMI connector server");
final String hostname = InetAddress.getLocalHost().getHostName();
//JMXServiceURL url =
// new JMXServiceURL("service:jmx:rmi://"+hostname+
// ":"+port+"/jndi/rmi://"+hostname+":"+port+"/jmxrmi");
//Added to allow connection through a firewall
// We use (port+1) to export the RMI connection objects
JMXServiceURL url =
new JMXServiceURL("service:jmx:rmi://"+hostname+
":"+(port+1)+"/jndi/rmi://"+hostname+":"+port+"/jmxrmi");
// Now create the server from the JMXServiceURL
//
JMXConnectorServer cs =
JMXConnectorServerFactory.newJMXConnectorServer(url, env, mbs);
// Start the RMI connector server.
//
System.out.println("Start the RMI connector server on port "+port);
cs.start();
}
}
生成脚本在这里
<project name="Agent" basedir="." default="main">
<property name="src.dir" value="src"/>
<property name="build.dir" value="build"/>
<property name="classes.dir" value="${build.dir}/classes"/>
<property name="jar.dir" value="${build.dir}/jar"/>
<property name="main-class" value="example.rmi.agent.CustomAgent"/>
<target name="clean">
<delete dir="${build.dir}"/>
</target>
<target name="compile">
<mkdir dir="${classes.dir}"/>
<javac srcdir="${src.dir}" destdir="${classes.dir}"/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar destfile="${jar.dir}/${ant.project.name}.jar" basedir="${classes.dir}">
<manifest>
<attribute name="Main-Class" value="${main-class}"/>
</manifest>
</jar>
</target>
<target name="run" depends="jar">
<java jar="${jar.dir}/${ant.project.name}.jar" fork="true"/>
</target>
<target name="clean-build" depends="clean,jar"/>
<target name="main" depends="clean,run"/>
<!-- Builds dist.agent.jar -->
<target name="build-agent-jar" description="build an agent jar that can be used with -javaagent" depends="compile">
<mkdir dir="${jar.dir}"/>
<jar basedir="${classes.dir}" destfile="${jar.dir}/${ant.project.name}.jar">
<manifest>
<attribute name="Premain-Class" value="example.rmi.agent.CustomAgent"/>
</manifest>
</jar>
<echo>To use this application with agent try:</echo>
<echo>java -Dexample.rmi.port=3000 -javaagent:${dist.agent.jar} -classpath [application-classpath] [application-classpath] [application-main-class]</echo>
</target>
</project>
我在远程计算机上启动应用程序时使用
主机上打开了两个端口6004和6005,如果jconsole是应用程序本地的,我可以通过jconsole连接到应用程序。
然后创建2个ssh隧道
ssh隧道ssh-l 6004:localhost:6004 foo@server ssh隧道ssh-l 6005:localhost:6005 foo@server
现在的问题是我无法使用Jconsole进行远程连接
服务:jmx:rmi://localhost:6005/jndi/rmi://localhost:6004/jmxrmi
jconsole启动者:
Dec 18, 2011 4:57:46 PM RMIConnector connect
FINER: [javax.management.remote.rmi.RMIConnector: jmxServiceURL=service:jmx:rmi://localhost:6005/jndi/rmi://localhost:6004/jmxrmi]
我需要加上
-djava.rmi.server.hostname=localhost
java-server参数
我已经在本地Windows 7和远程RHEL 7 VM上安装了JProfiler 10.0.1。 由于格式问题,此处提供了与第3点相关的输出: 一些事实: 我希望监视的远程RHEL JVM与用户“nifi”一起运行 由于我是一个“sudoer”,我使用自己的用户名“ojoqcu”通过SSH(通过Putty)连接到远程VM,然后使用“sudo su”、“su nifi”或简单的“sudo su ni
问题内容: 如何从Java应用程序通过SSH连接到远程MySQL数据库?小代码示例对我有所帮助,对此我将不胜感激。 问题答案: 我的理解是,您想访问在远程计算机上运行的mysql服务器,并通过SSH隧道侦听端口3306。 要使用命令行ssh客户端从本地计算机上的端口1234到远程计算机上的端口3306的隧道,您可以从本地计算机上键入以下命令: 要从Java执行相同的操作,可以使用JSch(SSH2
我正在尝试连接到远程主机以发出命令,但在运行代码时收到以下错误消息: SSH:握手失败:SSH:密钥交换没有通用算法;提供的客户端:[curve25519-sha256@libssh.org ecdh-sha2-nistp256 ecdh-sha2-nistp384 ecdh-sha2-nistp521 difffie-hellman-group14-sha1],提供的服务器:[difffie-h
问题内容: 我已经在服务器上安装了Kibana 5.4和Elastic search 5.4,我可以通过使用本地计算机上的curl来访问Kibana和Elastic search 我得到以下回应 var hashRoute =’/ app / kibana’; var defaultRoute =’/ app / kibana’; var hash = window.location.hash;
我已经在服务器上安装了Kibana 5.4和Elastic search 5.4,我可以使用 我得到以下回应 var hashRoute='/app/kibana'; var defaultRoute='/app/kibana'; var hash=window.location.hash; if(hash.length){window.location=hashRoute hash;}其他{wi
问题内容: 我正在尝试在Java项目中通过SSH连接到远程MySQL服务器。如何将SSH连接与JPA集成在一起? 我正在使用Netbeans 6.9.1,JPA,MySQL 5.2。 问题答案: 我假设您想隧道传输到仅侦听localhost(或已防火墙)的远程mysql 那么最简单的方法是 在运行应用程序服务器的帐户之间建立信任关系,以便将JPA服务提供给您的应用程序 创建隧道使用来创建隧道,该隧