重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
本篇内容主要讲解“RokcetMq安装和快速启动的方法”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“RokcetMq安装和快速启动的方法”吧!
成都创新互联长期为成百上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为乡宁企业提供专业的成都做网站、成都网站制作,乡宁网站改版等技术服务。拥有10多年丰富建站经验和众多成功案例,为您定制开发。
访问: http://rocketmq.apache.org/dowloading/releases/ 下载最新版本
将下载的最新版本包放在linux服务器,这里以rocketmq-all-4.5.2-bin-release.zip为例;
[jenkins@test01 rocketmq]$ ll 总用量 12296 -rw-r--r--. 1 jenkins jenkins 12589252 10月 22 15:45 rocketmq-all-4.5.2-bin-release.zip [jenkins@test01 rocketmq]$ unzip rocketmq-all-4.5.2-bin-release.zip Archive: rocketmq-all-4.5.2-bin-release.zip creating: rocketmq-all-4.5.2-bin-release/ creating: rocketmq-all-4.5.2-bin-release/benchmark/ inflating: rocketmq-all-4.5.2-bin-release/benchmark/consumer.sh inflating: rocketmq-all-4.5.2-bin-release/benchmark/runclass.sh inflating: rocketmq-all-4.5.2-bin-release/benchmark/tproducer.sh inflating: rocketmq-all-4.5.2-bin-release/benchmark/producer.sh ........
然后参考官网快速启动文档: http://rocketmq.apache.org/docs/quick-start/
由于name server和broker默认配置为4g到8g的内存,如果服务器内存不足需要修改默认内存;
解决办法,找到runserver.sh和runbroker.sh,编辑 JAVA_OPT=”${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn125m-XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m”
[jenkins@test01 rocketmq]$ mv rocketmq-all-4.5.2-bin-release rocketmq-all-4.5.2 [jenkins@test01 rocketmq]$ cd rocketmq-all-4.5.2 [jenkins@test01 rocketmq-all-4.5.2]$ ll 总用量 44 drwxr-xr-x. 2 jenkins jenkins 4096 8月 2 10:05 benchmark drwxr-xr-x. 3 jenkins jenkins 4096 7月 31 21:11 bin drwxr-xr-x. 6 jenkins jenkins 4096 7月 31 21:09 conf drwxr-xr-x. 2 jenkins jenkins 4096 8月 2 10:05 lib -rw-r--r--. 1 jenkins jenkins 17336 7月 31 21:09 LICENSE -rw-r--r--. 1 jenkins jenkins 1338 7月 31 21:09 NOTICE -rw-r--r--. 1 jenkins jenkins 4020 7月 31 21:09 README.md [jenkins@test01 rocketmq-all-4.5.2]$ nohup sh bin/mqnamesrv > mqnamesrv.out & [1] 13179 nohup: 忽略输入重定向错误到标准输出端 [jenkins@test01 rocketmq-all-4.5.2]$ tail -500f mqnamesrv.out Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release. The Name Server boot success. serializeType=JSON
看到The Name Server boot success. serializeType=JSON代表已经部署name server成功。
[jenkins@test01 rocketmq-all-4.5.2]$ nohup sh bin/mqbroker -n 10.130.44.165:9876 > mqbroker.out & [8] 13782 [6] Exit 143 nohup sh bin/mqbroker -n 10.130.44.165:9876 > mqbroker.out [jenkins@test01 rocketmq-all-4.5.2]$ nohup: 忽略输入重定向错误到标准输出端 [jenkins@test01 rocketmq-all-4.5.2]$ tail -500f mqbroker.out The broker[test01, 10.130.44.165:10911] boot success. serializeType=JSON and name server is 10.130.44.165:9876
看到The broker[test01, 10.130.44.165:10911] boot success代表Broker已启动,并且已经连接到name server。
先设置 NAMESRV_ADDR环境变量,然后使用消息发送工具
[jenkins@test01 rocketmq-all-4.5.2]$ export NAMESRV_ADDR=localhost:9876 [jenkins@test01 rocketmq-all-4.5.2]$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer 14:55:28.799 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework RocketMQLog:WARN No appenders could be found for logger (io.netty.util.internal.PlatformDependent0). RocketMQLog:WARN Please initialize the logger system properly. SendResult [sendStatus=SEND_OK, msgId=0A822CA5432112A3A380747FC2A30000, offsetMsgId=0A822CA500002A9F0000000000000000, messageQueue=MessageQueue [topic=TopicTest, brokerName=test01, queueId=0], queueOffset=0] SendResult [sendStatus=SEND_OK, msgId=0A822CA5432112A3A380747FC3120001, offsetMsgId=0A822CA500002A9F00000000000000B2, messageQueue=MessageQueue [topic=TopicTest, brokerName=test01, …………………… SendResult [sendStatus=SEND_OK, msgId=0A822CA5432112A3A380747FD3FD03E7, offsetMsgId=0A822CA500002A9F000000000002BDFE, messageQueue=MessageQueue [topic=TopicTest, brokerName=test01, queueId=3], queueOffset=249] 14:55:34.461 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[127.0.0.1:9876] result: true 14:55:34.470 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[10.130.44.165:10911] result: true [jenkins@test01 rocketmq-all-4.5.2]$
启动消息接收工具,消息接收工具会一直等待消息发送,不会自动停止
[jenkins@test01 rocketmq-all-4.5.2]$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer 14:59:55.032 [main] DEBUG i.n.u.i.l.InternalLoggerFactory - Using SLF4J as the default logging framework Consumer Started. …………………… ConsumeMessageThread_2 Receive New Messages: [MessageExt [queueId=2, storeSize=180, queueOffset=485, sysFlag=0, bornTimestamp=1571813940924, bornHost=/10.130.44.165:58852, storeTimestamp=1571813940925, storeHost=/10.130.44.165:10911, msgId=0A822CA500002A9F0000000000055334, commitLogOffset=348980, bodyCRC=1786477042, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1571813984202, UNIQ_KEY=0A822CA543EA12A3A3807482FABC03AC, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 52, 48], transactionId='null'}]] ConsumeMessageThread_5 Receive New Messages: [MessageExt [queueId=2, storeSize=180, queueOffset=482, sysFlag=0, bornTimestamp=1571813940894, bornHost=/10.130.44.165:58852, storeTimestamp=1571813940895, storeHost=/10.130.44.165:10911, msgId=0A822CA500002A9F0000000000054AC4, commitLogOffset=346820, bodyCRC=855266886, reconsumeTimes=0, preparedTransactionOffset=0, toString()=Message{topic='TopicTest', flag=0, properties={MIN_OFFSET=0, MAX_OFFSET=500, CONSUME_START_TIME=1571813984200, UNIQ_KEY=0A822CA543EA12A3A3807482FA9E03A0, WAIT=true, TAGS=TagA}, body=[72, 101, 108, 108, 111, 32, 82, 111, 99, 107, 101, 116, 77, 81, 32, 57, 50, 56], transactionId='null'}]]
至此环境搭建完成,并通过测试。
停止需要先暂停broker,再停止namesrv,具体命令如下:
[jenkins@test01 rocketmq-all-4.5.2]$ sh bin/mqshutdown broker The mqbroker(13790) is running... Send shutdown request to mqbroker(13790) OK [jenkins@test01 rocketmq-all-4.5.2]$ sh bin/mqshutdown namesrv The mqnamesrv(13501) is running... Send shutdown request to mqnamesrv(13501) OK [jenkins@test01 rocketmq-all-4.5.2]$
RocketMq默认日志目录放在当前用户的logs目录下。
[jenkins@test01 rocketmqlogs]$ pwd /home/jenkins/logs/rocketmqlogs [jenkins@test01 rocketmqlogs]$ ll 总用量 31220 -rw-rw-r--. 1 jenkins jenkins 5063 10月 23 17:01 broker_default.log -rw-rw-r--. 1 jenkins jenkins 707575 10月 23 18:26 broker.log -rw-rw-r--. 1 jenkins jenkins 0 10月 22 17:03 commercial.log -rw-rw-r--. 1 jenkins jenkins 0 10月 22 17:03 filter.log -rw-rw-r--. 1 jenkins jenkins 0 10月 22 17:03 lock.log -rw-rw-r--. 1 jenkins jenkins 3157 10月 23 17:00 namesrv_default.log -rw-rw-r--. 1 jenkins jenkins 203504 10月 23 18:21 namesrv.log -rw-rw-r--. 1 jenkins jenkins 0 10月 22 17:03 protection.log -rw-rw-r--. 1 jenkins jenkins 157157 10月 23 18:19 remoting.log -rw-rw-r--. 1 jenkins jenkins 1368353 10月 23 18:19 rocketmq_client.log -rw-rw-r--. 1 jenkins jenkins 194451 10月 23 18:26 stats.log -rw-rw-r--. 1 jenkins jenkins 0 10月 22 17:03 storeerror.log -rw-rw-r--. 1 jenkins jenkins 3510867 10月 23 18:25 store.log -rw-rw-r--. 1 jenkins jenkins 1515006 10月 23 18:25 transaction.log -rw-rw-r--. 1 jenkins jenkins 24251040 10月 23 18:26 watermark.log
到此,相信大家对“RokcetMq安装和快速启动的方法”有了更深的了解,不妨来实际操作一番吧!这里是创新互联网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!