RocketMQ双主双备集群搭建

RocketMQ双主双备集群搭建

一、RocketMQ

RocketMQ是阿里巴巴旗下一款开源的MQ框架,经历过双十一考研、Java编程语言实现,有非常好完整生态系统。
相比于Rabbitmq、kafka具有主要优势特性有:

  1. 支持事务消息(能够解决分布式事务的问题)
  2. 支持顺序消息(底层已经使用内存队列实现)
  3. 支持consumer端tag过滤,减少不必要的网络传输

二、集群结构

RocketMQ双主双备集群搭建
Name Server 服务注册发现 用于生产者获取Broker节点信息 类似eureka存储节点注册信息 去中心化思想

Broker 存储和负责转发消息 默认10911

Producer 生产者

Consumer 消费者

三、使用Docker搭建双主双备集群

主机 用途
192.168.40.128 namesrv-1,broker-a(slave), rocketmq-console
192.168.40.129 namesrv-2,broker-b(slave)
192.168.40.130 broker-a (master)
192.168.40.131 broker-b (master)
  1. 所有服务器都需拉取镜像

    docker pull rocketmqinc/rocketmq
    

1.启动namesrv

128、129 服务器启动namesrv

  1. 先创建挂载目录

    mkdir -p /home/rocketmq/namesrv/logs
    mkdir -p /home/rocketmq/namesrv/store
    
  2. 启动namesrv服务

    docker run -itd \
    --name rmqnamesrv \
    -p 9876:9876 \
    -v /home/rocketmq/namesrv/logs:/root/logs \
    -v /home/rocketmq/namesrv/store:/root/store \
    -e "MAX_POSSIBLE_HEAP=100000000" \
    rocketmqinc/rocketmq sh mqnamesrv
    

2.启动broker

所有服务器都需启动broker服务,

  1. 先创建挂载目录

    mkdir -p /home/rocketmq/broker/logs
    mkdir -p /home/rocketmq/broker/store
    mkdir -p /home/rocketmq/broker/conf
    
  2. 所有服务器创建broker.conf文件。

    vim /home/rocketmq/broker/conf/broker.conf
    
  3. 130 服务器 broker.conf(broker-a master )

    brokerClusterName = DefaultCluster
    brokerName = broker-a
    brokerId = 0
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    brokerIP1 = 192.168.40.130
    autoCreateTopicEnable=true
    namesrvAddr=192.168.40.128:9876;192.168.40.129:9876
    
  4. 128 服务器 broker.conf(broker-a slave)

    brokerClusterName = DefaultCluster
    brokerName = broker-a
    brokerId = 1
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    brokerIP1 = 192.168.40.128
    autoCreateTopicEnable=true
    namesrvAddr=192.168.40.128:9876;192.168.40.129:9876
    
  5. 131 服务器 broker.conf(broker-b master )

    brokerClusterName = DefaultCluster
    brokerName = broker-b
    brokerId = 0
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    brokerIP1 = 192.168.40.131
    autoCreateTopicEnable=true
    namesrvAddr=192.168.40.128:9876;192.168.40.129:9876
    
  6. 129 服务器 broker.conf(broker-b slave)

    brokerClusterName = DefaultCluster
    brokerName = broker-b
    brokerId = 1
    deleteWhen = 04
    fileReservedTime = 48
    brokerRole = ASYNC_MASTER
    flushDiskType = ASYNC_FLUSH
    brokerIP1 = 192.168.40.129
    autoCreateTopicEnable=true
    namesrvAddr=192.168.40.128:9876;192.168.40.129:9876
    
  7. 参数说明
    brokerClusterName: 为集群名称,所有的都填写一致才为一个群体。
    brokerName: 集群中每个节点的名称。
    brokerId: 当 brokerId 等于 0 时该节点为master节点,大于 0 为slave节点。
    namesrvAddr:namesrv的地址。

  8. 所有服务器启动broker服务。

    docker run -itd --name rmqbroker \
    -p 10911:10911 -p 10909:10909 \
    -v  /home/rocketmq/broker/logs:/root/logs \
    -v  /home/rocketmq/broker/store:/root/store \
    -v  /home/rocketmq/broker/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf \
    -e "NAMESRV_ADDR=192.168.40.128:9876;192.168.40.129:9876" \
    -e "MAX_POSSIBLE_HEAP=200000000" \
    rocketmqinc/rocketmq sh mqbroker -c ../conf/broker.conf
    

3.安装控制台

  1. 拉取镜像

    docker pull styletang/rocketmq-console-ng
    
  2. 启动

    docker run -itd --name rocketmq-console \
    -e "JAVA_OPTS=-Drocketmq.config.namesrvAddr=192.168.40.128:9876;192.168.40.129:9876 -Drocketmq.config.isVIPChannel=false" \
    -p 8096:8080 \
    styletang/rocketmq-console-ng
    

4.释放端口

每台服务器都需释放端口。

firewall-cmd --zone=public --add-port=9876/tcp --permanent
firewall-cmd --zone=public --add-port=10911/tcp --permanent
firewall-cmd --zone=public --add-port=10909/tcp --permanent
firewall-cmd --zone=public --add-port=8096/tcp --permanent
firewall-cmd --reload

5.控制台效果

RocketMQ双主双备集群搭建

RocketMQ双主双备集群搭建

上一篇:RocketMQ系列:mqadmin命令行之broker操作


下一篇:Error: <spyOn> : handleError() method does not exist