RocketMQ4.9.0下载链接
mac推荐一款工具,用于FTP文件上传~
以上步骤自行脑补一下,略~
[root@hgwtencent RocketMQ]# pwd
/soft/RocketMQ
[root@hgwtencent RocketMQ]# ll
总用量 17764
-rw-r--r-- 1 root root 18186461 11月 29 16:15 rocketmq-all-4.9.0-bin-release.zip
[root@hgwtencent RocketMQ]# unzip rocketmq-all-4.9.0-bin-release.zip
RocketMQ目录结构 :
[root@hgwtencent RocketMQ]# cd rocketmq-all-4.9.0-bin-release/
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# ll
总用量 48
drwxr-xr-x 2 root root 4096 6月 11 2021 benchmark # 启动脚本,包括shell脚本和cmd脚本
drwxr-xr-x 3 root root 4096 6月 11 2021 bin # 实例配置文件,包括broker配置文件、logback配置文件等
drwxr-xr-x 6 root root 4096 6月 11 2021 conf # 依赖jar包,包括netty、commons-lang、FastJSON等
drwxr-xr-x 2 root root 4096 6月 11 2021 lib
-rw-r--r-- 1 root root 17327 6月 9 2021 LICENSE
-rw-r--r-- 1 root root 1338 6月 9 2021 NOTICE
-rw-r--r-- 1 root root 5132 6月 9 2021 README.md
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# cd bin
[root@hgwtencent bin]# echo $JAVA_HOME
/usr/java/jdk1.8.0_311-amd64
[root@hgwtencent bin]# vim tools.sh
在红框后面追加上本机jdk环境/jre/lib/ext
如:
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext:${JAVA_HOME}/lib/exti:/usr/java/jdk1.8.0_311-amd64/jre/lib/ext"
Rocketmq默认的虚拟机内存较大,启动broker如果因为内存不足失败,需要编辑如下两个配置文件,去修改JVM内存大小 (根据自身服务器配置决定是否修改)
[root@hgwtencent bin]# vim runserver.sh
#参考设置
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn512m -XX:MetaspaceSize=256m -XX:MaxMetaspaceSize=256m"
原先
修改为下图的配置:
2、修改 runbroker.sh 内存大小
[root@hgwtencent bin]# vim runbroker.sh
#参考设置
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"
启动NameServer
# 以后台进程运行,日志输出到namesrv.log 将错误信息重定向到标准输出
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# touch namesrv.log
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# nohup sh bin/mqnamesrv > namesrv.log 2>&1 &
以后台运行后的方式去执行启动脚本,查看日志 :
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# tail -f ~/logs/rocketmqlogs/namesrv.log
启动Broker一共有两种方式,分别是 本地部署(linux) 和 外网部署,这里主要演示外网部署,命令贴在下面
本地部署
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# nohup sh bin/mqbroker -n localhost:9876 &
外网部署
1、首先需求修改一下配置文件:
[root@hgwtencent conf]# pwd
/soft/RocketMQ/rocketmq-all-4.9.0-bin-release/conf
[root@hgwtencent conf]# vim broker.conf
[root@hgwtencent conf]# cat broker.conf
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
namesrvAddr=124.222.223.222:9876
brokerIP1=124.222.223.222
23 namesrvAddr=服务器外网ip:9876
24 brokerIP1=服务器外网ip
2、启动Broker
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# touch broker.log
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# nohup bin/mqbroker -c conf/broker.conf > broker.log 2>&1 &
[2] 4718
以后台运行后的方式去执行启动脚本,查看日志 :
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# tail -f ~/logs/rocketmqlogs/broker.log
# 1.关闭 Broker
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# sh bin/mqshutdown broker
The mqbroker(14968) is running...
Send shutdown request to mqbroker(14968) OK
# 2.关闭 NameServer
[root@hgwtencent rocketmq-all-4.9.0-bin-release]# sh bin/mqshutdown namesrv
The mqnamesrv(14826) is running...
Send shutdown request to mqnamesrv(14826) OK
[2]+ 退出 143 nohup sh bin/mqbroker -n localhost:9876
在发送或接收消息之前,开发者需要通知客户端name servers 的位置。RocketMQ提供多种 实现方式。为了简单起见下方展示环境变量NAMESRV_ADDR的用法 :
# 设置环境变量:
export NAMESRV_ADDR=localhost:9876
使用安装包的Demo发送消息:
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
SendResult [sendStatus=SEND_OK, msgId= ...
接受消息 (bin目录下) :
> sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
ConsumeMessageThread_%d Receive New Messages: [MessageExt...
RocketMQ有一个可视化的dashboard,通过该控制台可以直观的查看到很多数据。
RocketMQ有一个对其扩展的开源项目: incubator-rocketmq-externals,这个项目中有一个子模块叫 rocketmq-console。这个便是管理控制台项目。
步骤是先将 incubator-rocketmq-externals 从 git 拉到本地,然后对 rocketmq-console进行操作(编译打包运行)
git地址 : https://github.com/SummerUnfair/rocketmq-externals/tags
gwh@GWdeMacBook-Pro [13:43:43] [~/Documents/Software/tools/rocketmq]
-> % pwd
/Users/gwh/Documents/Software/tools/rocketmq
gwh@GWdeMacBook-Pro [13:43:44] [~/Documents/Software/tools/rocketmq]
-> % unzip rocketmq-externals-rocketmq-console-1.0.0.zip
修改其src/main/resources中的application.properties配置文件 :
gwh@GWdeMacBook-Pro [13:45:20] [~/Documents/Software/tools/rocketmq/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-console/src/main/resources]
-> % pwd
/Users/gwh/Documents/Software/tools/rocketmq/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-console/src/main/resources
gwh@GWdeMacBook-Pro [13:45:21] [~/Documents/Software/tools/rocketmq/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-console/src/main/resources]
-> % ll
total 16
-rw-r--r--@ 1 gwh staff 741B 6 15 2017 application.properties
-rw-r--r--@ 1 gwh staff 1.1K 6 15 2017 logback.xml
drwxr-xr-x@ 7 gwh staff 224B 6 15 2017 static
gwh@GWdeMacBook-Pro [13:45:32] [~/Documents/Software/tools/rocketmq/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-console/src/main/resources]
-> % vim application.properties
大家自行修改为自己的部署的RocketMQ的ip:端口。
在解压目录rocketmq-console的pom.xml中添加如下JAXB依赖。
JAXB,Java Architechture for Xml Binding,用于XML绑定的Java技术,是一个业界标准,是一 项可以根据XML Schema生成Java类的技术
依赖如下:
<dependency>
<groupId>javax.xml.bindgroupId>
<artifactId>jaxb-apiartifactId>
<version>2.3.0version>
dependency>
<dependency>
<groupId>com.sun.xml.bindgroupId>
<artifactId>jaxb-implartifactId>
<version>2.3.0version>
dependency>
<dependency>
<groupId>com.sun.xml.bindgroupId>
<artifactId>jaxb-coreartifactId>
<version>2.3.0version>
dependency>
<dependency>
<groupId>javax.activationgroupId>
<artifactId>activationartifactId>
<version>1.1.1version>
dependency>
在rocketmq-console目录下运行maven的打包命令。
在/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-consol
项目目录下,执行以下打包命令
mvn clean package -Dmaven.test.skip=true
出现 BUILD SUCCESS
即打包成功~
在
/rocketmq-externals-rocketmq-console-1.0.0/rocketmq-console/target
执行以下启动命令~
在云服务器上开辟端口,并将本地jar包上传并运行(大家也可以将其打成Docker镜像运行)
[root@hgwtencent rocketmq-console]# touch rocketmq-console.log
[root@hgwtencent rocketmq-console]# ll
总用量 30300
-rw-r--r-- 1 root root 0 12月 2 14:14 rocketmq-console.log
-rw-r--r-- 1 root root 31025914 12月 2 14:14 rocketmq-console-ng-1.0.0.jar
run起来!
[root@hgwtencent rocketmq-console]# nohup java -jar rocketmq-console-ng-1.0.0.jar &> rocketmq-console.log &
查看一下:
[root@hgwtencent rocketmq-console]# ps -ef|grep "java -jar"
root 22657 21241 84 14:15 pts/0 00:00:21 java -jar rocketmq-console-ng-1.0.0.jar
root 22809 21241 0 14:16 pts/0 00:00:00 grep --color=auto java -jar
第一步、启动 NameServer
docker run -d -p 9876:9876 --name rmqserver foxiswho/rocketmq:server-4.5.1
第二步、启动broker
docker run -d -p 10911:10911 -p 10909:10909\
--name rmqbroker --link rmqserver:namesrv\
-e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt"\
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m"\
foxiswho/rocketmq:broker-4.5.1
Broker容器中默认的配置文件的路径为:
/etc/rocketmq/broker.conf
也可以通过-v参数指定本机的配置文件:
docker run -d -p 10911:10911 -p 10909:10909\
--name rmqbroker --link rmqserver:namesrv\
-e "NAMESRV_ADDR=namesrv:9876" -e "JAVA_OPTS=-Duser.home=/opt"\
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m"\
-v /conf/broker.conf:/etc/rocketmq/broker.conf \
foxiswho/rocketmq:broker-4.5.1
第三步、启动 rocketmq console
如果一切正常,NameServer和Broker一会儿就会安装好,为了管理上的方便,rocketmq console也是必不可少的工具了,通过上面查询的方式找到需要启动的版本,启动方式如下:
docker run -d --name rmqconsole -p 8180:8080 --link rmqserver:namesrv\
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876\
-Dcom.rocketmq.sendMessageWithVIPChannel=false"\
-t styletang/rocketmq-console-ng
然后通过如下命令检查一下启动情况:
docker ps|grep rocketmq