单机下RocketMq安装-多Master模式

发布时间 2023-06-11 18:14:19作者: 风里密码1900

在指定目录下新建文件夹rocketmq,并下载安装包到目录下

cd /usr/local
mkdir rocketmq
wget https://dist.apache.org/repos/dist/release/rocketmq/5.1.1/rocketmq-all-5.1.1-bin-release.zip

安装unzip,并解压压缩包

yum install -y unzip zip
unzip rocketmq-all-5.1.1-bin-release.zip

 创建存储相关路径

cd /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release
mkdir -p store store/commitlog store/consumequeue

进到bin目录里编辑broker.conf文件,cd /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin

官方broker说明文档:https://github.com/apache/rocketmq/blob/master/docs/cn/best_practice.md

原broker.conf文件内容如下

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

#集群名称 brokerClusterName = DefaultCluster

#broker名称 brokerName = broker-a

#broekrId #0 表示 Master,>0 表示 Slave brokerId = 0

#删除时间凌晨4点 deleteWhen = 04

#文件保留时间,默认48小时 fileReservedTime = 48

#broker的角色
#ASYNC_MASTER异步复制master
#SYNC_MASTER 同步双写Master brokerRole = ASYNC_MASTER

#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType = ASYNC_FLUSH

追加属性后的broker.conf文件

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements.  See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License.  You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.

#集群名称
brokerClusterName = DefaultCluster 

#broker名称
brokerName = broker-a

#broekrId #0 表示 Master,>0 表示 Slave
brokerId = 0

#在每天的什么时间删除已经超过文件保留时间的 commit log
deleteWhen = 04

#文件保留时间,默认48小时
fileReservedTime = 48

#broker的角色
#ASYNC_MASTER异步复制master
#SYNC_MASTER 同步双写Master
brokerRole = ASYNC_MASTER

#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType = ASYNC_FLUSH

#监听端口
listenPort=10911

#nameserver地址,多个地址时用分号(;)分割
namesrvAddr=公网ip:9876

#存储根路径
storePathRootDir=/usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/store

#存储commitlog路径
storePathCommitLog=/usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/store/commitlog

#当前broker监听的ip
brokerIP1=公网ip

#存在主从 broker 时,如果在 broker 主节点上配置了 brokerIP2 属性,#broker 从节点会连接主节点配置的 brokerIP2 进行同步
brokerIP2=公网ip

#是否自动创建topic
autoCreateTopicEnable=true

 

进入到 /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin 目录下,根据内存大小,对JVM参数进行调整,runbroker.sh 文件和 runserver.sh 文件,修改内存大小

修改runbroker.sh文件

 

修改runserver.sh 文件

 

如果内存太小启动失败,查看应用内存情况 ,并清空缓存内存,再次尝试启动

--清除缓存
echo 1 > /proc/sys/vm/drop_caches --清除pagecache
echo 2 > /proc/sys/vm/drop_caches --清除回收slab分配器中的对象(包括目录项缓存和inode缓存)。slab分配器是内核中管理内存的一种机制,其中很多缓存数据实现都是用的pagecache
echo 3 > /proc/sys/vm/drop_caches --清除pagecache和slab分配器中的缓存对象

 

启动和关闭 rocketmq nameserver

#启动,并打印日志到文件
nohup sh /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin/mqnamesrv >/usr/local/rocketmq/mqnamesrv.log 2>&1 & #关闭 sh /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin/mqshutdown namesrv

 

启动broker

#启动broker,并打印日志到相关文件
nohup sh /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin/mqnamesrv >/usr/local/rocketmq/mqnamesrv.log 2>&1 &

 

使用 jps-l 命令 查看是否启动成功

 

================================================================================================================================================================================================

配置Master2

进入bin目录下创建配置文件broke_b.conf,文件内容如下

#集群名称
brokerClusterName = DefaultCluster

#broker名称
brokerName = broker-b

#0表示master > 0表示save
brokerId = 0

#删除commitlog文件时间点,默认凌晨4点
deleteWhen = 04

#文件保留时间,默认48小时
fileReservedTime = 48

#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole = ASYNC_MASTER


#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType = ASYNC_FLUSH


listenPort=11911
namesrvAddr=120.53.239.169:9876
storePathRootDir=/usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/store_a
storePathCommitLog=/usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/store_a/commitlog
storePathConsumerQueue=/usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/store_a/consumequeue
brokerIP1=120.53.239.169
brokerIP2=120.53.239.169
autoCreateTopicEnable=true

备注:复制原broker.conf文件后修改相应存储文件路径、broker监听的端口,broker名称即可

启动broker-b

nohup sh /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/bin/mqbroker -c /usr/local/rocketmq/rocketmq-all-5.1.1-bin-release/conf/broker_b.conf  >/usr/local/rocketmq/broker_b.log 2>&1 & 

 

查看集群