使用 JConsole 监控 docker 中的 Java 应用程序



我正在尝试监视java应用程序,使用JConsole在docker容器内运行,但收到错误:

连接失败:JRMP 连接建立期间出错;嵌套 例外是java.net.SocketException;

我正在使用本指南中的下一个 docker 参数(也使用了注释中的 diff 额外标志,例如:Djava.rmi.server.hostname=10.16.114.98 + --net=host,(

docker run -p 8080:8080 -p 9010:9010 --rm -e JAVA_OPTS="-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.ssl=false" gateway

操作系统:红帽 7

以下是docker inspect的输出:

[
{
"Id": "06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942",
"Created": "2017-08-18T12:52:37.002174333Z",
"Path": "/bin/sh",
"Args": [
"-c",
"echo "The application will start in ${JHIPSTER_SLEEP}s..." u0026u0026     sleep ${JHIPSTER_SLEEP} u0026u0026     java -Djava.security.egd=file:/dev/./urandom -jar /app.war"
],
"State": {
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 22543,
"ExitCode": 0,
"Error": "",
"StartedAt": "2017-08-18T12:52:38.539827439Z",
"FinishedAt": "0001-01-01T00:00:00Z"
},
"Image": "760fc9348dddb4ef6a3a031e6c75d31645ac811ce17a27289e462f265d21d5e7",
"ResolvConfPath": "/var/lib/docker/containers/06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942/hostname",
"HostsPath": "/var/lib/docker/containers/06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942/hosts",
"LogPath": "/var/lib/docker/containers/06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942/06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942-json.log",
"Name": "/desperate_hugle",
"RestartCount": 0,
"Driver": "devicemapper",
"ExecDriver": "native-0.2",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "",
"ExecIDs": null,
"HostConfig": {
"Binds": null,
"ContainerIDFile": "",
"LxcConf": [],
"Memory": 0,
"MemoryReservation": 0,
"MemorySwap": 0,
"KernelMemory": 0,
"CpuShares": 0,
"CpuPeriod": 0,
"CpusetCpus": "",
"CpusetMems": "",
"CpuQuota": 0,
"BlkioWeight": 0,
"OomKillDisable": false,
"MemorySwappiness": -1,
"Privileged": false,
"PortBindings": {
"8080/tcp": [
{
"HostIp": "",
"HostPort": "8080"
}
],
"9010/tcp": [
{
"HostIp": "",
"HostPort": "9010"
}
]
},
"Links": null,
"PublishAllPorts": false,
"Dns": [],
"DnsOptions": [],
"DnsSearch": [],
"ExtraHosts": null,
"VolumesFrom": null,
"Devices": [],
"NetworkMode": "default",
"IpcMode": "",
"PidMode": "",
"UTSMode": "",
"CapAdd": null,
"CapDrop": null,
"GroupAdd": null,
"RestartPolicy": {
"Name": "no",
"MaximumRetryCount": 0
},
"SecurityOpt": null,
"ReadonlyRootfs": false,
"Ulimits": null,
"LogConfig": {
"Type": "json-file",
"Config": {}
},
"CgroupParent": "",
"ConsoleSize": [
0,
0
],
"VolumeDriver": ""
},
"GraphDriver": {
"Name": "devicemapper",
"Data": {
"DeviceId": "574",
"DeviceName": "docker-253:0-135637248-06df0e186f49297e217bab77c9101926bc2333c429d4551a151a64159a82c942",
"DeviceSize": "107374182400"
}
},
"Mounts": [
{
"Name": "42e8ebbf5846da5067567cab9a72e75931c1190b94a5d62169b9c2cf54e33138",
"Source": "/var/lib/docker/volumes/42e8ebbf5846da5067567cab9a72e75931c1190b94a5d62169b9c2cf54e33138/_data",
"Destination": "/tmp",
"Driver": "local",
"Mode": "",
"RW": true
}
],
"Config": {
"Hostname": "06df0e186f49",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": true,
"AttachStderr": true,
"ExposedPorts": {
"5701/udp": {},
"8080/tcp": {},
"9010/tcp": {}
},
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"JAVA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9010 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.rmi.port=9010 -Dcom.sun.management.jmxremote.ssl=false",
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/lib/jvm/java-1.8-openjdk/jre/bin:/usr/lib/jvm/java-1.8-openjdk/bin",
"LANG=C.UTF-8",
"JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk/jre",
"JAVA_VERSION=8u131",
"JAVA_ALPINE_VERSION=8.131.11-r1",
"JHIPSTER_SLEEP=0"
],
"Cmd": [
"/bin/sh",
"-c",
"echo "The application will start in ${JHIPSTER_SLEEP}s..." u0026u0026     sleep ${JHIPSTER_SLEEP} u0026u0026     java -Djava.security.egd=file:/dev/./urandom -jar /app.war"
],
"Image": "gateway",
"Volumes": {
"/tmp": {}
},
"WorkingDir": "",
"Entrypoint": null,
"OnBuild": null,
"Labels": {},
"StopSignal": "SIGTERM"
},
"NetworkSettings": {
"Bridge": "",
"SandboxID": "1a318dd2e3bffc03a0242b08ba4e8a6592f076f89f317da8ba825f2be7ca01d5",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": {
"5701/udp": null,
"8080/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "8080"
}
],
"9010/tcp": [
{
"HostIp": "0.0.0.0",
"HostPort": "9010"
}
]
},
"SandboxKey": "/var/run/docker/netns/1a318dd2e3bf",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "df67c23d6e56d645dfe6a8767598bacd35d86e1b29a4caf078fd4c0bc5a92784",
"Gateway": "172.17.0.1",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"MacAddress": "02:42:ac:11:00:03",
"Networks": {
"bridge": {
"EndpointID": "df67c23d6e56d645dfe6a8767598bacd35d86e1b29a4caf078fd4c0bc5a92784",
"Gateway": "172.17.0.1",
"IPAddress": "172.17.0.3",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
}
}
}
}
]

问题似乎是java.rmi.server.hostname属性的值。

这必须是 JMX 客户端用于连接到 JVM 的主机名或 IP 地址。如果尝试使用 127.0.0.1:9010 进行连接,则在启动时使用 -Djava.rmi.server.hostname=127.0.0.1

相关内容

  • 没有找到相关文章

最新更新