Apache RocketMQ
官网:http://rocketmq.apache.org/
外部Github:https://github.com/apache/rocketmq-externals
Linux安装配置
rocketmqHome=/opt/rocketmq/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1
- 修改
distribution
目录下bin/runserver
和bin/runbroker
的JVM运行内存,GC回收最大内存; - 修改
distribution
目录下conf/broker.conf
和conf/plain_acl.yml
的配置信息,启用acl认证;
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
listenPort=10915
namesrvAddr=127.0.0.1:9876
autoCreateTopicEnable=false
aclEnable=true
- 打包
mvn -Prelease-all -DskipTests clean install -U
Start Name Server
> nohup sh bin/mqnamesrv &
> tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...
Start Broker
/etc/profile设置环境变量,增加到文件末尾
export ROCKETMQ_HOME = /opt/rocketmq/...
生效环境变量:source /etc/profile
> nohup sh bin/mqbroker -n localhost:9876 &
or
> nohup sh bin/mqbroker -c conf/broker.conf &
> tail -fn 500 ~/logs/rocketmqlogs/broker.log
The broker[%s, 172.30.30.233:10911] boot success...
Shutdown Servers
> 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
修改源码打包出错解决办法
1. 错误信息
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-checkstyle-plugin:2.17:check (verify) on project rocketmq-client: Failed during checkstyle execution: There are 38 errors reported by Checkstyle 6.11.2 with style/rmq_checkstyle.xml ruleset. -> [Help 1]
2. 原因
项目依赖了 maven-checkstyle-plugin插件,编译打包时会根据对应配置文件检查。很多时候从网络下载的开源项目,我们只关注能否编译过,可以将此插件去掉或者关闭,这里采用关闭的方式来解决。
3. 解决办法
3.1 方法一
maven编译的时候增加参数checkstyle.skip=true
加参数记得用D:
clean install -Dcheckstyle.skip=true
扩展
用skipTests=true可以跳过执行单元测试
clean install -DskipTests=true -Dcheckstyle.skip=true
3.2 方法二
在configuration标签下,增加skip标签,跳过检查
<plugin>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.17</version>
<executions>
<execution>
<id>verify</id>
<phase>verify</phase>
<configuration>
<skip>true</skip>
<configLocation>style/rmq_checkstyle.xml</configLocation>
<encoding>UTF-8</encoding>
<consoleOutput>true</consoleOutput>
<failsOnError>true</failsOnError>
<includeTestSourceDirectory>false</includeTestSourceDirectory>
</configuration>
<goals>
<goal>check</goal>
</goals>
</execution>
</executions>
</plugin>
再clean install,就可以了。
启用认证
plain_acl.yml格式错误导致的问题:
ERROR: java.lang.ClassCastException: java.lang.Class cannot be cast to org.apache.rocketmq.acl.AccessValidator
Reason: Initialization failed while loading 'PlainAccessValidator'.
Console
启动脚本
#!/bin/bash
echo "打开目录"
cd /opt/rocketmq/rocketmq-all-4.7.1-source-release/distribution/target/rocketmq-4.7.1/rocketmq-4.7.1
if [ "$1" == "stop" ]
then
echo "开始停止..."
sh bin/mqshutdown broker
sleep 2
sh bin/mqshutdown namesrv
echo "停止成功!"
elif [ "$1" == "start" ]
then
echo "开始启动..."
nohup sh bin/mqnamesrv &
sleep 10
nohup sh bin/mqbroker -c conf/broker.conf &
echo "启动成功!"
tail -f ~/logs/rocketmqlogs/broker.log
fi