前言
本文基于centos6.8搭建安装rocketmqV4.5.1版本,两个节点分别部署A-m,B-S和A-S,B-m
目录
- 基础环境搭建
- 搭建ROCKETMQ
基础环境搭建
系统版本 | JDK | IP地址 | 角色 |
---|---|---|---|
Centos6.8 | 1.8 | 176.101.52.105 | MASTER-A SLAVE-B |
Centos6.8 | 1.8 | 176.101.52.104 | MASTER-B SLAVE-A |
关闭selinux
sed -i 's/^SELINUX=.*/SELINUX=disabled/` /etc/selinux/config
setenforce 0
关闭防火墙
service iptables stop && checkconfig iptables off
配置JDK环境变量
将JDK.SH文件放入/etc/profile.d/下 jdk.sh 内容如下
export JAVA_HOME=/home/apps/jdk
export JRE_HOME=$JAVA_HOME/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
PATH=$JAVA_HOME/bin:/usr/bin:/bin:/sbin:$PATH
export PATH
搭建ROCKETMQ
1.下载离线包上传并解压
unzip rocketmq-all-4.5.1-bin-release.zip
2.修改配置文件
2m-2s-async(主从异步),----本文采用这种
2m-2s-sync(主从同步)
2m-noslave(仅master)
注意
- 同一个机器上启动多个broker时,需使用不同的broker配置文件来启动实例,节点1启动一个a-m和b-s,使用broker-a.properties和broker-b-s.properties
- listenPort默认为10911,当一个机器上启动多个broker示例时,需区分开端口
- broker启动时,默认内存设置比较大,改成适合机器的,细节可看步骤
- 当一个节点启动多个broker实例时,存储路径如果显示的设置,则需要指定不同的storePath路径,(因部署时,直接粘贴复制的配置文件,导致启动两个broke失败)
3.1修改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.
#default config
#brokerClusterName=DefaultCluster
#brokerName=broker-a
#brokerId=0
#deleteWhen=04
#fileReservedTime=48
#brokerRole=ASYNC_MASTER
#flushDiskType=ASYNC_FLUSH
#所属集群名字
brokerClusterName=rocketmq-cluster
#broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=0
#nameServer地址,分号分割
namesrvAddr=176.101.52.104:9876;176.101.52.105:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=false
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=false
#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-4.5.1/store/broker-a
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.5.1/store/broker-a/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.5.1/store/broker-a/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.5.1/store/broker-a/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.5.1/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.5.1/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
#打开acl验证 若打开了则需配置plain_acl.yml 配置相关数据 该配置项默认关闭
aclEnable=true
3.2修改broker-b-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-cluster
#broker名字,名字可重复,为了管理,每个master起一个名字,他的slave同他,eg:Amaster叫broker-a,他的slave也叫broker-a
brokerName=broker-b
#0 表示 Master,>0 表示 Slave
brokerId=1
#nameServer地址,分号分割
namesrvAddr=176.101.52.104:9876;176.101.52.105:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许 Broker 自动创建Topic,建议线下开启,线上关闭
autoCreateTopicEnable=false
#是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=false
#Broker 对外服务的监听端口,
listenPort=10912
#删除文件时间点,默认凌晨 4点
deleteWhen=04
#文件保留时间,默认 48 小时
fileReservedTime=120
#commitLog每个文件的大小默认1G
mapedFileSizeCommitLog=1073741824
#ConsumeQueue每个文件默认存30W条,根据业务情况调整
mapedFileSizeConsumeQueue=300000
#destroyMapedFileIntervalForcibly=120000
#redeleteHangedFileInterval=120000
#检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#存储路径
storePathRootDir=/home/rocketmq-4.5.1/store/broker-b
#commitLog 存储路径
storePathCommitLog=/home/rocketmq-4.5.1/store/broker-b/commitlog
#消费队列存储路径存储路径
storePathConsumeQueue=/home/rocketmq-4.5.1/store/broker-b/consumequeue
#消息索引存储路径
storePathIndex=/home/rocketmq-4.5.1/store/broker-b/index
#checkpoint 文件存储路径
storeCheckpoint=/home/rocketmq-4.5.1/store/checkpoint
#abort 文件存储路径
abortFile=/home/rocketmq-4.5.1/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
#打开acl验证 若打开了则需配置plain_acl.yml 配置相关数据 该配置项默认关闭
aclEnable=true
3.3 修改plain_acl.yml内容如下
# 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.
#若为空则 表示不设置白名单,该条规则默认返回false。
# * 表示全部匹配
globalWhiteRemoteAddresses:
- 10.10.103.*
- 176.101.52.*
#accesKey secretkey 账号密码均需8度长度以上
accounts:
- accessKey: RocketMQ
secretKey: 12345678
whiteRemoteAddress:
admin: false
defaultTopicPerm: DENY
defaultGroupPerm: SUB
topicPerms:
- topicA=DENY
- topicB=PUB|SUB
- topicC=SUB
groupPerms:
# the group should convert to retry topic
- groupA=DENY
- groupB=PUB|SUB
- groupC=SUB
#用户级别的IP地址白名单。其类型为一个字符串,其配置规则与globalWhiteRemoteAddresses,但只能配置一条规则。
- accessKey: rocketmq2
secretKey: 12345678
whiteRemoteAddress: 176.101.52.*
# if it is admin, it could access all resources
admin: true
若需知道更多配置及acl相关信息 请跳转至该博客https://blog.csdn.net/prestigeding/article/details/94317946
3.3配置第二台(176.101.52.105)
配置内容同上,只需要修改部分内容这里不再复述
4 启动nameserver
分别在两台节点上执行
mkdir -p /home/rocketmq-4.5.1/logs
cd /home/rocketmq-4.5.1/bin/ && nohup ./mqnamesrv &
5启动broken
节点 MASTER-A SLAVE-B
nohup sh /home/rocketmq-4.5.1/bin/mqbroker -c /home/rocketmq-4.5.1/conf/2m-2s-async/broker-a.properties > /home/rocketmq-4.5.1/logs/broker-a.log 2>&1 &
nohup sh /home/rocketmq-4.5.1/bin/mqbroker -c /home/rocketmq-4.5.1/conf/2m-2s-async/broker-b-s.properties > /home/rocketmq-4.5.1/logs/broker-b-s.log 2>&1 &
节点MASTER-B SLAVE-A
nohup sh /home/rocketmq-4.5.1/bin/mqbroker -c /home/rocketmq-4.5.1/conf/2m-2s-async/broker-a-s.properties > /home/rocketmq-4.5.1/logs/broker-a.log 2>&1 &
nohup sh /home/rocketmq-4.5.1/bin/mqbroker -c /home/rocketmq-4.5.1/conf/2m-2s-async/broker-b.properties > /home/rocketmq-4.5.1/logs/broker-b-s.log 2>&1 &
部署consle管理界面
因最新consle包采用spring-boot架构,大家可自行进行编译,此处放上传送门
https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console
1修改rocketmq-console-ng-1.0.1.jar\BOOT-INF\classes\application.properties配置文件,内容如下
server.contextPath=/rocketmq
###访问端口
server.port=7001
### SSL setting
#server.ssl.key-store=classpath:rmqcngkeystore.jks
#server.ssl.key-store-password=rocketmq
#server.ssl.keyStoreType=PKCS12
#server.ssl.keyAlias=rmqcngkey
#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
rocketmq.config.namesrvAddr=12.39.128.35:9876;12.39.140.167:9876
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/home/rocketmq-4.5.1/console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
#set the message track trace topic if you don't want use the default one
rocketmq.config.msgTrackTopicName=
rocketmq.config.ticketKey=ticket
#Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
###是否登录校验默认false 建议线上开启
rocketmq.config.loginRequired=false
启动
nohup java -jar rocketmq-console-ng-1.0.0.jar. &
启动页面

网友评论