activeMQ集群实现负载均衡和高可用

关于更多activeMQ的实践(学习记录)请移步:https://gitee.com/ikgwr/activemq
在这里插入图片描述

节点服务端口管理端口存储网络连接器用途
Node-A616168161-Node-B、Node-C消费者
Node-B616178162/activemq/kahadb/Node-A生产者、消费者
Node-C616188163/activemq/kahadb/Node-A生产者、消费者

1、创建三个activeMQ服务器

cp -rf apache-activemq-5.15.9 activemq/activemq-a
cp -rf apache-activemq-5.15.9 activemq/activemq-b
cp -rf apache-activemq-5.15.9 activemq/activemq-c

2、创建kahadb目录,作为Master/Slave集群使用的共享储存文件夹

cd activemq/
mkdir kahadb

3、编辑activemq-a下配置文件/conf/activemq.xml以及/conf/jetty.xml,注释其他协议,保留tcp协议,并添加网络连接配置项

<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
    <!-- the default port number for the web console -->
    <property name="host" value="0.0.0.0"/>
    <property name="port" value="8161"/>
</bean>
<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"/> -->
</transportConnectors>

<networkConnectors>
    <networkConnector name="local_network" uri="static:(tcp://127.0.0.1:61617,tcp://127.0.0.1:61618)"/>
</networkConnectors>

5、编辑activemq-b下配置文件/conf/activemq.xml以及/conf/jetty.xml,注释其他协议,保留tcp协议,修改端口号,并添加网络连接配置项。因为B/C节点需要配置成Master/Slave,所以要修改共享存储文件的目录。

<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
    <!-- the default port number for the web console -->
    <property name="host" value="0.0.0.0"/>
    <property name="port" value="8162"/>
</bean>
<persistenceAdapter>
    <kahaDB directory="/software/activemq/kahadb"/>
</persistenceAdapter>
<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61617?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"/> -->
</transportConnectors>

<networkConnectors>
    <networkConnector name="network_a" uri="static:(tcp://127.0.0.1:61616)"/>
</networkConnectors>

6、编辑activemq-c下配置文件/conf/activemq.xml以及/conf/jetty.xml,注释其他协议,保留tcp协议,修改端口号,并添加网络连接配置项。因为B/C节点需要配置成Master/Slave,所以要修改共享存储文件的目录。

<bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
    <!-- the default port number for the web console -->
    <property name="host" value="0.0.0.0"/>
    <property name="port" value="8163"/>
</bean>
<persistenceAdapter>
    <kahaDB directory="/software/activemq/kahadb"/>
</persistenceAdapter>
<transportConnectors>
    <!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
    <transportConnector name="openwire" uri="tcp://0.0.0.0:61618?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"/> -->
</transportConnectors>

<networkConnectors>
    <networkConnector name="network_a" uri="static:(tcp://127.0.0.1:61616)"/>
</networkConnectors>

7、分别启动a/b/c节点

./software/activemq/activemq-a/bin/activemq start
./software/activemq/activemq-b/bin/activemq start
./software/activemq/activemq-c/bin/activemq start

8、查看对应端口,a/b节点已启动并监听相关端口,c节点在等待获得资源,没有启动提供服务

netstat -anp|grep 61616
netstat -anp|grep 61617
netstat -anp|grep 61618

在这里插入图片描述

9、停掉b节点,c节点启动提供服务

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值