rocketmq集群搭建

1.准备两个linux服务器

        

10.230.198.120master1 slave2
10.230.198.121master2 slave1

2.配置host文件

        修改配置文件hosts    vim /etc/hosts

        #nameserver
        10.230.198.120   rocketmq-nameserver1
        10.230.198.121   rocketmq-nameserver2
        #broker 
        10.230.198.120   rocketmq-master1
        10.230.198.120   rocketmq-slave2
        10.230.198.121   rocketmq-master2
        10.230.198.121   rocketmq-slave1

        配置完成后重启网卡  systemctl restart network

3.防火墙配置

        #关闭防火墙
        systemctl stop firewalld.service
        #查看防火墙状态
        firewall-cmd --state
        或者systemctl status firewalld.service
        #禁止防火墙开机自启动
        systemctl disable firewalld.service

4.环境变量配置

        vim /etc/profile
        在profile文件的尾部加上如下命令
        #set rocketmq
        ROCKETMQ_HOME=/home/rocketMQ/rocketmq-4.9.3
        PATH=$PATH:$ROCKETMQ_HOME/bin
        export ROCKETMQ_HOME PATH
        输入保存wq!退出,立即生效 source /etc/profile

5.创建消息存放路径

        mkdir /home/rocketMQ/store
        mkdir /home/rocketMQ/store/commitlog
        mkdir /home/rocketMQ/store/consumequeue
        mkdir /home/rocketMQ/store/index

6.配置broker文件,双主双从,同步配置

        1)进入目录/home/rocketMQ/rocketmq-4.9.3/conf/2m-2s-sync,查看到如下文件

            broker-a.properties
            broker-a-s.properties
            broker-b.properties
            broker-b-s.properties

        2)broker-a.properties文件,在服务器10.230.198.120上配置

        #所属集群名字
            brokerClusterName=rocketmq-cluster
            #broker名字,注意此处不同的配置文件填写的不一样
            brokerName=broker-a
            #0 表示 Master,>0 表示 Slave
            brokerId=0
            #nameServer地址,分号分割
            namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
            #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
            defaultTopicQueueNums=4
            #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
            autoCreateTopicEnable=true
            #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
            autoCreateSubscriptionGroup=true
            #Broker 对外服务的监听端口
            listenPort=10911
            #删除文件时间点,默认凌晨 4点
            deleteWhen=04
            #文件保留时间,默认 48 小时
            fileReservedTime=120
            #commitLog每个文件的大小默认1G
            mapedFileSizeCommitLog=1073741824
            #ConsumeQueue每个文件默认存30W条,根据业务情况调整
            mapedFileSizeConsumeQueue=300000
            #destroyMapedFileIntervalForcibly=120000
            #redeleteHangedFileInterval=120000
            #检测物理文件磁盘空间
            diskMaxUsedSpaceRatio=88
            #存储路径
            storePathRootDir=/home/rocketMQ/store
            #commitLog 存储路径
            storePathCommitLog=/home/rocketMQ/store/commitlog
            #消费队列存储路径存储路径
            storePathConsumeQueue=/home/rocketMQ/store/consumequeue
            #消息索引存储路径
            storePathIndex=/home/rocketMQ/store/index
            #checkpoint 文件存储路径
            storeCheckpoint=/home/rocketMQ/store/checkpoint
            #abort 文件存储路径
            abortFile=/home/rocketMQ/store/abort
            #限制的消息大小
            maxMessageSize=65536
            #flushCommitLogLeastPages=4
            #flushConsumeQueueLeastPages=2
            #flushCommitLogThoroughInterval=10000
            #flushConsumeQueueThoroughInterval=60000
            #Broker 的角色
            #- ASYNC_MASTER 异步复制Master
            #- SYNC_MASTER 同步双写Master
            #- SLAVE
            brokerRole=ASYNC_MASTER
            #刷盘方式
            #- ASYNC_FLUSH 异步刷盘
            #- SYNC_FLUSH 同步刷盘
            flushDiskType=ASYNC_FLUSH
            #checkTransactionMessageEnable=false
            #发消息线程池数量
            #sendMessageThreadPoolNums=128
            #拉消息线程池数量
            #pullMessageThreadPoolNums=128

        3)broker-b-s.properties文件,在服务器10.230.198.120上配置

        #所属集群名字
            brokerClusterName=rocketmq-cluster
            #broker名字,注意此处不同的配置文件填写的不一样
            brokerName=broker-b
            #0 表示 Master,>0 表示 Slave
            brokerId=1
            #nameServer地址,分号分割
            namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
            #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
            defaultTopicQueueNums=4
            #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
            autoCreateTopicEnable=true
            #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
            autoCreateSubscriptionGroup=true
            #Broker 对外服务的监听端口
            listenPort=11011
            #删除文件时间点,默认凌晨 4点
            deleteWhen=04
            #文件保留时间,默认 48 小时
            fileReservedTime=120
            #commitLog每个文件的大小默认1G
            mapedFileSizeCommitLog=1073741824
            #ConsumeQueue每个文件默认存30W条,根据业务情况调整
            mapedFileSizeConsumeQueue=300000
            #destroyMapedFileIntervalForcibly=120000
            #redeleteHangedFileInterval=120000
            #检测物理文件磁盘空间
            diskMaxUsedSpaceRatio=88
            #存储路径
            storePathRootDir=/home/rocketMQ/store
            #commitLog 存储路径
            storePathCommitLog=/home/rocketMQ/store/commitlog
            #消费队列存储路径存储路径
            storePathConsumeQueue=/home/rocketMQ/store/consumequeue
            #消息索引存储路径
            storePathIndex=/home/rocketMQ/store/index
            #checkpoint 文件存储路径
            storeCheckpoint=/home/rocketMQ/store/checkpoint
            #abort 文件存储路径
            abortFile=/home/rocketMQ/store/abort
            #限制的消息大小
            maxMessageSize=65536
            #flushCommitLogLeastPages=4
            #flushConsumeQueueLeastPages=2
            #flushCommitLogThoroughInterval=10000
            #flushConsumeQueueThoroughInterval=60000
            #Broker 的角色
            #- ASYNC_MASTER 异步复制Master
            #- SYNC_MASTER 同步双写Master
            #- SLAVE
            brokerRole=SLAVE
            #刷盘方式
            #- ASYNC_FLUSH 异步刷盘
            #- SYNC_FLUSH 同步刷盘
            flushDiskType=ASYNC_FLUSH
            #checkTransactionMessageEnable=false
            #发消息线程池数量
            #sendMessageThreadPoolNums=128
            #拉消息线程池数量
            #pullMessageThreadPoolNums=128

        4)broker-b.properties文件,在服务器10.230.198.121上配置

        #所属集群名字
            brokerClusterName=rocketmq-cluster
            #broker名字,注意此处不同的配置文件填写的不一样
            brokerName=broker-b
            #0 表示 Master,>0 表示 Slave
            brokerId=0
            #nameServer地址,分号分割
            namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
            #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
            defaultTopicQueueNums=4
            #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
            autoCreateTopicEnable=true
            #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
            autoCreateSubscriptionGroup=true
            #Broker 对外服务的监听端口
            listenPort=10911
            #删除文件时间点,默认凌晨 4点
            deleteWhen=04
            #文件保留时间,默认 48 小时
            fileReservedTime=120
            #commitLog每个文件的大小默认1G
            mapedFileSizeCommitLog=1073741824
            #ConsumeQueue每个文件默认存30W条,根据业务情况调整
            mapedFileSizeConsumeQueue=300000
            #destroyMapedFileIntervalForcibly=120000
            #redeleteHangedFileInterval=120000
            #检测物理文件磁盘空间
            diskMaxUsedSpaceRatio=88
            #存储路径
            storePathRootDir=/home/rocketMQ/store
            #commitLog 存储路径
            storePathCommitLog=/home/rocketMQ/store/commitlog
            #消费队列存储路径存储路径
            storePathConsumeQueue=/home/rocketMQ/store/consumequeue
            #消息索引存储路径
            storePathIndex=/home/rocketMQ/store/index
            #checkpoint 文件存储路径
            storeCheckpoint=/home/rocketMQ/store/checkpoint
            #abort 文件存储路径
            abortFile=/home/rocketMQ/store/abort
            #限制的消息大小
            maxMessageSize=65536
            #flushCommitLogLeastPages=4
            #flushConsumeQueueLeastPages=2
            #flushCommitLogThoroughInterval=10000
            #flushConsumeQueueThoroughInterval=60000
            #Broker 的角色
            #- ASYNC_MASTER 异步复制Master
            #- SYNC_MASTER 同步双写Master
            #- SLAVE
            brokerRole=ASYNC_MASTER
            #刷盘方式
            #- ASYNC_FLUSH 异步刷盘
            #- SYNC_FLUSH 同步刷盘
            flushDiskType=ASYNC_FLUSH
            #checkTransactionMessageEnable=false
            #发消息线程池数量
            #sendMessageThreadPoolNums=128
            #拉消息线程池数量
            #pullMessageThreadPoolNums=128

        5)broker-a-s.properties文件,在服务器10.230.198.121上配置

        #所属集群名字
            brokerClusterName=rocketmq-cluster
            #broker名字,注意此处不同的配置文件填写的不一样
            brokerName=broker-a
            #0 表示 Master,>0 表示 Slave
            brokerId=1
            #nameServer地址,分号分割
            namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
            #在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
            defaultTopicQueueNums=4
            #是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
            autoCreateTopicEnable=true
            #是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
            autoCreateSubscriptionGroup=true
            #Broker 对外服务的监听端口
            listenPort=11011
            #删除文件时间点,默认凌晨 4点
            deleteWhen=04
            #文件保留时间,默认 48 小时
            fileReservedTime=120
            #commitLog每个文件的大小默认1G
            mapedFileSizeCommitLog=1073741824
            #ConsumeQueue每个文件默认存30W条,根据业务情况调整
            mapedFileSizeConsumeQueue=300000
            #destroyMapedFileIntervalForcibly=120000
            #redeleteHangedFileInterval=120000
            #检测物理文件磁盘空间
            diskMaxUsedSpaceRatio=88
            #存储路径
            storePathRootDir=/home/rocketMQ/store
            #commitLog 存储路径
            storePathCommitLog=/home/rocketMQ/store/commitlog
            #消费队列存储路径存储路径
            storePathConsumeQueue=/home/rocketMQ/store/consumequeue
            #消息索引存储路径
            storePathIndex=/home/rocketMQ/store/index
            #checkpoint 文件存储路径
            storeCheckpoint=/home/rocketMQ/store/checkpoint
            #abort 文件存储路径
            abortFile=/home/rocketMQ/store/abort
            #限制的消息大小
            maxMessageSize=65536
            #flushCommitLogLeastPages=4
            #flushConsumeQueueLeastPages=2
            #flushCommitLogThoroughInterval=10000
            #flushConsumeQueueThoroughInterval=60000
            #Broker 的角色
            #- ASYNC_MASTER 异步复制Master
            #- SYNC_MASTER 同步双写Master
            #- SLAVE
            brokerRole=SLAVE
            #刷盘方式
            #- ASYNC_FLUSH 异步刷盘
            #- SYNC_FLUSH 同步刷盘
            flushDiskType=ASYNC_FLUSH
            #checkTransactionMessageEnable=false
            #发消息线程池数量
            #sendMessageThreadPoolNums=128
            #拉消息线程池数量
            #pullMessageThreadPoolNums=128

7.修改脚本文件

        1)vim /home/rocketMQ/bin/runbroker.sh

        # 开发环境JVM Configuration
            #============================================================
            JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn128m"

        2)vim /usr/local/rocketmq/bin/runserver.sh

        JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn128m -XX:PermSize=128m -XX:MaxPermSize=320m"

8.服务启动

        1)分别在10.230.198.120和10.230.198.121服务器上启动NameServer

            cd /home/rocketMQ/bin
            nohup sh mqnamesrv &

        2)启动broker集群

        在10.230.198.120,启动master1和slave2
        master1:
            cd /home/rocketMQ/bin
            nohup sh mqbroker -c /home/rocketMQ/rocketmq-4.9.3/conf/2m-2s-sync/broker-a.properties &
        slave2:
            cd /home/rocketMQ/bin
            nohup sh mqbroker -c /home/rocketMQ/rocketmq-4.9.3/conf/2m-2s-sync/broker-b-s.properties &
      在10.230.198.121,启动master2和slave1
      master2:
            cd /home/rocketMQ/bin
            nohup sh mqbroker -c /home/rocketMQ/rocketmq-4.9.3/conf/2m-2s-sync/broker-b.properties &
      slave1:
            cd /home/rocketMQ/bin
            nohup sh mqbroker -c /home/rocketMQ/rocketmq-4.9.3/conf/2m-2s-sync/broker-a-s.properties &

        3)启动后用jps可以查看进程

  • 8
    点赞
  • 22
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值