许多 Docker 容器上的 ActiveMQ Artemis 集群配置?
Configuration for ActiveMQ Artemis cluster on many Docker containers?
我不知道我做错了什么。我正在尝试在 2 docker 个容器上正确配置 ActiveMQ Artemis HA 集群,但我没有在日志中看到任何关于“备份服务器”等信息。它似乎不起作用。我试图为集群制作一个简单的 Java 客户端,但它没有连接到它。请不要写“你读过文档了吗”——因为是的,我已经读过了。从我的角度来看,似乎主从之间没有任何联系,但我不知道为什么。我已经用数据配置了 docker 环境:
Docker 文件:
FROM ubuntu:latest
LABEL maintainer="Bernard"
RUN mkdir /artemis
WORKDIR /artemis
RUN apt-get update
RUN apt-get -y install wget
RUN apt-get -y install openjdk-11-jdk
RUN java --version
RUN wget -O "artemis.tar" "https://www.apache.org/dyn/closer.cgi?filename=activemq/activemq-artemis/2.18.0/apache-artemis-2.18.0-bin.tar.gz&action=download"
RUN tar -xvf ./artemis.tar; \
ln -s /artemis/apache-artemis-2.18.0/ ./current
RUN /artemis/current/bin/artemis create --user admin --password admin --http-host 0.0.0.0 --require-login --relax-jolokia bernard
EXPOSE 8161 \
9404 \
61616 \
61617 \
5445 \
5672 \
1883 \
61613
ENTRYPOINT ["/artemis/bernard/bin/artemis", "run"]
docker-compose.yml
:
version: '3'
services:
myartemis1:
build: artemis/
volumes:
- "/e/sandbox/artemis_volume/artemis1/etc:/artemis/bernard/etc"
networks:
artemis-cluster-network:
ipv4_address: 172.20.0.100
ports:
- 8161:8161
- 9404:9404
- 9876:9876
- 61616:61616
- 5445:5445
- 5672:5672
- 1883:1883
- 61613:61613
- 5432:5432
myartemis2:
build: artemis/
volumes:
- "/e/sandbox/artemis_volume/artemis2/etc:/artemis/bernard/etc"
networks:
artemis-cluster-network:
ipv4_address: 172.20.0.101
ports:
- 8162:8161
- 9405:9404
- 9877:9876
- 61618:61616
- 61617:61617
- 5446:5445
- 5673:5672
- 1884:1883
- 61614:61613
- 5433:5432
volumes:
artemis1:
artemis2:
networks:
artemis-cluster-network:
ipam:
config:
- subnet: 172.20.0.0/16
大师broker.xml
:
<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<bindings-directory>data/bindings</bindings-directory>
<journal-directory>data/journal</journal-directory>
<large-messages-directory>data/largemessages</large-messages-directory>
<paging-directory>data/paging</paging-directory>
<connectors>
<connector name="netty-connector">tcp://localhost:61616</connector>
<connector name="server1-connector">tcp://172.20.0.101:61617</connector>
</connectors>
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
</acceptors>
<ha-policy>
<replication>
<master>
<group-name>mynode</group-name>
<check-for-live-server>true</check-for-live-server>
<cluster-name>my-cluster</cluster-name>
</master>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>2000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="my-discovery-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty-connector</connector-ref>
<check-period>1000</check-period>
<connection-ttl>5000</connection-ttl>
<min-large-message-size>50000</min-large-message-size>
<call-timeout>5000</call-timeout>
<retry-interval>500</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<max-retry-interval>5000</max-retry-interval>
<initial-connect-attempts>-1</initial-connect-attempts>
<reconnect-attempts>-1</reconnect-attempts>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>ON_DEMAND</message-load-balancing>
<max-hops>1</max-hops>
<confirmation-window-size>32000</confirmation-window-size>
<call-failover-timeout>30000</call-failover-timeout>
<notification-interval>1000</notification-interval>
<notification-attempts>2</notification-attempts>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
</cluster-connection>
</cluster-connections>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createAddress" roles="guest"/>
<permission type="deleteAddress" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="browse" roles="guest"/>
<permission type="send" roles="guest"/>
<permission type="manage" roles="guest"/>
</security-setting>
</security-settings>
<addresses>
<address name="DLQ">
<anycast>
<queue name="DLQ"/>
</anycast>
</address>
<address name="ExpiryQueue">
<anycast>
<queue name="ExpiryQueue"/>
</anycast>
</address>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<address-settings>
<address-setting match="#">
<redistribution-delay>0</redistribution-delay>
</address-setting>
</address-settings>
</core>
</configuration>
奴隶broker.xml
:
<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<paging-directory>data/paging</paging-directory>
<bindings-directory>data/bindings</bindings-directory>
<journal-directory>data/journal</journal-directory>
<large-messages-directory>data/large-messages</large-messages-directory>
<connectors>
<connector name="netty-connector">tcp://localhost:61617</connector>
<connector name="server0-connector">tcp://172.20.0.100:61616</connector>
</connectors>
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61617</acceptor>
</acceptors>
<ha-policy>
<replication>
<slave>
<group-name>mynode</group-name>
<cluster-name>my-cluster</cluster-name>
</slave>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>2000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="my-discovery-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address/>
<connector-ref>netty-connector</connector-ref>
<check-period>1000</check-period>
<connection-ttl>5000</connection-ttl>
<min-large-message-size>50000</min-large-message-size>
<call-timeout>5000</call-timeout>
<retry-interval>500</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<max-retry-interval>5000</max-retry-interval>
<initial-connect-attempts>-1</initial-connect-attempts>
<reconnect-attempts>-1</reconnect-attempts>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>ON_DEMAND</message-load-balancing>
<max-hops>1</max-hops>
<confirmation-window-size>32000</confirmation-window-size>
<call-failover-timeout>30000</call-failover-timeout>
<notification-interval>1000</notification-interval>
<notification-attempts>2</notification-attempts>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
</cluster-connection>
</cluster-connections>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createAddress" roles="guest"/>
<permission type="deleteAddress" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="browse" roles="guest"/>
<permission type="send" roles="guest"/>
<permission type="manage" roles="guest"/>
</security-setting>
</security-settings>
<addresses>
<address name="DLQ">
<anycast>
<queue name="DLQ"/>
</anycast>
</address>
<address name="ExpiryQueue">
<anycast>
<queue name="ExpiryQueue"/>
</anycast>
</address>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<address-settings>
<address-setting match="#">
<redistribution-delay>0</redistribution-delay>
</address-setting>
</address-settings>
</core>
</configuration>
Java 客户的片段:
final String groupAddress = "231.7.7.7";
final int groupPort = 9876;
DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory udpBroadcastEndpointFactory =
new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress)
.setGroupPort(groupPort);
discoveryGroupConfiguration.setBroadcastEndpointFactory(udpBroadcastEndpointFactory);
ConnectionFactory jmsConnectionFactory =
ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
Connection jmsConnection1 = jmsConnectionFactory.createConnection();
Connection jmsConnection2 = jmsConnectionFactory.createConnection();
netty-acceptor
acceptor 必须使用容器 IP 地址来允许外部连接,即 master acceptor 应该是:
<acceptor name="netty-acceptor">tcp://172.20.0.100:61616</acceptor>
从接受者应该是:
<acceptor name="netty-acceptor">tcp://172.20.0.101:61616</acceptor>
netty-connector
必须使用容器 IP 地址,以便其他代理实例在被发现时能够连接到它,即主连接器应该是:
<connector name="netty-connector">tcp://172.20.0.100:61617</connector>
从连接器应该是:
<connector name="netty-connector">tcp://172.20.0.100:61617</connector>
Docker Compose 使部署微服务应用程序变得非常容易,但它对生产环境有一些限制。我会看一下开源 ArtemisCloud.io 项目,它是容器映像的集合,提供了一种在 Kubernetes 上部署 Apache ActiveMQ Artemis Broker 的方法。
我不知道我做错了什么。我正在尝试在 2 docker 个容器上正确配置 ActiveMQ Artemis HA 集群,但我没有在日志中看到任何关于“备份服务器”等信息。它似乎不起作用。我试图为集群制作一个简单的 Java 客户端,但它没有连接到它。请不要写“你读过文档了吗”——因为是的,我已经读过了。从我的角度来看,似乎主从之间没有任何联系,但我不知道为什么。我已经用数据配置了 docker 环境:
Docker 文件:
FROM ubuntu:latest
LABEL maintainer="Bernard"
RUN mkdir /artemis
WORKDIR /artemis
RUN apt-get update
RUN apt-get -y install wget
RUN apt-get -y install openjdk-11-jdk
RUN java --version
RUN wget -O "artemis.tar" "https://www.apache.org/dyn/closer.cgi?filename=activemq/activemq-artemis/2.18.0/apache-artemis-2.18.0-bin.tar.gz&action=download"
RUN tar -xvf ./artemis.tar; \
ln -s /artemis/apache-artemis-2.18.0/ ./current
RUN /artemis/current/bin/artemis create --user admin --password admin --http-host 0.0.0.0 --require-login --relax-jolokia bernard
EXPOSE 8161 \
9404 \
61616 \
61617 \
5445 \
5672 \
1883 \
61613
ENTRYPOINT ["/artemis/bernard/bin/artemis", "run"]
docker-compose.yml
:
version: '3'
services:
myartemis1:
build: artemis/
volumes:
- "/e/sandbox/artemis_volume/artemis1/etc:/artemis/bernard/etc"
networks:
artemis-cluster-network:
ipv4_address: 172.20.0.100
ports:
- 8161:8161
- 9404:9404
- 9876:9876
- 61616:61616
- 5445:5445
- 5672:5672
- 1883:1883
- 61613:61613
- 5432:5432
myartemis2:
build: artemis/
volumes:
- "/e/sandbox/artemis_volume/artemis2/etc:/artemis/bernard/etc"
networks:
artemis-cluster-network:
ipv4_address: 172.20.0.101
ports:
- 8162:8161
- 9405:9404
- 9877:9876
- 61618:61616
- 61617:61617
- 5446:5445
- 5673:5672
- 1884:1883
- 61614:61613
- 5433:5432
volumes:
artemis1:
artemis2:
networks:
artemis-cluster-network:
ipam:
config:
- subnet: 172.20.0.0/16
大师broker.xml
:
<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<bindings-directory>data/bindings</bindings-directory>
<journal-directory>data/journal</journal-directory>
<large-messages-directory>data/largemessages</large-messages-directory>
<paging-directory>data/paging</paging-directory>
<connectors>
<connector name="netty-connector">tcp://localhost:61616</connector>
<connector name="server1-connector">tcp://172.20.0.101:61617</connector>
</connectors>
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61616</acceptor>
</acceptors>
<ha-policy>
<replication>
<master>
<group-name>mynode</group-name>
<check-for-live-server>true</check-for-live-server>
<cluster-name>my-cluster</cluster-name>
</master>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>2000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="my-discovery-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address>jms</address>
<connector-ref>netty-connector</connector-ref>
<check-period>1000</check-period>
<connection-ttl>5000</connection-ttl>
<min-large-message-size>50000</min-large-message-size>
<call-timeout>5000</call-timeout>
<retry-interval>500</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<max-retry-interval>5000</max-retry-interval>
<initial-connect-attempts>-1</initial-connect-attempts>
<reconnect-attempts>-1</reconnect-attempts>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>ON_DEMAND</message-load-balancing>
<max-hops>1</max-hops>
<confirmation-window-size>32000</confirmation-window-size>
<call-failover-timeout>30000</call-failover-timeout>
<notification-interval>1000</notification-interval>
<notification-attempts>2</notification-attempts>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
</cluster-connection>
</cluster-connections>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createAddress" roles="guest"/>
<permission type="deleteAddress" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="browse" roles="guest"/>
<permission type="send" roles="guest"/>
<permission type="manage" roles="guest"/>
</security-setting>
</security-settings>
<addresses>
<address name="DLQ">
<anycast>
<queue name="DLQ"/>
</anycast>
</address>
<address name="ExpiryQueue">
<anycast>
<queue name="ExpiryQueue"/>
</anycast>
</address>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<address-settings>
<address-setting match="#">
<redistribution-delay>0</redistribution-delay>
</address-setting>
</address-settings>
</core>
</configuration>
奴隶broker.xml
:
<?xml version='1.0'?>
<configuration xmlns="urn:activemq" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xi="http://www.w3.org/2001/XInclude" xsi:schemaLocation="urn:activemq /schema/artemis-configuration.xsd">
<core xmlns="urn:activemq:core" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:activemq:core ">
<paging-directory>data/paging</paging-directory>
<bindings-directory>data/bindings</bindings-directory>
<journal-directory>data/journal</journal-directory>
<large-messages-directory>data/large-messages</large-messages-directory>
<connectors>
<connector name="netty-connector">tcp://localhost:61617</connector>
<connector name="server0-connector">tcp://172.20.0.100:61616</connector>
</connectors>
<acceptors>
<acceptor name="netty-acceptor">tcp://localhost:61617</acceptor>
</acceptors>
<ha-policy>
<replication>
<slave>
<group-name>mynode</group-name>
<cluster-name>my-cluster</cluster-name>
</slave>
</replication>
</ha-policy>
<broadcast-groups>
<broadcast-group name="my-broadcast-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<broadcast-period>2000</broadcast-period>
<connector-ref>netty-connector</connector-ref>
</broadcast-group>
</broadcast-groups>
<discovery-groups>
<discovery-group name="my-discovery-group">
<group-address>231.7.7.7</group-address>
<group-port>9876</group-port>
<refresh-timeout>10000</refresh-timeout>
</discovery-group>
</discovery-groups>
<cluster-connections>
<cluster-connection name="my-cluster">
<address/>
<connector-ref>netty-connector</connector-ref>
<check-period>1000</check-period>
<connection-ttl>5000</connection-ttl>
<min-large-message-size>50000</min-large-message-size>
<call-timeout>5000</call-timeout>
<retry-interval>500</retry-interval>
<retry-interval-multiplier>1.0</retry-interval-multiplier>
<max-retry-interval>5000</max-retry-interval>
<initial-connect-attempts>-1</initial-connect-attempts>
<reconnect-attempts>-1</reconnect-attempts>
<use-duplicate-detection>true</use-duplicate-detection>
<message-load-balancing>ON_DEMAND</message-load-balancing>
<max-hops>1</max-hops>
<confirmation-window-size>32000</confirmation-window-size>
<call-failover-timeout>30000</call-failover-timeout>
<notification-interval>1000</notification-interval>
<notification-attempts>2</notification-attempts>
<discovery-group-ref discovery-group-name="my-discovery-group"/>
</cluster-connection>
</cluster-connections>
<security-settings>
<security-setting match="#">
<permission type="createNonDurableQueue" roles="guest"/>
<permission type="deleteNonDurableQueue" roles="guest"/>
<permission type="createDurableQueue" roles="guest"/>
<permission type="deleteDurableQueue" roles="guest"/>
<permission type="createAddress" roles="guest"/>
<permission type="deleteAddress" roles="guest"/>
<permission type="consume" roles="guest"/>
<permission type="browse" roles="guest"/>
<permission type="send" roles="guest"/>
<permission type="manage" roles="guest"/>
</security-setting>
</security-settings>
<addresses>
<address name="DLQ">
<anycast>
<queue name="DLQ"/>
</anycast>
</address>
<address name="ExpiryQueue">
<anycast>
<queue name="ExpiryQueue"/>
</anycast>
</address>
<address name="exampleQueue">
<anycast>
<queue name="exampleQueue"/>
</anycast>
</address>
</addresses>
<address-settings>
<address-setting match="#">
<redistribution-delay>0</redistribution-delay>
</address-setting>
</address-settings>
</core>
</configuration>
Java 客户的片段:
final String groupAddress = "231.7.7.7";
final int groupPort = 9876;
DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
UDPBroadcastEndpointFactory udpBroadcastEndpointFactory =
new UDPBroadcastEndpointFactory().setGroupAddress(groupAddress)
.setGroupPort(groupPort);
discoveryGroupConfiguration.setBroadcastEndpointFactory(udpBroadcastEndpointFactory);
ConnectionFactory jmsConnectionFactory =
ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
Connection jmsConnection1 = jmsConnectionFactory.createConnection();
Connection jmsConnection2 = jmsConnectionFactory.createConnection();
netty-acceptor
acceptor 必须使用容器 IP 地址来允许外部连接,即 master acceptor 应该是:
<acceptor name="netty-acceptor">tcp://172.20.0.100:61616</acceptor>
从接受者应该是:
<acceptor name="netty-acceptor">tcp://172.20.0.101:61616</acceptor>
netty-connector
必须使用容器 IP 地址,以便其他代理实例在被发现时能够连接到它,即主连接器应该是:
<connector name="netty-connector">tcp://172.20.0.100:61617</connector>
从连接器应该是:
<connector name="netty-connector">tcp://172.20.0.100:61617</connector>
Docker Compose 使部署微服务应用程序变得非常容易,但它对生产环境有一些限制。我会看一下开源 ArtemisCloud.io 项目,它是容器映像的集合,提供了一种在 Kubernetes 上部署 Apache ActiveMQ Artemis Broker 的方法。