利用6台机器搭建一个3分片的broker集群,一共有3个broker实例(3m),采用同步刷屏模式
1.引言
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<<EOF 192.168.11.1 nameserver1 192.168.11.2 nameserver2 192.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目录,并创建软链接
#解压到/usr/local
unzip rocketmq-all-4.7.1-bin-release.zip -d /usr/local/ cd /usr/local/ #创立软链接 ln -s rocketmq-all-4.7.1-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 echo 'export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/'>> ~/.bashrc #如果是Centos echo 'export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.262.b10-0.el7_8.x86_64/'>> ~/.bashrc #无论是Ubuntu还是Centos都执行如下: #设置CLASSPATH echo 'export CLASSPATH=$JAVA_HOME/lib:$JAVA_HOME/jre/lib'>> ~/.bashrc #设置ROCKETMQ_HOME echo 'export ROCKETMQ_HOME=/usr/local/rocketmq'>> ~/.bashrc
#添加到PATH echo 'export PATH=$PATH:$ROCKETMQ_HOME/bin:$JAVA_HOME/bin:$JAVA_HOME/jre/bin'>> ~/.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/bin sudo ./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=false orderMessageEnable=false listenPort=9876 serverWorkerThreads=8 serverCallbackExecutorThreads=0 serverSelectorThreads=3 serverOnewaySemaphoreValue=256 serverAsyncSemaphoreValue=64 serverChannelMaxIdleTimeSeconds=120 serverSocketSndBufSize=65535 serverSocketRcvBufSize=65535 serverPooledByteBufAllocatorEnable=true useEpollNativeSelector=true EOF
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=0 GroupName=broker-a EOF
执行:source ~/.bashrc
2)配置broker1的启动配置
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)启动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 broker sh mqshutdown namesrv
2. 查看broker是否启动
#查看进程 jps -m #查看端口 netstat -tupln|grep -E '309|409'
5.4 查看集群信息
通过控制台查询
博主:测试生财(一个不为996而996的测开码农)
座右铭:专注测试开发与自动化运维,努力读书思考写作,为内卷的人生奠定财务自由。
内容范畴:技术提升,职场杂谈,事业发展,阅读写作,投资理财,健康人生。
csdn:https://blog.csdn.net/ccgshigao
博客园:https://www.cnblogs.com/qa-freeroad/
51cto:https://blog.51cto.com/14900374
微信公众号:测试生财(定期分享独家内容和资源)