1、环境变量配置:
#设置jdk环境变量
export JAVA_HOME=/usr/local/java/jdk1.8.0_191 #jdk安装目录
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib:$CLASSPATH
export JAVA_PATH=${JAVA_HOME}/bin:${JRE_HOME}/bin
export PATH=$PATH:${JAVA_PATH}
#设置 rocketmq 环境变量
export ROCKETMQ_HOME=/usr/local/rocketmq/rocketmq-4.2
export PATH=$PATH::$ROCKETMQ_HOME/bin
2、创建目录
mkdir /usr/local/rocketmq/rocketmq-4.2/data/store 存储路径
mkdir /usr/local/rocketmq/rocketmq-4.2/data/store/commitlog commitLog 存储路径
mkdir /usr/local/rocketmq/rocketmq-4.2/data/store/consumequeue 消费队列存储路径存储路径
mkdir /usr/local/rocketmq/rocketmq-4.2/data/store/index 消息索引存储路径
3、修改配置文件:
broker-a.properties:
#所属集群名称,如果多个master,那么每个master配置的名称应该一致,要不然识别不了
brokerClusterName=rocketmq-cluster
#broker名称
brokerName=broker-a
#0 表示master,>0 表示slave
brokerId=0
#nameServer地址,分号隔开
namesrvAddr=192.168.9.201:9876;192.168.9.202:9876
#在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4
#是否允许broker自动创建topic,建议线下开启,线上关闭
autoCreateTopicEnable=true
#是否允许broker自动创建订阅组,建议线下开始,线上关闭
autoCreateSubscriptionGroup=true
#broker对外服务的监听端口,
#同一台机器部署多个broker,端口号要不同,且端口号之间要相距大些
listenPort=10911
#删除文件的时间节点,默认凌晨4点
deleteWhen=04
#文件保留时间,默认48小时
fileReservedTime=120
#commitLog每个文件的大小,默认大小1g
mapedFileSizeCommitLog=1073741824
#consumeQueue每个文件默认存30w条,根据自身业务进行调整
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
#检查物理文件磁盘空间
diskMaxUsedSpaceRatio=88
#store存储路径,master与slave目录要不同
storePathRootDir=/usr/local/rocketmq/rocketmq-4.2/data/store
#commitLog存储路径
storePathCommitLog=/usr/local/rocketmq/rocketmq-4.2/data/store/commitlog
#限制的消息大小
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
#发消息线程池数
sendMessageThreadPoolNums=128
#拉去消息线程池数
pullMessageThreadPoolNums=128
#broker角色:
#ASYSC_MASTER 异步复制master
#SYSC_MASTER 同步复制master
#SLAVE 从
brokerRole=SYSC_MASTER
#刷盘方式
#ASYNC_FLUSH 异步刷盘
#SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH
broker-b-s.properties:
brokerClusterName=rocketmq-cluster
brokerName=broker-b
#0 -> master ,>0 -> slave
brokerId=1
namesrvAddr=192.168.9.201:9876;192.168.9.202:9876
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10950
deleteWhen=04
fileReservedTime=120
mapedFileSizeCommitLog=1073741824
mapedFileSizeConsumeQueue=300000
destroyMapedFileInterval=120000
redeleteHangedFileInterval=120000
diskMaxUsedSpaceRatio=88
storePathRootDir=/usr/local/rocketmq/rocketmq-4.2/data/store/slave
storePathCommitLog=/usr/local/rocketmq/rocketmq-4.2/data/store/slave/commitlog
maxMessageSize=65536
flushCommitLogLeastPages=4
flushConsumeQueueLeastPages=2
flushCommitLogThoroughInterval=10000
flushConsumeQueueThoroughInterval=60000
checkTransactionMessageEnable=false
sendMessageThreadPoolNums=128
pullMessageThreadPoolNums=128
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
另外一台机器也是这样配置
4、修改日志配置文件
#创建日志目录
mkdir -p /usr/local/rocketmq/rocketmq-4.2/logs
#替换*.xml文件中的{user.home}为自己指定的目录
cd /usr/local/rocketmq/rocketmq-4.2/conf && sed -i 's#${user.home}#/root/svr/rocketmq#g' *.xml
5、改参数:
runbroker.sh,runserver.sh启动参数默认对jvm的堆内存设置比较大(不改启动不起来),如果是虚拟机非线上环境需要改下参数,大小可以根据自己机器来决定。
6、启动服务
先启动namesrv(两台都要启动):
cd /usr/local/rocketmq/rocketmq-4.2/bin
nohup sh mqnamesrv &
nohup: 忽略输入并把输出追加到"nohup.out"
jps
2604 NamesrvStartup
2621 Jps
因为rocketmq是java开发的,所以通过jps命令查看namesrv有没有启动,当然通过日志文件也可以,namesrv正常启动之后,后续再分别启动Broker。
另外一台执行相同的步骤
7、启动完成,查看集群信息:
sh mqadmin clusterlist -n 192.168.9.201:9876