您的当前位置:首页正文

查看docker中运行的JVM参数问题及解决方法

2020-09-23 来源:榕意旅游网
查看docker中运⾏的JVM参数问题及解决⽅法

⽅法⼀、jcmd命令:

1、jps获取java的线程id2、jcmd pidVM.flags获取

51152:

-XX:CICompilerCount=3 -XX:InitialHeapSize=526385152 -XX:MaxHeapSize=1073741824 -XX:MaxNewSize=357564416-XX:MinHeapDeltaBytes=524288 -XX:NewSize=175112192 -XX:OldSize=351272960 -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC?但是以上命令查询的结果不全

⽅法⼆、jinfo命令:

jinfo -flag pid

在docker中使⽤此命令后报错:

Attaching to process ID 1, please wait...

Error attaching to process: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process:ptrace(PTRACE_ATTACH, ..) failed for 1: Operation not permitted

sun.jvm.hotspot.debugger.DebuggerException: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process:ptrace(PTRACE_ATTACH, ..) failed for 1: Operation not permitted at

sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.execute(LinuxDebuggerLocal.java:163) at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach(LinuxDebuggerLocal.java:278) at sun.jvm.hotspot.HotSpotAgent.attachDebugger(HotSpotAgent.java:671)

at sun.jvm.hotspot.HotSpotAgent.setupDebuggerLinux(HotSpotAgent.java:611) at sun.jvm.hotspot.HotSpotAgent.setupDebugger(HotSpotAgent.java:337) at sun.jvm.hotspot.HotSpotAgent.go(HotSpotAgent.java:304) at sun.jvm.hotspot.HotSpotAgent.attach(HotSpotAgent.java:140) at sun.jvm.hotspot.tools.Tool.start(Tool.java:185) at sun.jvm.hotspot.tools.Tool.execute(Tool.java:118) at sun.jvm.hotspot.tools.JInfo.main(JInfo.java:138)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at sun.tools.jinfo.JInfo.runTool(JInfo.java:108) at sun.tools.jinfo.JInfo.main(JInfo.java:76)

Caused by: sun.jvm.hotspot.debugger.DebuggerException: Can't attach to the process: ptrace(PTRACE_ATTACH, ..)failed for 1: Operation not permitted

at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.attach0(Native Method)

at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal.access$100(LinuxDebuggerLocal.java:62)

at sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$1AttachTask.doit(LinuxDebuggerLocal.java:269) at

sun.jvm.hotspot.debugger.linux.LinuxDebuggerLocal$LinuxDebuggerLocalWorkerThread.run(LinuxDebuggerLocal.java:138)

解决⽅法:

这其实不是什么 Bug,⽽是 Docker ⾃ 1.10 版本开始加⼊的安全特性。

类似于 jmap 这些 JDK ⼯具依赖于 Linux 的 PTRACE_ATTACH,⽽是 Docker ⾃ 1.10 在默认的 seccomp 配置⽂件中禁⽤了 ptrace。这篇⽂章介绍了整个的缘由以及应对⽅法:

主要提及三种:

1.1 –security-opt seccomp=unconfined

简单暴⼒(不推荐),直接关闭 seccomp 配置。⽤法:

1docker run --security-opt seccomp:unconfined ...

1.2 –cap-add=SYS_PTRACE

使⽤ --cap-add 明确添加指定功能:

1docker run --cap-add=SYS_PTRACE ...

1.3 Docker Compose 的⽀持

Docker Compose ⾃ version 1.1.0 (2015-02-25) 起⽀持 cap_add。官⽅⽂档:cap_add, cap_drop。⽤法:前⾯的 docker-compose.yml 改写后⽂件内容如下(相同内容部分就不重复贴了):1

2version: '2'services:3 mysql:4 ...5 api:6 ...

cap_add:

7 - SYS_PTRACE8解决问题后使⽤命令:

1Debugger attached successfully.2Server compiler detected.3JVM version is 25.202-b08

4Non-default VM flags: -XX:CICompilerCount=3 -XX:InitialHeapSize=262144000 -XX:MaxHeapSize=268435456 -XX:MaxNewSize=89128960 -XX:MinHeapDeltaBytes=524288 -XX:NewSize=87031808 -XX:OldSize=175112192 -XX:ThreadStackSize=256 -XX:+UseCompressedClassPointers -5

XX:+UseCompressedOops -XX:+UseParallelGC

6Command line: -Dlog4j2.formatMsgNoLookups=true -Xmx256m -Xss256k -Djava.security.egd=file:/dev/./urandom

Attaching to process ID 1, please wait...

到此这篇关于查看docker中运⾏的JVM参数的⽂章就介绍到这了,更多相关docker JVM参数内容请搜索以前的⽂章或继续浏览下⾯的相关⽂章希望⼤家以后多多⽀持!

因篇幅问题不能全部显示,请点此查看更多更全内容