https://my.oschina.net/langxSpirit/blog/910177
摘要: 官网的Quick Start太简陋,很多坑在里面,这里整理记录一下、
一、安装与配置
1、下载
官网:http://rocketmq.apache.org/
如:rocketmq-all-4.0.0-incubating-bin-release.zip
需要
64bit OS, Linux/Unix/Mac is recommended;
64bit JDK 1.7+;
2、复制到对应目录,linux中解压
复制rocketmq-all-4.0.0-incubating-bin-release.zip到 /opt/rocketmq
mkdir /opt/rocketmq
cd /opt/rocketmq
unzip rocketmq-all-4.0.0-incubating-bin-release.zip
3、增加执行权限:
cd bin
chmod +x *
4、增加环境变量
vi /etc/profile
使用vi 编辑器,在profile文件的末尾加入如下命令:
export ROCKETMQ_HOME=/opt/rocketmq/apache-rocketmq-all
export PATH=$PATH::$ROCKETMQ_HOME/bin
输入:wq! 保存并退出
使得配置立刻生效:
source /etc/profile
5、创建日志目录
cd /opt/rocketmq && mkdir logs
6、启动Name Server
cd /opt/rocketmq/apache-rocketmq-all/bin
&& nohup sh mqnamesrv > /opt/rocketmq/logs/mqnamesrv.log 2> /opt/rocketmq/logs/mqnamesrv.log &
7、配置Broker
启动之前,可以适当更改一下runbroker.sh参数
runbroker.sh需要根据内存大小进行适当地调整
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xgmn1g -XX:PermSize=1g -XgX:MaxPermSize=1g"
本机为虚拟机,就设置小点,1-2g内存,如下:
修改配置文件:conf/2m-noslave/broker-a.properties
样例:
listenPort=10911
namesrvAddr=192.168.62.100:9876
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=72
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
其中 192.168.62.100 为虚拟机静态ip
8、启动Broker
cd /opt/rocketmq/apache-rocketmq-all/bin
&& nohup sh mqbroker autoCreateTopicEnable=true
-c /opt/rocketmq/apache-rocketmq-all/conf/2m-noslave/broker-a.properties
> /opt/rocketmq/logs/mqbroker.log 2>/opt/rocketmq/logs/mqbroker.log &
autoCreateTopicEnable=true 允许 Broker 自动创建Topic,建议线下开启,线上关闭
9、测试
测试生产者:
cd /opt/rocketmq/apache-rocketmq-all
export NAMESRV_ADDR=localhost:9876
sh /opt/rocketmq/apache-rocketmq-all/bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
测试消费者:
sh /opt/rocketmq/apache-rocketmq-all/bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
测试OK。
ps aux | grep java | awk '/broker/rocketmq_nameserver'
ps aux | grep java | awk '/broker/rocketmq_brokerserver'
tail -f /opt/rocketmq/logs/mqnamesrv.log
tail -f /opt/rocketmq/logs/mqbroker.log
cd /opt/rocketmq/apache-rocketmq-all/bin && sh mqshutdown namesrv
cd /opt/rocketmq/apache-rocketmq-all/bin && sh mqshutdown broker
1、如果消费者、生产者位于不通的网段需要经过防火墙的话,需要开通到broker和nameserver的防火墙端口
lokkit -p 9876:tcp -p 10911:tcp
2、 connect to <192.168.62.100:10909> failed
Rocket默认开启了VIP通道,VIP通道端口为10911-2=10909。若Rocket服务器未启动端口10909,则报connect to <> failed。
解决方式:
1)增加一行代码
producer.setVipChannelEnabled(false);
2)增加对端口10909的防火墙开启。