RocketMQ环境搭建
安装
服务器需要开放9876
、10909
、10911
三个端口
下载二进制包:RocketMQ 并解压到指定目录
启动
# 启动namesrv
$ nohup sh bin/mqnamesrv &
# 验证namesrv是否启动成功
$ tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
# 先启动broker
$ nohup sh bin/mqbroker -n localhost:9876 &
# 验证broker是否启动成功, 比如, broker的ip是192.168.1.2 然后名字是broker-a
$ tail -f ~/logs/rocketmqlogs/Broker.log
The broker[broker-a,192.169.1.2:10911] boot success...
测试
$ export NAMESRV_ADDR=localhost:9876
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
$ sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
关闭
$ sh bin/mqshutdown broker
The mqbroker(36695) is running...
Send shutdown request to mqbroker(36695) OK
$ sh bin/mqshutdown namesrv
The mqnamesrv(36664) is running...
Send shutdown request to mqnamesrv(36664) OK
问题
问题一:在服务器上测试没问题,使用其他电脑测试报错
org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:634)
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1279)
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1225)
at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:283)
at org.apache.rocketmq.example.quickstart.Producer.main(Producer.java:67)
09:59:04.727 [NettyClientSelector_1] INFO RocketmqRemoting - closeChannel: close the connection to remote address[] result: true
测试一下9876
端口
$ nc -vz -w 2 192.168.0.254 9876
Connection to 192.168.0.254 port 9876 [tcp/sd] succeeded!
端口是通的,没办法只能Google一下错误
解决方案
-
修改
conf/broker.conf
文件添加如下代码
namesrvAddr = localhost:9876 brokerIP1 = [服务器IP] autoCreateTopicEnable = true
-
重新启动broker,并指定
conf/broker.conf
配置文件nohup sh bin/mqbroker -n localhost:9876 -c conf/broker.conf &
问题二:内存占用过大,造成服务器卡顿
启动RocketMQ后直接吃了6G内存,卡的服务器命令都执行不了了
解决方案
-
修改
bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx1024m -Xmn125m -XX:MetaspaceSize=1024m -XX:MaxMetaspaceSize=1024m"
-
修改
bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx1024m -Xmn125m"
参考链接