gpt4 book ai didi

java - DC/OS JMX 访问 java 应用程序

转载 作者:行者123 更新时间:2023-12-02 13:01:05 25 4
gpt4 key购买 nike

我是 docker 和 dc/os 的新手。我已经在microsoft azure中部署了dc/os集群。我需要通过 jmx 设置对我的 java 应用程序的访问权限,但我不能。我们以部署标准 tomcat 镜像为例。我在本地计算机上安装了 docker。要运行具有 jmx 访问权限的 tomcat 容器,我使用以下命令:

docker run -e 
JAVA_OPTS= "-Dcom.sun.management.jmxremote
-Djava.rmi.server.hostname=127.0.0.1
-Dcom.sun.management.jmxremote.port=8081
-Dcom.sun.management.jmxremote.rmi.port=8081
-Dcom.sun.management.jmxremote.local.only=false
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false"
-p 8080:8080 -p 8081:8081 tomcat:8.0

我可以通过端口 8081 连接到 Tomcat。

我尝试在 dc/os 集群中执行相同的操作。我使用下面的 json 配置来部署:

{
"id": "/tomcat",
"instances": 1,
"cpus": 1,
"mem": 512,
"container": {
"type": "DOCKER",
"docker": {
"image": "tomcat:8.0",
"network": "BRIDGE",
"portMappings": [
{ "protocol": "tcp", "hostPort": 8080, "containerPort": 8080 },
{ "protocol": "tcp", "hostPort": 8081, "containerPort": 8081 }
]
}
},
"requirePorts": true,
"acceptedResourceRoles": [
"slave_public"
],
"env": {
"JAVA_OPTS": "-Dcom.sun.management.jmxremote -Djava.rmi.server.hostname=10.0.0.4 -Dcom.sun.management.jmxremote.port=8081 -Dcom.sun.management.jmxremote.rmi.port=8081 -Dcom.sun.management.jmxremote.local.only=false -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"
},
"healthChecks": [
{
"gracePeriodSeconds": 120,
"intervalSeconds": 30,
"maxConsecutiveFailures": 3,
"path": "/",
"portIndex": 0,
"protocol": "HTTP",
"timeoutSeconds": 5
}
]
}

之后我可以访问 tomcat webconsole,但无法通过 jmx 连接。我尝试了“-Djava.rmi.server.hostname”的各种值:127.0.0.1、10.0.0.4(代理ip)、agents.westeurope.cloudapp.azure.com。请帮助我理解我做错了什么。

更新:感谢 Walter - MSFT,他指出了 azure 上默认打开哪些端口的事实。我真的忘记了。但通过 jmx 连接的问题对我来说仍然是现实的。我开启了新的讨论,并提供了更多细节。 DC/OS JMX Access

最佳答案

您可以阅读Azure official article:

Any DC/OS container in the ACS public agent pool is automatically exposed to the internet. By default, ports 80, 443, 8080 are opened, and any (public) container listening on those ports are accessible.

根据您的描述,好像8081端口没有开放。您可以在 Azure 门户上打开端口 8081。

更多信息请引用此链接:Enable public access to an Azure Container Service application

更新:

我在我的实验室中使用你的 json 文件进行测试,它对我有用,你不需要更改它。您应该在 Azure NSG 和负载平衡上打开端口。

核供应国集团:

负载均衡器enter image description here

我在实验室测试,可以打开8080 Web UI。当我测试端口 8081 时,我注意到该端口正在监听,我可以使用公共(public) IP 访问该端口。

azureuser@dcos-master-01234567-0:~$ netcat -z -v 13.84.176.235 8081
Connection to 13.84.176.235 8081 port [tcp/tproxy] succeeded!

你也可以使用curl来测试,我得到以下结果。

azureuser@dcos-master-01234567-0:~$ curl 13.84.176.235:8081
curl: (52) Empty reply from server

如果您无法访问8081 Web UI,我建议您最好检查docker容器。

关于java - DC/OS JMX 访问 java 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44290883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com