环境
CentOS 8
Maven
安装包准备
-
安装包下载:https://www.apache.org/dyn/closer.cgi?path=rocketmq/4.9.0/rocketmq-all-4.9.0-source-release.zip
并解压 -
需要maven编译
-
构建二级制文件
mvn -Prelease-all -DskipTests clean install -U
启动
- 启动NameServer
nohup sh mqnamesrv >/usr/local/src/rocketmq/rocketmq-all-4.9.0-source-release/distribution/log/mqnamesrv.log &
查看日志:
[root@10-211-55-6 log]# tail -f mqnamesrv.log
OpenJDK 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
OpenJDK 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
OpenJDK 64-Bit Server VM warning: MaxNewSize (131072k) is equal to or greater than the entire heap (131072k). A new max generation size of 131008k will be used.
The Name Server boot success. serializeType=JSON
- 启动broker
nohup sh mqbroker -n localhost:9876 autoCreateTopicEnable=true >/usr/local/src/rocketmq/rocketmq-all-4.9.0-source-release/distribution/log/mqbroker.log &
autoCreateTopicEnable=true
: 自动创建topic
指定配置文件启动
nohup sh bin/mqbroker -n localhost:9876 -c ./conf/broker.conf >/usr/local/src/rocketmq/rocketmq-all-4.9.0-source-release/distribution/log/mqbroker.log &
查看日志
The broker[10-211-55-6, 10.211.55.6:10911] boot success. serializeType=JSON and name server is localhost:9876
注:注意启动完看日志,可能会报出Cannot allocate memory内存不足的错,解决办法(修改target下的配置文件记得在每次maven构建的时候再修改一次(可能你安装完就不会再构建一次了),或者直接修改/distribution/bin目录下的文件):
vi runserver.sh
#修改这里的配置内存
JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=256m"
vi runbroker.sh/
#修改这里的配置内存
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=256m"
vi tools.sh/
#修改这里的配置内存
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m -XX:PermSize=128m -XX:MaxPermSize=128m"
常用命令
sh bin/mqshutdown broker //停止 broker
sh bin/mqshutdown namesrv //停止 nameserver
./mqadmin clusterList -n 127.0.0.1:9876 #查看集群情况
./mqadmin brokerStatus -n 127.0.0.1:9876 -b 172.20.1.138:10911 #查看 broker 状态 (注意换成你的 broker 地址)
./mqadmin topicList -n 127.0.0.1:9876 #查看 topic 列表
./mqadmin topicStatus -n 127.0.0.1:9876 -t MyTopic #查看 topic 状态 (换成你想查询的 topic)
./mqadmin topicRoute -n 127.0.0.1:9876 -t MyTopic #查看 topic 路由
ps -aux | grep mq # mq运行状态
测试(可忽略)
#在发送/接收消息之前,我们需要告诉客户名称服务器的位置。RocketMQ 提供了多种方法来实现这一点。为了简单起见,我们使用环境变量NAMESRV_ADDR
export NAMESRV_ADDR=localhost:9876
#发送消息
sh tools.sh org.apache.rocketmq.example.quickstart.Producer
#接收消息
sh tools.sh org.apache.rocketmq.example.quickstart.Consumer