Maven/Docker快速搭建RocketMQ
程序员文章站
2022-08-06 15:50:57
"官方文档" [https://rocketmq.apache.org/docs/quick start/] ①:Bin_二进制安装版 1. 环境准备 系统环境:Centos7 x64 JDK:jdk 8u171 linux x64 Maven:3.2.x以上的版本均可 4g+ free disk ......
[]
①:bin_二进制安装版
1. 环境准备
系统环境:centos7 x64
jdk:jdk-8u171-linux-x64
maven:3.2.x以上的版本均可
4g+ free disk for broker server
2. 下载rocketmq
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 可视化监控服务配置
[]
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 &