利用6台机器搭建一个3分片的broker集群,一共有3个broker实例(3m),采用同步刷屏模式
1.引言
本文主要介绍如何在三台机器上搭建一个3m(无slave节点的)rocketmq的集群。
2.环境准备
机器名 |
机器IP | 机器配置 |
备注 |
nameserver1 |
192.168.11.1 | 4C4G |
|
nameserver2 |
192.168.11.2 | 4C4G |
|
nameserver3 |
192.168.11.3 | 4C4G |
|
broker1 |
192.168.11.4 | 8C16G | |
broker2 |
192.168.11.5 | 8C16G | |
broker3 |
192.168.11.6 | 8C16G |
2.1 配置hostname
这里设置是为了方便管理机器节点,也可以跳过此处。
#nameserver1上执行: hostnamectl set-hostname nameserver1 #nameserver2上执行: hostnamectl set-hostname nameserver2 #nameserver3上执行: hostnamectl set-hostname nameserver3 #broker1上执行: hostnamectl set-hostname broker1 #broker2上执行: hostnamectl set-hostname broker2 #broker3上执行: hostnamectl set-hostname broker3
2.2 设置hosts
在broker1,broker2,broker3分别执行:
cat >>/etc/hosts<<EOF192.168.11.1 nameserver1192.168.11.2 nameserver2192.168.11.3 nameserver3 EOF
3. 具体步骤
3.1 下载rocketmq的编译好的二进制包(4.7.1版本)
wget https://mirror.bit.edu.cn/apache/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
3.2 解压缩到到/usr/local/mq目录,并创建软链接
rocketmq-all-.-bin-release. -d /usr/local/cd /usr/local/ #创立软链接 -s rocketmq-all-.-bin-release rocketmq
3.3 安装java
#Ubuntu:sudo apt install -y openjdk-8-jdk*#Centos:sudo yum install -y java-1.8.0-openjdk*
4.初始化环境
4.1 设置环境变量
#如果是Ubuntu >> ~/.bashrc #如果是Centos >> ~/.bashrc #无论是Ubuntu还是Centos都执行如下: #设置CLASSPATH >> ~/.bashrc #设置ROCKETMQ_HOME >> ~/.bashrc #添加到PATH >> ~/.bashrc
4.2 加载环境变量
source ~/.bashrc
4.3 创建目录
#/data目录的空间至少为1T+mkdir -pv {/data/logs,/data/rocketmq/store/commitlog}
4.4 修改rocketmq的主目录
sed -i 's#${user.home}#/data#g' $ROCKETMQ_HOME
/conf/*.xml
4.5 修改Linux系统参数提高性能
cd $ROCKETMQ_HOME/binsudo ./os.sh
5 启动
5.1 启动nameserver
1) 生成配置
分别在nameserver1,nameserver2,nameserver3上执行:
#进入Rockmq的bin目录 cd $ROCKETMQ_HOME/bin #生产nameserver的配置cat >> namesrv.properties << EOF rocketmqHome=/usr/local/rocketmq kvConfigPath=/root/namesrv/kvConfig.json productEnvName=center clusterTest=falseorderMessageEnable=falselistenPort=9876serverWorkerThreads=8serverCallbackExecutorThreads=0serverSelectorThreads=3serverOnewaySemaphoreValue=256serverAsyncSemaphoreValue=64serverChannelMaxIdleTimeSeconds=120serverSocketSndBufSize=65535serverSocketRcvBufSize=65535serverPooledByteBufAllocatorEnable=trueuseEpollNativeSelector=trueEOF
2) 启动nameserver
cd $ROCKETMQ_HOME/bin nohup ./mqnamesrv -c namesrv.properties &
5.2 启动broker
下面分别配置三台broker
5.2.1 配置Rocket集群
1) 配置broker1的环境变量
cat >> ~/.bashrc << EOF Role=broker1 brokerId=0GroupName=broker-a EOF
执行:source ~/.bashrc
2)配置broker1的启动配置
cd $ROCKETMQ_HOMEcat >conf/dledger/qmq-${Role}.conf<<EOF brokerClusterName=QMQ brokerId=${brokerId} brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH brokerName=${GroupName} namesrvAddr=nameserver1:9876;nameserver2:9876;nameserver3:9876storePathRootDir=/data/rocketmq/${Role} storePathCommitLog=/data/rocketmq/${Role}/commitlog enableDLegerCommitLog=false#凌晨4点触发一次删除 deleteWhen = 04diskMaxUsedSpaceRatio=50#只保留最近1天的消息 fileReservedTime = 24sendMessageThreadPoolNums=8defaultTopicQueueNums=16maxTransferCountOnMessageInMemory=1000waitTimeMillsInSendQueue=1000transientStorePoolEnable=falsewarmMapedFileEnable=falsetransferMsgByHeap=truemaxTransferCountOnMessageInMemory=2000maxTransferBytesOnMessageInMemory=2000*1024EOF
3)启动broker1
cd $ROCKETMQ_HOME/bin nohup sh mqbroker -c $ROCKETMQ_HOME/conf/dledger/qmq-${Role}.conf &
1)配置broker2环境变量
cat >> ~/.bashrc << EOF
Role=broker2
brokerId=0
GroupName=broker-b EOF
执行:source ~/.bashrc
2)配置broker2的启动配置
cd $ROCKETMQ_HOME cat >conf/dledger/qmq-${Role}.conf<<EOF brokerClusterName=QMQ brokerId=${brokerId} brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH brokerName=${GroupName} namesrvAddr=nameserver1:9876;nameserver2:9876;nameserver3:9876 storePathRootDir=/data/rocketmq/${Role} storePathCommitLog=/data/rocketmq/${Role}/commitlog enableDLegerCommitLog=false #凌晨4点触发一次删除 deleteWhen = 04 diskMaxUsedSpaceRatio=50 #只保留最近1天的消息 fileReservedTime = 24 sendMessageThreadPoolNums=8 defaultTopicQueueNums=16 maxTransferCountOnMessageInMemory=1000 waitTimeMillsInSendQueue=1000 transientStorePoolEnable=false warmMapedFileEnable=false transferMsgByHeap=true maxTransferCountOnMessageInMemory=2000 maxTransferBytesOnMessageInMemory=2000*1024 EOF
3)启动broker2
cd $ROCKETMQ_HOME/bin nohup sh mqbroker -c $ROCKETMQ_HOME/conf/dledger/qmq-${Role}.conf &
1)配置broker3环境变量
cat >> ~/.bashrc << EOF Role=broker3 brokerId=0 GroupName=broker-c EOF
执行:source ~/.bashrc
2)配置broker3的启动配置
cd $ROCKETMQ_HOME cat >conf/dledger/qmq-${Role}.conf<<EOF brokerClusterName=QMQ brokerId=${brokerId} brokerRole=SYNC_MASTER flushDiskType=ASYNC_FLUSH brokerName=${GroupName} namesrvAddr=nameserver1:9876;nameserver2:9876;nameserver3:9876 storePathRootDir=/data/rocketmq/${Role} storePathCommitLog=/data/rocketmq/${Role}/commitlog enableDLegerCommitLog=false #凌晨4点触发一次删除 deleteWhen = 04 diskMaxUsedSpaceRatio=50 #只保留最近1天的消息 fileReservedTime = 24 sendMessageThreadPoolNums=8 defaultTopicQueueNums=16 maxTransferCountOnMessageInMemory=1000 waitTimeMillsInSendQueue=1000 transientStorePoolEnable=false warmMapedFileEnable=false transferMsgByHeap=true maxTransferCountOnMessageInMemory=2000 maxTransferBytesOnMessageInMemory=2000*1024 EOF
3)启动broker3
cd $ROCKETMQ_HOME/bin nohup sh mqbroker -c $ROCKETMQ_HOME/conf/dledger/qmq-${Role}.conf &
5.3 其它命令
Broker其它命令
1. 关闭broker
sh mqshutdown brokersh mqshutdown namesrv
2. 查看broker是否启动
#查看进程 jps -m #查看端口 netstat -tupln|grep -E '309|409'
5.4 查看集群信息
通过控制台查询
博主:测试生财
座右铭:专注测试与自动化,致力提高研发效能;通过测试精进完成原始积累,通过读书理财奔向财务*。
csdn:https://blog.csdn.net/ccgshigao