场景
我所有的业务均运行再docker镜像之中,网上有伙伴写到docker run 的启动方法,我没有去验证过,直觉告诉我可能不太好使。要监控docker内部,通过以往的处理方法我需要将镜像中端口映射出来,那么再这基础之上直接做端口映射。
下载jprofiler
可以去官网下载,也可以去这里下载
注意:我这里的下载文件为Linux和Windows的合集,其他环境请移步到官网下载。本场景使用jprofiler14进行
配置Windows客户端
安装过程忽略
启动Windows客户端
新建远程集成
选择远程计算机,Linux平台,我这里是Linux平台
默认下一步
默认选择,第一个或者第二
输入目标ip地址
!!!!注意:以下路径再Linux上有配置,后面有讲,必须配对**!!!!!**
注意:8849端口,需要有镜像映射出来,启动镜像的时候需要设置正确。8849端口为服务器对外端口,docker镜像内端口可以不是8849。端口将再最后做详细说明。
将红色部分拷贝到启动命令之后
配置完成
配置服务器
将jprofiler_linux_14_0.tar.gz拷贝到镜像中并解压
配置启动
在启动命令java -jar **.jar后添加参数,然后重启镜像。参数如下,由上截图倒数第二张出拷贝
-agentpath:/xx/jprofiler14.0/bin/linux-x64/bin/linux-aarch64/libjprofilerti.so=port=28007,nowait
配置镜像映射
docker run 的命令将8848端口映射到主机
启动
进入到镜像中,jprofiler14.0的安装目录下的bin目录,执行./jpenable并选择,尤其是最后一步指定端口,必须配置成映射到宿主机的端口,本次使用的是jprofiler的默认端口8849
[root@137189016cac bin]# ./jpenable
Connecting to /xx/znsx...ofilerti.so=port=18000,nowait [1] ...
DANGER! The selected JVM uses class sharing.
Under some circumstances, a bug in the JVM can cause the JVM to crash in attach mode.
To avoid this problem, start the JVM with the VM parameter -Xshare:off
Do you wish to proceed with attaching anyway?
Proceed [p], Cancel [c, Enter]
p
Please select the profiling mode:
GUI mode (attach with JProfiler GUI) [1, Enter]
Offline mode (use config file to set profiling settings) [2]
1
Please enter a profiling port
[35684]
8849
You can now use the JProfiler GUI to connect on port 8849
回到Windows客户端
按如下图操作,点击开始即可
注意:一定要在启动的时候去执行./jpenable和Windows的连接,否则进不去!!!