1:在安装mq之前先确保安装了以下软件 不然会在编译时报 git,mvn命令找不到,这几个文件均安装在 /usr/local下
git-2 13.1.tar.gz
apache-maven-3.5.0-bin.tar.gz
RocketMQ-3.5.8.tar.gz
jdk-8u131-linux-x64.tar.gz
如图所示
2 :安装完 jdk和maven之后再/ect/profile中配置环境变量 执行 source profile 使得环境变量生效
export JAVA_HOME=/usr/local/jdk1.8.0_131
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
MAVEN_HOME=/usr/local/apache-maven-3.5.0
export MAVEN_HOME
export PATH=${PATH}:${MAVEN_HOME}/bin
3:将rocketMQ解压到/usr/local/rockemq-source下,解压过后在/usr/local/rockemq-source/RocketMQ-3.5.8/下执行命令 sh Install.sh 进行编译
编译后源文件中会新增以下文件,而我们执行命令真正要操作的是 target下边bin(/usr/local/rockemq-source/RocketMQ-3.5.8/devenv/bin)中的各项命令,否则容易出现 Could not find or load main class 类似的错误
drwxr-xr-x 5 root root 4096 Jun 27 16:56 target
lrwxrwxrwx 1 root root 47 Jun 27 16:56 devenv -> target/alibaba-rocketmq-broker/alibaba-rocketmq
安装目录如图
4:配置mq的环境变量并使其生效
echo "ROCKETMQ_HOME=`pwd`" >> ~/.bash_profile
source ~/.bash_profile
我查看了下./bash_profile中写入的配置(/root文件夹下用 ls -al命令查看)
PATH=$PATH:$HOME/bin
export PATH
ROCKETMQ_HOME=/usr/local/rockemq-source/RocketMQ-3.5.8/devenv
5:启动 mqnameserver
nohup sh mqnamesrv &
注意启动时报错如下
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
Error: Could not find or load main class com.alibaba.rocketmq.namesrv.NamesrvStartup
不能加载启动类说明配置mq环境变量不对, 改成【步骤四】设置mq环境变量的方式或者参考是不是没有按照【步骤三】来设置来排查问题,当然也可以参考链接分析这个问题
点击打开链接
再次启动报如下错误
java.lang.ExceptionInInitializerError
at com.alibaba.rocketmq.namesrv.NamesrvStartup.main0(NamesrvStartup.java:103)
at com.alibaba.rocketmq.namesrv.NamesrvStartup.main(NamesrvStartup.java:51)
Caused by: java.lang.RuntimeException: InetAddress java.net.InetAddress.getLocalHost() throws UnknownHostException
See http://docs.aliyun.com/cn#/pub/ons/faq/exceptions&unknown_host for further details.
at com.alibaba.rocketmq.common.MixAll.localhost(MixAll.java:433)
at com.alibaba.rocketmq.common.MixAll.(MixAll.java:67)
... 2 more
Caused by: java.net.UnknownHostException: nginx57: nginx57: Name or service not known
at java.net.InetAddress.getLocalHost(InetAddress.java:1505)
at com.alibaba.rocketmq.common.MixAll.localhost(MixAll.java:429)
... 3 more
Caused by: java.net.UnknownHostException: nginx57: Name or service not known
at java.net.Inet6AddressImpl.lookupAllHostAddr(Native Method)
at java.net.InetAddress$2.lookupAllHostAddr(InetAddress.java:928)
at java.net.InetAddress.getAddressesFromNameService(InetAddress.java:1323)
at java.net.InetAddress.getLocalHost(InetAddress.java:1500)
... 4 more
network文件配置
NETWORKING=yes
HOSTNAME=nginx57
hosts文件配置
127.0.0.1 nginx57
::1 localhost localhost.localdomain localhost7 localhost7.localdomain7
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
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
nohup sh mqbroker -n localhost:9876 autoCreateTopicEnable=true &
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=128m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=320m; support was removed in 8.0
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: Cannot open file /root/tmpfs/logs/gc.log due to No such file or directory
The broker[nginx57, 192.168.100.57:10911] boot success. serializeType=JSON and name server is localhost:9876
ps aux | grep java
root 7894 0.1 1.5 6327268 127820 pts/0 Sl Jun27 2:12 /usr/local/jdk1.8.0_131/bin/java -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC -verbose:gc -Xloggc:/root/rmq_srv_gc.log -XX:+PrintGCDetails -XX:-OmitStackTraceInFastThrow -Djava.ext.dirs=/usr/local/rockemq-source/RocketMQ-3.5.8/devenv/bin/../lib -cp .:/usr/local/rockemq-source/RocketMQ-3.5.8/devenv/bin/../conf:.:/usr/local/jdk1.8.0_131/lib/tools.jar:/usr/local/jdk1.8.0_131/lib/dt.jar com.alibaba.rocketmq.namesrv.NamesrvStartup
root 8174 36.0 7.3 6313384 593116 pts/0 Sl 14:25 7:18 /usr/local/jdk1.8.0_131/bin/java -server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320m -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC -verbose:gc -Xloggc:/root/tmpfs/logs/gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:-OmitStackTraceInFastThrow -XX:+AlwaysPreTouch -Djava.ext.dirs=/usr/local/rockemq-source/RocketMQ-3.5.8/devenv/bin/../lib -cp .:/usr/local/rockemq-source/RocketMQ-3.5.8/devenv/bin/../conf:.:/usr/local/jdk1.8.0_131/lib/tools.jar:/usr/local/jdk1.8.0_131/lib/dt.jar com.alibaba.rocketmq.broker.BrokerStartup -n localhost:9876 autoCreateTopicEnable=true
测试我是照着网上网友的给的测试项目导入到eclipse中直接拿来测试的 将里边的地址改成自己搭建的mq地址就行
http://download.csdn.net/download/tianwei7518/8138705
在测试过程中碰见的问题如下
No route info of this topic TopicTest1
这个问题我出现的原因是没有关闭 安装rocketMq服务器的防火墙,但是貌似有很多原因都会导致这个问题具体可参链接
https://github.com/alibaba/RocketMQ/issues/44
测试成功