Rocketmq两主两从集群部署

环境准备

准备两台服务器或者虚拟机

服务器一:192.***.*.31

服务器二:192.***.*.32

部署模式: 2M-2S-SYNC(两主两从同步写)

相关安装包存储路径:/root/svr/rocketmq

部署

下载安装包

Apache:

https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.2.0/rocketmq-all-4.2.0-bin-release.zip

Github:

https://github.com/apache/rocketmq/

解压

运行: unzip rocketmq-all-4.2.0-bin-release.zip -d /root/svr/rocketmq

配置host(给nameServer用)

命令: vim /etc/hosts

192.***.*.31 rocketmq1
192.***.*.32 rocketmq2

配置环境变量:vim /etc/profile

export ROCKETMQ_HOME=/root/svr/rocketmq
export PATH=$PATH::$ROCKETMQ_HOME/bin

执行:source /etc/profile

配置集群参数

命令(master): vim /root/svr/rocketmq/conf/2m-2s-sync/broker-a.properties

brokerClusterName=rocketmq-cluster
brokerName=broker-a
brokerId=0
namesrvAddr=rocketmq1:9876;rocketmq2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/root/svr/rocketmq/data/store
storePathCommitLog=/root/svr/rocketmq/data/store/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SYNC_MASTER
flushDiskType=ASYNC_FLUSH

命令(slave) vim /root/svr/rocketmq/conf/2m-2s-sync/broker-b-s.properties

brokerClusterName=rocketmq-cluster
brokerName=broker-a
#0 表示 Master,>0 表示 Slave
brokerId=1 
namesrvAddr=rocketmq1:9876;rocketmq2:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10922
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileIntervalForcibly=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/root/svr/rocketmq/data/store2
storePathCommitLog=/root/svr/rocketmq/data/store2/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
#角色
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH

创建存储&日志文件

mkdir /root/svr/rocketmq/data (也要创建store文件夹)
mkdir /root/svr/rocketmq/data/store/commitlog
mkdir /root/svr/rocketmq/data/store/consumequeue
mkdir /root/svr/rocketmq/data/store/index

修改日志配置文件

mkdir -p /root/svr/rocketmq/logs
cd /root/svr/rocketmq/conf && sed -i 's#${user.home}#/root/svr/rocketmq#g' *.xml

注意logback.*.xml配置文件中${user.home}需要替换自己指定的目录

改参数

unbroker.sh,runserver.sh启动参数默认对jvm的堆内存设置比较大(不改启动不起来),如果是虚拟机非线上环境需要改下参数,大小可以根据自己机器来决定

默认大小
-Xms8g -Xmx8g -Xmn4g
改为:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"

复制

scp 到其他服务器

scp -r rocketmq/ root@192.***.*.32:/root/svr/

启动服务

启动Nameserver服务

/root/svr/rocketmq/bin目录下执行命令:nohup sh mqnamesrv &

启动BrokerServer

/root/svr/rocketmq/bin目录下执行命令:nohup sh mqbroker -c /root/svr/rocketmq/conf/2m-2s-sync/broker-a.properties&

验证是否启动成功

输入命令jps或者查看rocketmq/logs下日志是否输出正常

Rocketmq两主两从集群部署_第1张图片

查看集群监控状态

sh mqadmin clusterlist -n 192.***.*.31:9876

Rocketmq两主两从集群部署_第2张图片
Rocketmq两主两从集群部署_第3张图片

监控

源码下载地址

https://github.com/apache/rocketmq-externals.git

配置namesrv

rocketmq.config.namesrvAddr=192.***.*.31:9876

测试

export NAMESRV_ADDR=rocketmq1:9876
测试发送端
 > sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
测试消费端
 > sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

服务停止

/root/svr/rocketmq/bin目录下执行命令或者jps查看进程号 kill -9 pid

sh mqshutdown broker
sh mqshutdown namesrv

你可能感兴趣的:(工具,Rocketmq)