RocketMQ两主两从部署搭建

安装部署
1.1 部署环境
在这里插入图片描述

1.2 安装要求
建议使用64位操作系统,建议使用Linux / Unix / Mac;
64位JDK 1.8+;
Maven 3.2.x;(非必要)
Git;(非必要)
1.3 获取rocketmq安装包,并解压
下载官方RocketMQ压缩包,各版本下载页面:http://rocketmq.apache.org/release_notes/
source版本为需要自己编译的版本,bin版本直接解压即可。

cd /app
wget https://mirrors.bfsu.edu.cn/apache/rocketmq/4.5.2/rocketmq-all-4.5.2-bin-release.zip
unzip rocketmq-all-4.5.2-bin-release.zip
mv rocketmq-all-4.5.2-bin-release rocketmq
cd /app/rocketmq/bin
vim runbroker.sh
    #默认值为生产环境配置,虚机需要修改,不能低于1g
    #JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
    JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"
vim runserver.sh
    #默认值为生产环境配置,虚机需要修改,不能低于1g
    #JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
    JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspacSize=128m -XX:MaxMetaspaceSize=320m"

1.4 创建配置文件目录

mkdir -p /app/rocketmq/rocketmq-a/{conf,store,logs}
mkdir -p /app/rocketmq/rocketmq-a/store/{index,commitlog,consumequeue}

其他rocketmq实例参照上面创建。
批量修改conf下日志文件的配置,将配置中所有的${user.home}变量替换为/app/rocketmq/。

cd /app/rocetmq/conf && sed -i 's#${user.home}#/app/rocketmq#g' *.xml

1.5 修改配置文件
编辑broker-a.properties

vim /app/rocketmq/rocketmq-a-m/conf/broker-a.properties
# 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=rocketmq-csf
brokerName=broker-a
#0 表示 Master>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=192.168.1.40:9876;192.168.1.41:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口,10911为默认值
listenPort=10911
#Master监听slave请求端口,用于主从同步,默认为服务端口+1
haListenPort=10912
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/app/rocketmq/rocketmq-a/store
#commitLog 存储路径
storePathCommitLog=/app/rocketmq/rocketmq-a/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/app/rocketmq/rocketmq-a/store/consumequeue
#消息索引存储路径
storePathIndex=/app/rocketmq/rocketmq-a/store/index
#checkpoint 文件存储路径
storeCheckpoint=/app/rocketmq/rocketmq-a/store/checkpoint
#abort 文件存储路径
abortFile=/app/rocketmq/rocketmq-a/store/abort
#限制的消息大小
maxMessageSize=65536
#flushCommitLogLeastPages=4
#flushConsumeQueueLeastPages=2
#flushCommitLogThoroughInterval=10000
#flushConsumeQueueThoroughInterval=60000
#Broker 的角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=SYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
#checkTransactionMessageEnable=false
#发消息线程池数量
#sendMessageThreadPoolNums=128
#拉消息线程池数量
#pullMessageThreadPoolNums=128
#强制指定本机IP,需要根据每台机器进行修改。官方介绍可为空,系统默认自动识别,但多网卡时IP地址可能读取错误
brokerIP1=192.168.1.40

编辑broker-a-s.properties

vim /app/rocketmq/rocketmq-a-m/conf/broker-a-s.properties
# 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=rocketmq-csf
#broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
brokerName=broker-a
#0 表示 Master>0 表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=192.168.1.40:9876;192.168.1.41:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true
#Broker 对外服务的监听端口,10911为默认值
listenPort=10911
#Master监听slave请求端口,用于主从同步,默认为服务端口+1
haListenPort=10912
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/app/rocketmq/rocketmq-a/store
#commitLog 存储路径
storePathCommitLog=/app/rocketmq/rocketmq-a/store/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/app/rocketmq/rocketmq-a/store/consumequeue
#消息索引存储路径
storePathIndex=/app/rocketmq/rocketmq-a/store/index
#checkpoint 文件存储路径
storeCheckpoint=/app/rocketmq/rocketmq-a/store/checkpoint
#abort 文件存储路径
abortFile=/app/rocketmq/rocketmq-a/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
#强制指定本机IP,需要根据每台机器进行修改。官方介绍可为空,系统默认自动识别,但多网卡时IP地址可能读取错误
brokerIP1=192.168.1.41

broker-b.properties配置参考broker-a.properties
broker-b-s.properties配置参考broker-a-s.properties
当单台服务器上跑多个RocketMQ实例时有一个点要特别注意,那就是listenPort和haListenPort的配置,大多数情况下haListenPort是默认不配的,因此当一个实例使用默认的listenPort=10911端口时,haListenPort会默认占用10912端口,因此需要再配置下一个RocketMQ实例时要避开上述两个端口,多个实例之间的listenPort端口需要>2。
1.6 服务启动
服务启动包括两部分,NameServer的启动和BrokerServer的启动,其中NameServer类似于注册中心的角色,而BrokerServer才是真正处理消息的服务器。

cd /app/rocketmq/bin
nohup sh mqnamesrv >/app/rocketmq/mqnamesrv.log &
nohup sh mqbroker -c /app/rocketmq/rocketmq-a/conf/broker-a.properties >/app/rocketmq/rocketmq/rocketmq-a/log/mqbroker.log &

1.7 服务关闭

cd /app/rocketmq/bin
sh mqshutdown namesrv
sh mqshutdown broker

1.8 服务管理
如果需要查询NameServer集群的情况,可以使用如下命令查看:

sh mqadmin clusterList -n "192.168.1.40:9876;192.168.1.41:9876"

可视化监控部署

2.1 安装maven 3.2以上

wget http://mirrors.tuna.tsinghua.edu.cn/apache/maven/maven-3/3.6.2/binaries/apache-maven-3.6.2-bin.tar.gz
tar -zvxf apache-maven-3.6.2-bin.tar.gz -C /usr/local/maven
vim /etc/profile
   #maven
   export MAVEN_HOME=/usr/local/apache-maven-3.6.2
   export PATH=$PATH:$MAVEN_HOME/bin
source /etc/profile
mvn --version

settings.xml修改配置如下:

vim /usr/local/maven/apache-maven-3.6.2/conf/settings.xml
<mirrors>
   <!-- mirror
    | Specifies a repository mirror site to use instead of a given repository. The re
pository that
    | this mirror serves has an ID that matches the mirrorOf element of this mirror.
IDs are used
    | for inheritance and direct lookup purposes, and must be unique across the set o
f mirrors.
    |
   <mirror>
     <id>mirrorId</id>
     <mirrorOf>repositoryId</mirrorOf>
     <name>Human Readable Name for this Mirror.</name>
     <url>http://my.repository.com/repo/path</url>
   </mirror>
    -->
    <mirror>
            <id>alimaven</id>
            <mirrorOf>central</mirrorOf>
            <name>aliyun maven</name>
            <url>http://maven.aliyun.com/nexus/content/groups/public</url>
    </mirror>
 </mirrors>

2.2 下载部署
Apache版的RocketMQ管理界面部署工具可以从github上下载源码,地址:https://github.com/apache/rocketmq-externals,部署流程如下:

cd /app/rocketmq
git clone https://github.com/apache/rocketmq-externals.git
cd rocketmq-externals/rocketmq-console/src/main/resources/

修改配置如下图:

vim application.properties

在这里插入图片描述

server.port #是管理界面端口设置,默认为8080;
rocketmq.config.namesrvAddr #如果nameserver有多个,则后面就配置多个ip+port,用分号 分割;
rocketmq.config.isVIPChannel #注意这个参数,默认为true,如果rocketmq版本号 < 3.5.8 则设置为false;
rocketmq.config.dataPath #
2.3 编译rocketmq-console

mvn clean package -Dmaven.test.skip=true

编译需用maven命令进行编译,如下图,显示BIUD SUCCESS,则编译成功,编译成功后在target下找到文件:rocketmq-console-ng-1.0.1.jar
在这里插入图片描述
2.4 运行jar包
nohup java -jar target/rocketmq-console-ng-1.0.1.jar >/dev/null 2>&1 &

2.5 访问管理界面
浏览器输入http://192.168.1.40:8080/
在这里插入图片描述
在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

princeAladdin

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值