【问题标题】:How to use firewall with ActiveMQ?如何在 ActiveMQ 中使用防火墙?
【发布时间】:2016-03-16 16:46:37
【问题描述】:

我在运行ZookeeperActiveMQ3 台虚拟机 中配置了此端口。

root@mom3:~# ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip

To                         Action      From
--                         ------      ----
22                         ALLOW IN    Anywhere
2881                       ALLOW IN    Anywhere
2888                       ALLOW IN    Anywhere
3888                       ALLOW IN    Anywhere
61616                      ALLOW IN    Anywhere
61617                      ALLOW IN    Anywhere
22 (v6)                    ALLOW IN    Anywhere (v6)
2881 (v6)                  ALLOW IN    Anywhere (v6)
2888 (v6)                  ALLOW IN    Anywhere (v6)
3888 (v6)                  ALLOW IN    Anywhere (v6)
61616 (v6)                 ALLOW IN    Anywhere (v6)
61617 (v6)                 ALLOW IN    Anywhere (v6)

当我尝试启动 ActiveMQ 时,它会获得一个随机端口来使用它:

 INFO | Master started: tcp://mom1.company.com:37649
 WARN | Store update waiting on 1 replica(s) to catch up to log position 0. 
 WARN | Store update waiting on 1 replica(s) to catch up to log position 0. 
 WARN | Store update waiting on 1 replica(s) to catch up to log position 0. 

但是当我禁用我的防火墙时,ActiveMQ正常启动

如何每次都使用相同的端口,以便在我的防火墙中创建新规则?

编辑 根据@Daniel 的建议,这是我对activemq.xml 文件的配置。

<persistenceAdapter>
    <replicatedLevelDB
        directory="${activemq.data}/leveldb"
        replicas="3"
        bind="tcp://0.0.0.0:0:61616"
        zkAddress="mom1.company.com:2881,mom2.company.com:2881,mom3.company.com:2881"
        zkPassword="password"
        zkPath="/activemq/leveldb-stores"
        hostname="mom3.company"
    />
</persistenceAdapter>

...
<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="amqp" uri="amqp://0.0.0.0:5672?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="stomp" uri="stomp://0.0.0.0:61613?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="mqtt" uri="mqtt://0.0.0.0:1883?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="ws" uri="ws://0.0.0.0:61614?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
    <transportConnector name="ssl" uri="ssl://0.0.0.0:61617?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>

【问题讨论】:

    标签: activemq firewall apache-zookeeper


    【解决方案1】:

    由于您正在撰写有关 zookeeper 的文章,而我模糊地记得当我使用主/从复制 levelDB 设置时的这条日志行,我将继续假设您也在使用一个。如果确实是这种情况,那么您看到的端口就是主服务器启动的“绑定”端口,供客户端连接并开始复制数据。这个端口可以很容易地在你的代理 XML 配置中使用 replicatedLevelDB 部分中的 bind 参数进行配置,例如

    <broker brokerName="broker" ... >
      ...
      <persistenceAdapter>
        <replicatedLevelDB
          directory="activemq-data"
          replicas="3"
          bind="tcp://0.0.0.0:<myDesiredPort>"
          zkAddress="zoo1.example.org:2181,zoo2.example.org:2181,zoo3.example.org:2181"
          zkPassword="password"
          zkPath="/activemq/leveldb-stores"
          hostname="broker1.example.org"
          />
      </persistenceAdapter>
      ...
    </broker>
    

    然后将始终使用“myDesiredPort”作为绑定端口。由于通常 61619 是根本未设置此参数时的默认端口,因此您可能现在已经配置了此元素,但是使用 bind="tcp://0.0.0.0:0" 动态选择一个。有关复制的 levelDB 的更多说明和可用参数的完整列表,请参阅documentation

    希望这能解决您的问题,但如果这不是您的设置,请将您的代理配置添加到您的问题中,这样可以更轻松地找到真正的罪魁祸首而无需猜测。

    【讨论】:

    • 您好丹尼尔,感谢您的建议。我是对的,这就是我的设置,3 个zookeeper 服务器与activemq 一起工作。我尝试了端口6161961616,但我得到了ERROR | Error in thread 'ActiveMQ BrokerService[localhost] Task-1' java.lang.IllegalArgumentException: port out of range:-1 at java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)[:1.8.0_73]
    • 感谢您使用配置更新您的问题,我想我发现了问题。只是为了完整起见(这应该不是问题,因为您还测试了61619)绑定端口需要使用自己的空闲端口,在您的配置中,绑定和开放线连接器都使用相同的,这将不起作用,因为在内部,绑定与使用给定参数启动另一个连接器没有太大区别。然而,真正的问题是你的配置中 1:0 太多了,现在你有 bind="tcp://0.0.0.0:0:61616" 请用 bind="tcp://0.0.0.0:61619" 试试。
    猜你喜欢
    • 2015-06-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-16
    • 2019-04-15
    • 2015-06-24
    • 1970-01-01
    • 2013-12-02
    • 2019-06-12
    相关资源
    最近更新 更多