在Docker中运行时,ActiveMQ Artemis不显示Web控制台

s1ag04yj  于 2023-03-17  发布在  Docker
关注(0)|答案(3)|浏览(178)

我正在使用本地计算机(使用Windows 10)中的Docker桌面从quay.io部署Docker中的ActiveMQ Artemis。
我发出以下命令以启动最新映像:

docker run -e AMQ_USER=admin -e AMQ_PASSWORD=admin -p8161:8161 -p61616:61616 -p5672:5672 --rm --name artemis quay.io/artemiscloud/activemq-artemis-broker

注:dev.latest标记不可用,因此使用了latest标记。
Docker容器中的ActiveMQ Artemis示例成功启动,我能够登录到Web控制台:

...
2022-06-18 20:08:26,820 INFO  [org.apache.activemq.artemis.core.server] AMQ221007: Server is now live
2022-06-18 20:08:26,821 INFO  [org.apache.activemq.artemis.core.server] AMQ221001: Apache ActiveMQ Artemis Message Broker version 2.22.0 [broker, nodeID=68f4db2b-ef42-11ec-b609-0242ac110002]
2022-06-18 20:08:27,607 INFO  [org.apache.activemq.hawtio.branding.PluginContextListener] Initialized activemq-branding plugin
2022-06-18 20:08:27,746 INFO  [org.apache.activemq.hawtio.plugin.PluginContextListener] Initialized artemis-plugin plugin
2022-06-18 20:08:28,414 INFO  [io.hawt.HawtioContextListener] Initialising hawtio services
2022-06-18 20:08:28,438 INFO  [io.hawt.system.ConfigManager] Configuration will be discovered via system properties
2022-06-18 20:08:28,443 INFO  [io.hawt.jmx.JmxTreeWatcher] Welcome to Hawtio 2.14.2
2022-06-18 20:08:28,459 INFO  [io.hawt.web.auth.AuthenticationConfiguration] Starting hawtio authentication filter, JAAS realm: "activemq" authorized role(s): "admin" role principal classes: "org.apache.activemq.artemis.spi.core.security.jaas.RolePrincipal"
2022-06-18 20:08:28,480 INFO  [io.hawt.web.auth.LoginRedirectFilter] Hawtio loginRedirectFilter is using 1800 sec. HttpSession timeout
2022-06-18 20:08:28,520 INFO  [io.hawt.web.proxy.ProxyServlet] Proxy servlet is disabled
2022-06-18 20:08:28,539 INFO  [io.hawt.web.servlets.JolokiaConfiguredAgentServlet] Jolokia overridden property: [key=policyLocation, value=file:/home/jboss/broker/etc/jolokia-access.xml]
2022-06-18 20:08:28,788 INFO  [org.apache.activemq.artemis] AMQ241001: HTTP Server started at http://172.17.0.2:8161
2022-06-18 20:08:28,789 INFO  [org.apache.activemq.artemis] AMQ241002: Artemis Jolokia REST API available at http://172.17.0.2:8161/console/jolokia
2022-06-18 20:08:28,790 INFO  [org.apache.activemq.artemis] AMQ241004: Artemis Console available at http://172.17.0.2:8161/console
2022-06-18 20:14:28,681 INFO  [io.hawt.web.auth.LoginServlet] Hawtio login is using 1800 sec. HttpSession timeout
2022-06-18 20:14:30,401 INFO  [io.hawt.web.auth.keycloak.KeycloakServlet] Keycloak integration is disabled
2022-06-18 20:14:34,273 INFO  [io.hawt.web.auth.LoginServlet] Logging in user: admin

我无法查看消费者、生产者、会话、队列等标记。
我知道我们需要修改jolokia-access.xml中的IP并重新启动,但如果在Docker运行命令中没有--rm,我无法编辑映像中docker exec -it artemis bash内的文件并重新启动它。
jolokia-access.xml中是否有任何环境变量可以禁用cors或strict?
下面是我在http://localhost:8161/console上看到的内容:

日志显示控制台在http://172.17.0.2:8161/console可用。但是,这是不可访问的,因为Docker是完全不同的网络。当我尝试访问它时,我得到以下消息:

This site can’t be reached 172.17.0.2 took too long to respond

当我访问端点http://localhost:8161/console/jolokia时,我得到消息:

{ error_type: "java.lang.Exception", error: "java.lang.Exception : Origin null is not allowed to call this agent", status: 403 }
qnakjoqk

qnakjoqk1#

为了绕过码头上的犹太人,

  • 我在Docker中使用nginx服务器创建了一个反向代理并设置了头。

下面是我遵循的步骤,

  • 运行一个nginx示例,
> docker run -d --name nginx-proxy -p 80:80 nginx
  • 使用以下命令将现有的default.conf复制到本地系统
# my present working directory is a temp folder 
> docker cp nginx-proxy:/etc/nginx/conf.d/default.conf .
  • 已标识aretmis容器的主机名/IP地址,因为我需要将其设置为Origin的标头
> docker exec artemis hostname -i
  • 将以下内容更新为default.conf文件
server {
    listen       80;
    listen  [::]:80;
    server_name  localhost;

    location / {
     if ($request_method = 'OPTIONS') {
        add_header Origin http://172.17.0.2;
        add_header 'Access-Control-Allow-Origin' '*';

        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';

        add_header 'Access-Control-Max-Age' 86400;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204; break;
     }

     if ($request_method = 'POST') {
        add_header Origin http://172.17.0.2;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }
     if ($request_method = 'GET') {
        add_header Origin http://172.17.0.2;
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Credentials' 'true';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
     }

      proxy_pass http://172.17.0.2:8161/;
      proxy_set_header Origin http://172.17.0.2;
      proxy_set_header Host      $host:$server_port;
      proxy_set_header X-Real-IP $remote_addr;
    }

    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
     error_page   500 502 503 504  /50x.html;
     location = /50x.html {
        root   /usr/share/nginx/html;
     }
}
  • 注意:不要忘记最后的;
  • 复制默认值到nginx服务器,我们可以验证和重新加载新的配置,而无需停止容器。
# I am in my temp directory 
# to copy use below command
> docker cp default.conf nginx-proxy:/etc/nginx/conf.d/default.conf

# to validate the config file use below command
> docker exec nginx-proxy nginx -t

# to restart send singal using below command
> docker exec nginx-proxy nginx -r reload
  • 由于我们为nginx容器公开了80端口,因此可以点击http://localhost:80/console来访问ArtemisMQ页面。
  • 这只能用于开发目的。不适用于生产。

Refered How to set nginx reverse proxy blog
附加注解:

  • 我必须验证我是否能够从docker的nginx服务器中访问jolokia端点,使用下面的命令。
> docker exec -it nginx-proxy bash

我用来验证的curl命令。

root@681b68921481:/# curl -H "Origin: http://172.17.0.2" http://admin:amdin@172.17.0.2:8161/console/jolokia/
  • 输出:
{"request":{"type":"version"},"value":{"agent":"1.7.0","protocol":"7.2","config":{"listenForHttpService":"true","authIgnoreCerts":"false","agentId":"172.17.0.2-1-6c008c24-servlet","debug":"fal
se","agentType":"servlet","policyLocation":"file:\/home\/jboss\/broker\/etc\/jolokia-access.xml","agentContext":"\/jolokia","serializeException":"false","mimeType":"text\/plain","dispatcherCla
sses":"org.jolokia.http.Jsr160ProxyNotEnabledByDefaultAnymoreDispatcher","multicastGroup":"239.192.48.84","authMode":"basic","authMatch":"any","streaming":"true","canonicalNaming":"true","hist
oryMaxEntries":"10","allowErrorDetails":"false","allowDnsReverseLookup":"true","realm":"jolokia","includeStackTrace":"false","multicastPort":"24884","mbeanQualifier":"qualifier=hawtio","useRes
gkn4icbw

gkn4icbw2#

我解决了创建一个自定义脚本launch.sh来覆盖图像quay.io/artemiscloud/activemq-artemis-broker中的启动器,并禁用CORS限制以在Docker上运行Web控制台。

# Download script
wget https://gist.githubusercontent.com/vifito/36b00547251ab84225d986fd7d4f18f3/raw -O launch.sh

# Set exec permission
chmod +x launch.sh

# docker run
docker run -d --name amq \
  -e AMQ_USER=admin -e AMQ_PASSWORD=admin \
  -p 8161:8161 -p 61616:61616 \
  -v `pwd`/launch.sh:/opt/amq/bin/launch.sh \
  quay.io/artemiscloud/activemq-artemis-broker

# Open console
xdg-open http://0.0.0.0:8161/console
egdjgwm8

egdjgwm83#

ArtemisCloud代理容器出于安全原因限制对容器网络的访问,但Docker Desktop for Windows不支持host networking driver
您可以覆盖默认的代理配置,在/home/jboss/broker/etc上装载您自己的etc文件夹,即

docker run -v /tmp/my-broker-etc:/home/jboss/broker/etc -e AMQ_USER=admin -e AMQ_PASSWORD=admin -p8161:8161 -p61616:61616 -p5672:5672 --rm --name artemis quay.io/artemiscloud/activemq-artemis-broker

Docker使部署微服务应用程序变得非常容易,但它对生产环境有一些限制。我想看看ArtemisCloud.io运营商,它提供了一种在Kubernetes上部署Apache ActiveMQ Artemis Broker的方法。

相关问题