一、简介
Master-Slave集群:
由至少3个节点组成,一个Master节点,其他为Slave节点。只有Master节点对外提供服务,Slave节点处于等待状态。当主节点宕机后,从节点会推举出一个节点出来成为新的Master节点,继续提供服务。
优点是可以解决多服务热备的高可用问题,缺点是无法解决负载均衡和分布式的问题。
Broker Cluster集群:
Broker-Cluster部署方式中,各个broker通过网络互相连接,并共享queue。当broker-A上面指定的queue-A中接收到一个message处于pending状态,而此时没有consumer连接broker-A时。如果cluster中的broker-B上面有一个consumer在消费queue-A的消息,那么broker-B会先通过内部网络获取到broker-A上面的message,并通知自己的consumer来消费。
优点是可以解决负载均衡和分布式的问题。但不支持高可用。
所以,最完美的解决方案是将两者结合起来。
1、集群规划:
Broker-a | |||||||
集群成员 | 端口 | ||||||
openwire | amqp | stomp | mqtt | ws | Admin Port | ||
192.168.2.86 | 61619 | 5675 | 61643 | 1886 | 61644 | 8191 |
Broker-b | |||||||
集群成员 | 端口 | ||||||
openwire | amqp | stomp | mqtt | ws | Admin Port | ||
192.168.2.86 | 61719 | 6675 | 61743 | 2886 | 61744 | 8291 |
2、下载MQ安装包:
http://archive.apache.org/dist/activemq/5.14.4/apache-activemq-5.14.4-bin.tar.gz
3、安装JDK
yum –y install java-1.7.0-openjdk*
192.168.2.86上操作
解压安装包
tar –zxf apache-activemq-5.14.4-bin.tar.gz
mv apache-activemq-5.14.4 activemq-cluster1 #broker-a集群
cp –r activemq-cluster1 activemq-cluster2 #broker-b集群
Master-Slave基于Zookeeper。
修改activemq-cluster1的activemq.xml文件
vi activemq-cluster1/conf/activemq.xml
broker-a的配置:
<brokerxmlns="http://activemq.apache.org/schema/core"brokerName="broker-a" schedulerSupport="true"dataDirectory="${activemq.data}">
<persistenceAdapter>
<replicatedLevelDB
directory="${activemq.data}/leveldb"
replicas="3"
bind="tcp://0.0.0.0:0"
zkAddress="192.168.2.93:2281,192.168.2.93:2381,192.168.2.93:2481"
zkPassword=""
hostname="192.168.2.86"
sync="local_disk"
zkPath="/activemq/leveldb-stores"
/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and framesize to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61619?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp"uri="amqp://0.0.0.0:5675?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp" uri="stomp://0.0.0.0:61643?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="mqtt"uri="mqtt://0.0.0.0:1886?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws"uri="ws://0.0.0.0:61644?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
修改activemq-cluster2的activemq.xml文件
vi activemq-cluster2/conf/activemq.xml
broker-b的配置:
<brokerxmlns="http://activemq.apache.org/schema/core"brokerName="broker-b" schedulerSupport="true"dataDirectory="${activemq.data}">
<persistenceAdapter>
<replicatedLevelDB
directory="${activemq.data}/leveldb"
replicas="3"
bind="tcp://0.0.0.0:0"
zkAddress="192.168.2.93:2281,192.168.2.93:2381,192.168.2.93:2481"
zkPassword=""
hostname="192.168.2.86"
sync="local_disk"
zkPath="/activemq/leveldb-stores2"
/>
</persistenceAdapter>
<transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and framesize to 100MB -->
<transportConnector name="openwire"uri="tcp://0.0.0.0:61719?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="amqp"uri="amqp://0.0.0.0:6675?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="stomp"uri="stomp://0.0.0.0:61743?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnectorname="mqtt"uri="mqtt://0.0.0.0:2886?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
<transportConnector name="ws"uri="ws://0.0.0.0:61744?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
brokerName一致才会认为是同一个Master-Slavecluster,且至少有3个才会成功,否则无法选主,导致没有broker可以提供服务。
broker-a配置文件加入以下内容:
<networkConnectors>
<networkConnectoruri="masterslave:(tcp://192.168.2.86:61719,tcp://192.168.2.87:61719,tcp://192.168.2.88:61719)"/>
</networkConnectors>
broker-b配置文件加入以下内容:
<networkConnectors>
<networkConnectoruri="masterslave:(tcp://192.168.2.86:61619,tcp://192.168.2.87:61619,tcp://192.168.2.88:61619)"/>
</networkConnectors>
然后把activemq-cluster1、activemq-cluster2目录分别拷贝到192.168.2.87,192.168.2.88
scp –r activemq-cluster1/ 192.168.2.87:~/
scp –r activemq-cluster1/ 192.168.2.88:~/
scp –r activemq-cluster2/ 192.168.2.87:~/
scp –r activemq-cluster2/ 192.168.2.88:~/
启动broker-a (3个节点)和 broker-b(3个节点)
每台服务器执行以下命令:
activemq-cluster1/bin/activemq start
activemq-cluster2/bin/activemq start
查看日志可以看到2个broker直接建立链接的log
Broker-a
INFO | Successfully connected to tcp://192.168.2.87:61719
INFO | Network connection between vm://broker-a#0 andtcp://192.168.2.87:61719 (broker-b) has been established.
Broker-b
Network connection between vm://broker-b#6and tcp://192.168.2.88:61619 (broker-a) has been established. |
本文出自 “12666522” 博客,请务必保留此出处http://12676522.blog.51cto.com/12666522/1922537
ActiveMQ集群Master-Slave + Broker Cluster模式
原文地址:http://12676522.blog.51cto.com/12666522/1922537