如何在ActiveMQ中使用防火墙?

如何在ActiveMQ中使用防火墙?,activemq,firewall,apache-zookeeper,Activemq,Firewall,Apache Zookeeper,我在运行Zookeeper和ActiveMQ的3台虚拟机中配置了此端口 root@mom3:~# ufw status verbose Status: active Logging: on (low) Default: deny (incoming), allow (outgoing), disabled (routed) New profiles: skip To Action From --

我在运行
Zookeeper
ActiveMQ
3台虚拟机中配置了此端口

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>

...

既然你写的是一个动物园管理员,而我隐约记得我在使用主/从复制的levelDB设置时的这一行日志,那么我继续假设你也在使用它。如果确实是这样,那么您看到的端口就是主服务器启动的“绑定”端口,供客户端连接并开始复制数据。例如,可以使用replicatedLevelDB部分中的bind参数在代理XML配置中轻松配置此端口

<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的更多说明和可用参数的完整列表,请参阅


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

嗨,丹尼尔,谢谢您的建议。我是对的,这是我的设置,3
zookeeper
服务器使用
activemq
。我尝试了端口
6161619
6161616
,但在线程'ActiveMQ BrokerService[localhost]Task-1'java.lang.IllegalArgumentException:port超出范围:-1在java.net.InetSocketAddress.checkPort(InetSocketAddress.java:143)[:1.8.0_73]。感谢您用配置更新您的问题,我想我发现了问题所在。为了完整性起见(这应该不是问题,因为您也测试了
61619
),绑定端口需要使用自己的空闲端口,在您的配置中,绑定和openwire连接器都使用相同的端口,这将不起作用,因为在内部绑定与使用给定参数启动另一个连接器没有太大区别。然而,真正的问题是,您的配置中有一个:0太多,现在您有
bind=”tcp://0.0.0.0:0:61616“
请尝试使用
bind=”tcp://0.0.0.0:61619“