VisualVM连接到Docker上托管的Tomcat

时间:2015-10-26 08:52:18

标签: tomcat docker jmx visualvm

我尝试配置从VisualVM到托管在远程Docker机器上的Tomcat的JMX连接:

locahost with VisualVM --> server with docker (192.168.23.8) --> Tomcat container

我的Dockerfile是:

FROM centos:centos6

RUN yum upgrade -y \
  &&  yum -y install java-1.7.0-openjdk \
  &&  yum -y install tar \
  && yum clean all

COPY apache-tomcat-7.0.64.tar.gz /tmp/
RUN mkdir /opt/tomcat
RUN tar -xzvf /tmp/apache-tomcat-7.0.64.tar.gz --directory /opt/tomcat/ --strip 1
RUN rm /tmp/apache-tomcat-7.0.64.tar.gz

COPY catalina-jmx-remote.jar /opt/tomcat/lib/
COPY setenv.sh /opt/tomcat/bin/
COPY server.xml /opt/tomcat/conf/

EXPOSE 8080
EXPOSE 9090
EXPOSE 9091

CMD /opt/tomcat/bin/catalina.sh start && tail -f /opt/tomcat/logs/catalina.out

使用bin / setenv.sh文件(其中192.168.23.8是我的主机ip):

export JAVA_OPTS="-Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -Djava.rmi.server.hostname=192.168.23.8"

使用原始的conf / server.xml,我添加了以下监听器:

<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" 
          rmiRegistryPortPlatform="9090" rmiServerPortPlatform="9091" />

catalina-jmx-remote.jar已在7.0.64附加库中找到。

每个端口都在localhost和docker服务器之间打开,我的端口正确暴露:

Ports: [
{
IP: "0.0.0.0",
PrivatePort: 9091,
PublicPort: 9091,
Type: "tcp"
},
{
IP: "0.0.0.0",
PrivatePort: 9090,
PublicPort: 9090,
Type: "tcp"
},
{
IP: "0.0.0.0",
PrivatePort: 8080,
PublicPort: 33284,
Type: "tcp"
}
]

Tomcat日志是:

INFO: Command line argument: -Dcom.sun.management.jmxremote=true
Oct 26, 2015 8:36:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcom.sun.management.jmxremote.ssl=false
Oct 26, 2015 8:36:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Dcom.sun.management.jmxremote.authenticate=false
Oct 26, 2015 8:36:52 AM org.apache.catalina.startup.VersionLoggerListener log
INFO: Command line argument: -Djava.rmi.server.hostname=192.168.23.8
...
Oct 26, 2015 8:36:53 AM org.apache.catalina.mbeans.JmxRemoteLifecycleListener createServer
INFO: The JMX Remote Listener has configured the registry on port 9090 and the server on port 9091 for the Platform server

但是当我在VisualVM上打开一个新的JMX连接时,我收到以下错误:

Cannot connect to 192.168.23.8:9090 using service:jmx:rmi:///jndi/rmi://192.168.23.8:9090/jmxrmi

有什么想法解决这个问题吗?

0 个答案:

没有答案