zoukankan      html  css  js  c++  java
  • docker-compose启动的tomcat无法远程连接jmx

    最近想学习下java GC优化,就用了一下VisualVM,在远程服务器启动了一个非docker的tomcat,很顺利的就连接了,但是用docker-compose启动的服务却

    怎么也连不上,一定是docker的锅.

    最终找到了解决方法,在这里 https://forums.docker.com/t/enable-jmx-rmi-access-to-a-docker-container/625

    这篇文章中最重要的一句话就是

    In my case, I am working with docker-compose please DON FORGET to expose the SAME PORT 6001 in the remote docker host (it won't work if you expose in another port differently that jmxremote.port and jmxremote.rmi.port):

    一句话概括就是: docker-compose暴露的端口要跟jmx的端口一样

    好了,问题解决,下面写出tomcat配置jmx的方法:

    1. docker-compose.yml

    web:
      image: "registry.xxxxxx.com/msgbox/base_tomcat:tomcat7.42_jdk8u40"
      ports:
       - 9911:8080
       - 9912:8787
       - 44445:44445
      volumes:
       - ./confs:/data1/confs
       - ./web/webapps:/data1/xxx/webapps
       - ./authconfs:/data1/authconfs
       - ./web/logs:/data1/xxx/logs
      environment:
       - NAME_CONF=test-yf=/data1/xxx/bin/./
       - RUN_COMMAND=catalina.sh jpda run
       - JMX_PORT=44445
       - JMX_HOST=10.77.6.164
       - CATALINA_HEAP=-server -Xmx768m -Xmn100m -Xms768m
      links:
        - kafka

    2. setenv.sh

    if [[ ! -z "$JMX_PORT" ]]; then
        if [ -z "$JMX_HOST" ]; then
            JMX_HOST=$(hostname -i)
        fi 
        CATALINA_EXTRA="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=${JMX_PORT} -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=true -Dcom.sun.management.jmxremote.password.file=../conf/jmxremote.password -Dcom.sun.management.jmxremote.access.file=../conf/jmxremote.access -Djava.rmi.server.hostname=${JMX_HOST} -Dcom.sun.management.jmxremote.rmi.port=${JMX_PORT}"
    fi

    完成

  • 相关阅读:
    5,MongoDB 之 "$" 的奇妙用法
    4,MongoDB 之 $关键字 及 $修改器 $set $inc $push $pull $pop MongoDB
    3,MongoDB之数据类型
    2,MongoDB之增删改查及pymongo的使用
    1,MongoDB简介和安装
    19,Ubuntu安装之python开发
    18,Shell编程实战
    17,saltstack高效运维
    16.2,docker网络
    如何使用 window api 转换字符集?
  • 原文地址:https://www.cnblogs.com/txwsqk/p/6254729.html
Copyright © 2011-2022 走看看