Maven/Docker快速搭建RocketMQ

官方文档 [https://rocketmq.apache.org/docs/quick-start/]

①:Bin_二进制安装版

1. 环境准备

系统环境:Centos7 x64
JDK:jdk-8u171-linux-x64
Maven:3.2.x以上的版本均可
4g+ free disk for Broker server

2. 下载RocketMQ

https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.4.0/rocketmq-all-4.4.0-bin-release.zip

3. 解压

> unzip rocketmq-all-4.4.0-bin-release.zip
> cd rocketmq-all-4.4.0/

4. 根据内存修改配置(默认需要4G+4G 共8G)

cd bin
vim runserver.sh 
# 找到如下配置
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"
# 修改成你可以接受的范围
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx521m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

vim runbroker.sh
# 找到如下配置
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
# 修改成你可以接受的范围
JAVA_OPT="${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m"

4.1. 配置环境变量

vim /etc/profile
# 将如下配置加到最后一行
export NAMESRV_ADDR=127.0.0.1:9876
#立即生效环境配置
source /etc/profile

5. 启动 Name Server

  > nohup sh bin/mqnamesrv &
  #查看日志
  > tail -f ~/logs/rocketmqlogs/namesrv.log
    The Name Server boot success...

6. 启动 Broker

  > nohup sh bin/mqbroker -n 127.0.0.1:9876 &
  #查看日志
  > tail -f ~/logs/rocketmqlogs/broker.log 
    The broker[%s, 127.0.0.1:10911] boot success...

7.测试收发消息 Send & Receive Messages

注意:此处tools.sh默认(-Xms1g -Xmx1g),内存不够需要再次按runserver.sh/runbroker.sh方式修改
# 修改成你可以接受的范围
vi tools.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

 # export NAMESRV_ADDR=localhost:9876
 > sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
 
 SendResult [sendStatus=SEND_OK, msgId= ...
 > sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
 
 ConsumeMessageThread_%d Receive New Messages: [MessageExt...

8. 关闭RocketMQ服务 Shutdown 1.broker --> 2.namesrv

> 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

②:Docker版

docker search rocketmq
docker pull foxiswho/rocketmq:server-4.5.1
docker pull foxiswho/rocketmq:broker-4.5.1

下面的就是分步启动nameserver和broker。
1.启动NameServer
docker run -d -p 9876:9876 --name rmqserver  foxiswho/rocketmq:server-4.5.1
2.启动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参数指定本机的配置文件:`-v /conf/broker.conf:/etc/rocketmq/broker.conf`

#查看验证启动成功
docker ps|grep rocketmq

#测试收发
vi tools.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"
进入容器内部执行shell
发(生产者): `sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer`
收(消费者): `sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer`

发送成功则显示:SendResult [sendStatus=SEND_OK, msgId= ...
消费成功则显示:ConsumeMessageThread_%d Receive New Messages: [MessageExt...

③:rocketmq-console 可视化监控服务配置

官方文档
[https://github.com/apache/rocketmq-externals/tree/master/rocketmq-console]

docker镜像版

mvn clean package -Dmaven.test.skip=true docker:build
或
docker pull styletang/rocketmq-console-ng
#运行
docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 -t styletang/rocketmq-console-ng

maven编译普通版

cd /usr/local/rocketmq-externals
git clone https://github.com/apache/rocketmq-externals

#修改配置文件
vi /usr/local/rocketmq/rocketmq-externals/rocketmq-console/src/main/resources/application.properties

# 修改如下相应配置
server.port=8080 //服务端口号
rocketmq.config.namesrvAddr=127.0.0.1:9876 //配置服务地址
rocketmq.config.dataPath=/tmp/rocketmq-console/data //mq数据路径,可以自己修改

#使用maven打包

cd /usr/local/rocketmq/rocketmq-externals/rocketmq-console
mvn clean package -Dmaven.test.skip=true
或
mvn spring-boot:run

#后台运行
nohup java -jar -Xms256m -Xmx256m -Xmn125m rocketmq-console-ng-1.0.1.jar --server.port=8080 --rocketmq.config.namesrvAddr=127.0.0.1:9876 >rocketmq-console.log 2>&1 &
posted @ 2019-11-14 14:52  Zzzang  阅读(790)  评论(0编辑  收藏  举报