RocketMQ环境搭建(单master Mac OS)
单master的安装比较简单,提前要安装好jdk。时刻初学rocketmq 快速先搭建一个坏境用起来。
环境准备:
Mac OS
rocketmq-all-4.5.1-bin-release
jdk_1.8.0_211
安装步骤:
1、解压 rocketmq-all-4.5.1-bin-release.zip 到 /usr/local下
unzip rocketmq-all-4.5.1-bin-release.zip -d /usr/local/
2、进入到 /usr/local/rocketmq-all-4.5.1-bin-release/bin 目录下编辑 runserver.sh 和 runborker.sh 两个文件 调整一下namesrv和broker的启动的jvm内存参数。具体参数大小根据你的电脑配置情况而定
vim runserver.sh JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim runroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"
3、配置broker的一些参数
3.1 创建几个新目录。用来存储消息文件
mkdir -p /usr/local/rocketmq-all-4.5.1-bin-release/store/(commitlog,pathindex,pathconsumequeue)
#注意:abort和checkpoint这两个目录不要创建。否则会报错“AllocateMappedFileService started:false”
3.2 编辑/usr/local/rocketmq-all-4.5.1-bin-release/conf/broker.conf。主要看一下蓝色字体部分
brokerClusterName = DefaultCluster brokerName = broker-a # 0表示master >0表示slave brokerId = 0 deleteWhen = 04 # 文件保留时间,默认48小时 fileReservedTime = 48 # Broker 的角色 #- ASYNC_MASTER 异步复制Master #- SYNC_MASTER 同步双写Master #- SLAVE brokerRole = ASYNC_MASTER #刷盘方式 # ASYNC_FLUSH 异步刷盘 # SYNC_FLUSH 同步刷盘 flushDiskType = ASYNC_FLUSH #checkTransactionMessageEnable=false # 发消息线程池数量 # sendMessageThreadPoolNums=128 # 拉消息线程池数量 # pullMessageThreadPoolNums=128lushDiskType=ASYNC_FLUSH # 修改nameserver为公有ip namesrvAddr = localhost:9876 # 修改broker为共有ip brokerIP1 = localhost # 发送消息时,自动创建服务器不存在的topic,默认创建的队列数 defaultTopicQueueNums=4 # 是否允许 Broker 自动创建Topic,建议线下开启,线上关闭 #autoCreateTopicEnable=true # 是否允许Broker 自动创建订阅组,建议线下开启,线上关闭 #autoCreateSubscriptionGroup=true # Broker 对外服务的监听端口 listenPort=10911 # 删除文件时间点,默认凌晨4点 deleteWhen=04 # commitLog每个文件的大小默认1G mapedFileSizeCommitLog=1073741824 # ConsumeQueue每个文件默认存30w条,根据业务情况调整 mapedFileSizeConsumeQueue=300000 #destroyMapedFileIntervalForcibly=120000 #redeleteHangedFileInterval=120000 # 检测物理文件磁盘空间 diskMaxUsedSpaceRatio=88 # 存储路径 storePathRootDir=/usr/local/rocketmq-all-4.5.1-bin-release/store # commitLog存储路径 storePathCommitLog=/usr/local/rocketmq-all-4.5.1-bin-release/store/commitlog # 消费队列存储路径 storePathConsumeQueue=/usr/local/rocketmq-all-4.5.1-bin-release/store/pathconsumequeue # 消息索引存储路径 storePathIndex=/usr/local/rocketmq-all-4.5.1-bin-release/store/pathindex # checkpoint 文件存储 storeCheckpoint=/usr/local/rocketmq-all-4.5.1-bin-release/store/checkpoint # abort 文件存储 abortFile=/usr/local/rocketmq-all-4.5.1-bin-release/store/abort # 限制消息大小 maxMessageSize=65536 #flushCommitLogLeastPages=4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000
4、启动rocketmq,先启动 namesrv 再启动 broker
--后台启动namesrv
nohup sh mqnamesrv &
--后台启动broker
export NAMESRV_ADDR=localhost:9876
--如果你在brocker.conf文件中配置了namesrvAddr = localhost:9876就直接用下面的命令
nohup sh mqbroker -c /usr/local/rocketmq-all-4.5.1-bin-release/conf/broker.conf &
--否则用这个命令
nohup sh mqbroker -n localhost:9876 -c /usr/local/rocketmq-all-4.5.1-bin-release/conf/broker.conf &
5、查看进程和日志看是否启动成功
jps -l
tail -f -n 300 ~/logs/rocketmqlogs/namesrv.log
tail -f -n 300 ~/logs/rocketmqlogs/broker.log
6、测试一下
-- 先启动consumer
export NAMESRV_ADDR=localhost:9876
/usr/local/rocketmq-all-4.5.1-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
-- 启动producer
export NAMESRV_ADDR=localhost:9876
/usr/local/rocketmq-all-4.5.1-bin-release/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
参考:
【1】https://www.cnblogs.com/lina-2159/p/13601204.html