写点什么

RocketMQ 安装部署

用户头像
云淡风轻
关注
发布于: 2021 年 03 月 02 日

RocketMQ 安装部署


官方文档

http://rocketmq.apache.org/docs/quick-start/


安装步骤

下载 rocketmq v4.8.0,并解压到安装目录。

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


Start NameServer (ip:9876)

nohup sh /Users/xxx/software/rocketmq-4.8/bin/mqnamesrv &
tail -f /Users/xxx/logs/rocketmqlogs/namesrv.log
复制代码


Start Broker (ip:10911)

nohup sh /Users/xxx/software/rocketmq-4.8/bin/mqbroker -n 127.0.0.1:9876 -c /Users/xxx/software/rocketmq-4.8/conf/broker.conf autoCreateTopicEnable=true &
tail -f /Users/xxx/logs/rocketmqlogs/broker.log
复制代码


Shutdown

sh /Users/xxx/software/rocketmq-4.8/bin/mqshutdown namesrv
sh /Users/xxx/software/rocketmq-4.8/bin/mqshutdown broker
复制代码


Send & Receive Message

export NAMESRV_ADDR=127.0.0.1:9876
sh /Users/xxx/software/rocketmq-4.8/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
sh /Users/xxx/software/rocketmq-4.8/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
复制代码


修改配置

修改/etc/profile 添加环境变量

export ROCKETMQ_HOME=/Users/xxx/software/rocketmq-4.8export NAMESRV_ADDR=127.0.0.1:9876
复制代码


修改 broker 配置

/Users/xxx/software/rocketmq-4.8/conf/broker.conf

brokerClusterName = DefaultClusterbrokerName = broker-abrokerId = 0listenPort = 10911deleteWhen = 04fileReservedTime = 48brokerRole = ASYNC_MASTERflushDiskType = ASYNC_FLUSH
###brokerIP1 = 127.0.0.1namesrvAddr = 127.0.0.1:9876autoCreateTopicEnable = trueautoCreateSubscriptionGroup = true
#存储路径(确保路径已创建,否则会导致消息发送失败)storePathRootDir=/Users/xxx/store#commitLog存储路径(确保路径已创建,否则会导致消息发送失败)storePathCommitLog=/Users/xxx/store/commitlog#消费队列存储路径(确保路径已创建,否则会导致消息发送失败)storePathConsumeQueue=/Users/xxx/store/consumequeue# 消息索引存储路径(确保路径已创建,否则会导致消息发送失败)storePathIndex=/Users/xxx/store/index# checkpoint 文件存储路径(确保路径已创建,否则会导致消息发送失败)storeCheckpoint=/Users/xxx/store/checkpoint#abort 文件存储路径(确保路径已创建,否则会导致消息发送失败)abortFile=/Users/xxx/store/abort
复制代码


修改启动 shell 脚本

/Users/xxx/software/rocketmq-4.8/bin/runserver.sh

/Users/xxx/software/rocketmq-4.8/bin/runbroker.sh

/Users/xxx/software/rocketmq-4.8/bin/tools.sh

#注释掉下面3行配置,估计跟环境变量里面JAVA_HOME冲突#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
#调整JVM内存大小,默认值太大了JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"choose_gc_options
复制代码


测试发送+接收

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
发送成功日志:SendResult [sendStatus=SEND_OK, msgId=7F0000011E9C5CAD8086086157270000, offsetMsgId=0ABB1D1000002A9F0000000000000000, messageQueue=MessageQueue [topic=TopicTest, brokerName=broker-a, queueId=1], queueOffset=0]

sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
消费成功日志:ConsumeMessageThread_9 Receive New Messages: [MessageExt [brokerName=broker-a, queueId=3, storeSize=202, queueOffset=8, sysFlag=0, bornTimestamp=1614668597093, bornHost=/10.187.29.16:52890, storeTimestamp=1614668597093, storeHost=/10.187.29.16:10911, msgId=0ABB1D1000002A9F0000000000001ACA, commitLogOffset=6858, bodyCRC=1054644365, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=250, CONSUME_START_TIME=1614668611066, UNIQ_KEY=7F0000011E9C5CAD8086086157650022, CLUSTER=DefaultCluster, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 51, 52], transactionId='null'}]]
复制代码


mqadmin 命令

./mqadmin topicList -n 10.187.29.16:9876./mqadmin topicStatus -n 127.0.0.1:9876 -t TestTopic./mqadmin topicRoute -n 127.0.0.1:9876 -t TestTopic
./mqadmin getBrokerConfig -n 127.0.0.1:9876 -b 127.0.0.1:10911./mqadmin brokerStatus -n 127.0.0.1:9876 -b 127.0.0.1:10911
./mqadmin producerConnection -n 127.0.0.1:9876 -g my-producer-group -t TestTopic
复制代码


备注


存储目录:/Users/xxx/store

日志目录:/Users/xxx/logs/rocketmqlogs (消息发送失败仔细查一下日志)


RocketMQ-Console 安装部署


Git 地址

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

https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console


安装步骤

下载源码

git clone https://github.com/apache/rocketmq-externals.git
复制代码


修改 application.properties 配置

#if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876rocketmq.config.namesrvAddr=127.0.0.1:9876#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default truerocketmq.config.isVIPChannel=false
复制代码


Maven 打包

mvn clean package -Dmaven.test.skip=true
复制代码


启动服务

nohup java -jar /Users/xxx/software/rocketmq-console-ng-2.0.0.jar --server.port=8080 --rocketmq.config.namesrvAddr=127.0.0.1:9876 &
查看日志tail -f /Users/xxx/logs/consolelogs/rocketmq-console.log
复制代码


使用 Console 服务

访问: http://127.0.0.1:8080/

注册的 RocketMQ-Cluster

更多配置

https://github.com/apache/rocketmq-externals/blob/master/rocketmq-console/doc/100/UserGuide_EN.md


用户头像

云淡风轻

关注

云淡风轻 2018.08.18 加入

JAVA软件工程师

评论

发布
暂无评论
RocketMQ安装部署