CentOS1核2G安装RocketMQ

安装JDK

可以到https://repo.huaweicloud.com/java/jdk/去查看对应的JDK安装包。
这里使用JDK1.8:

wget https://repo.huaweicloud.com/java/jdk/8u152-b16/jdk-8u152-linux-x64.rpm

直接使用rpm命令安装即可:

rpm -i jdk-8u152-linux-x64.rpm
=============分割线====================
[root@LengDanran ~]# rpm -i jdk-8u152-linux-x64.rpm 
Unpacking JAR files...
	tools.jar...
	plugin.jar...
	javaws.jar...
	deploy.jar...
	rt.jar...
	jsse.jar...
	charsets.jar...
	localedata.jar...

下载并启动 RocketMQ4.4.0 version

http://rocketmq.apache.org/release_notes/

wget https://archive.apache.org/dist/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-release.zip

解压缩到/usr/local/rocketmq

mkdir /usr/local/rocketmq
unzip rocketmq-all-4.4.0-bin-release.zip -d /usr/local/rocketmq/
cd /usr/local/rocketmq/rocketmq-all-4.4.0-bin-release/

nohup ./bin/mqnamesrv -n 你的公网IP:9876 >> namesrv.log
# 此时会出现这样的结果:
=================================分割线=========================================
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.
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000006c0000000, 2147483648, 0) Failed; error='Cannot allocate memory' (errno=12)
=====================================分割线=======================================
说明是内存太小,启动不起来,需要修改内存配置文件:
启动内存配置
由于name server和broker认配置为4g到8g的内存,如果服务器内存不足需要修改认内存;
解决办法,找到runserver.sh和runbroker.sh,编辑 
JAVA_OPT="${JAVA_OPT} -server -xms64m -Xmx128m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"


修改内存配置文件

文件在bin目录下:

./bin/runserver.sh

#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -xms64m -Xmx128m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

./bin/runbroker.sh

#===========================================================================================
# JVM Configuration
#===========================================================================================
JAVA_OPT="${JAVA_OPT} -server -xms64m -Xmx128m -Xmn128m"

修改./conf/broker.conf文件

文件末尾添加

brokerIP1 = 你的公网ip

启动namesrv:

nohup ./bin/mqnamesrv -n 你的公网IP:9876 >> namesrv.log &

启动broker

nohup sh ./bin/mqbroker -n 47.98.166.246:9876 -c ./conf/broker.conf autocreateTopicEnable=true >> broker.log &

autocreateTopicEnable=true一定要加,不然使用客户端连接的时候会出现No route info of this topic的异常

注意:服务器端口问题会导致timeout异常

使用Spring来测试:

org.apache.rocketmq.remoting.exception.RemotingTooMuchRequestException: sendDefaultImpl call timeout
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.sendDefaultImpl(DefaultMQProducerImpl.java:612) ~[rocketmq-client-4.3.1.jar:4.3.1]
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1253) ~[rocketmq-client-4.3.1.jar:4.3.1]
at org.apache.rocketmq.client.impl.producer.DefaultMQProducerImpl.send(DefaultMQProducerImpl.java:1203) ~[rocketmq-client-4.3.1.jar:4.3.1]
at org.apache.rocketmq.client.producer.DefaultMQProducer.send(DefaultMQProducer.java:214) ~[rocketmq-client-4.3.1.jar:4.3.1]

在出这个异常之前有[NettyClientSelector_1] INFO RocketmqRemoting.info (Slf4jLoggerFactory.java:95)
closeChannel: close the connection to remote address[] result: true

通过telnet验证过9876端口是通的
rocketMQ后台管理界面有应用机器ip,master的broker.log中查看也有对应ip。但是就是发消息失败

可以参考:

https://github.com/apache/rocketmq/issues/568

maybe you should close the vip channel,detail can see Apache RocketMQ单机部署

rocket除了9876其实还有两个端口
10911
10909

10909是VIP通道对应的端口,在JAVA中的消费者对象或者是生产者对象中关闭VIP通道即可无需开放10909端口

使用如下方法
setVipChannelEnabled(false);
详细的可以看看Apache RocketMQ单机部署

所以应当放开 9876,10911,10909这三个端口

测试

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native