10.10.0.138
github官方地址:https://github.com/apache/rocketmq-docker
#下载
wget -O rocketmq-docker.zip https://github.com/apache/rocketmq-docker/archive/refs/heads/master.zip
#解压
unzip rocketmq-docker.zip
构建镜像
cd rocketmq-docker-master/image-build
sh build-image.sh 4.8.0 alpine
提示结果为成功
Successfully built d8d1c5e4f5e4
Successfully tagged apacherocketmq/rocketmq:4.8.0-alpine
查看镜像
docker images | grep rocketmq
apacherocketmq/rocketmq 4.8.0-alpine d8d1c5e4f5e4 47 seconds ago 145MB
#只有一个镜像,namesvr和broker 是通过不同指令来启动的
服务启动方式有多种,目前采用第2种方式,双主集群。
1. Single Node
2. Cluster with docker-compose
3. Cluster on Kubernetes
4. Cluster of Dledger storage
生成各种部署方案
sh stage.sh 4.8.0
以下为输出
Stage version = 4.8.0
mkdir /opt/rocketmq/rocketmq-docker/stages/4.8.0
staged templates into folder /opt/rocketmq/rocketmq-docker/stages/4.8.0
进入目录
cd /opt/rocketmq/rocketmq-docker/stages/4.8.0/templates/
大概能看到以下内容
data
docker-compose
kubernetes
play-consumer.sh
play-docker-compose.sh
play-docker-compose.sh.bak
play-docker-dledger.sh
play-docker.sh
play-docker-tls.sh
play-kubernetes.sh
play-producer.sh
ssl
上述的sh文件分别各个部署方案的启动文件
修改配置文件
/opt/rocketmq/rocketmq-docker/stages/4.8.0/templates/docker-compose/data/broker/conf/broker.conf
/opt/rocketmq/rocketmq-docker/stages/4.8.0/templates/docker-compose/data1/broker/conf/broker.conf
分别增加主机ip配置:
#增加一行
brokerIP1 = 10.10.0.138
修改 docker-compose/docker-compose.yml,必须修改,不然会出现报错信息,报错信息如下:
rmqnamesrv | The Name Server boot success. serializeType=JSON
rmqbroker-b | java.io.FileNotFoundException: /root/rocketmq-4.8.0/conf/broker.conf (Permission denied)
rmqbroker-b | at java.io.FileInputStream.open0(Native Method)
rmqbroker-b | at java.io.FileInputStream.open(FileInputStream.java:195)
rmqbroker-b | at java.io.FileInputStream.<init>(FileInputStream.java:138)
rmqbroker-b | at java.io.FileInputStream.<init>(FileInputStream.java:93)
rmqbroker-b | at org.apache.rocketmq.broker.BrokerStartup.createBrokerController(BrokerStartup.java:128)
rmqbroker-b | at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:58)
rmqbroker | java.io.FileNotFoundException: /root/rocketmq-4.8.0/conf/broker.conf (Permission denied)
rmqbroker | at java.io.FileInputStream.open0(Native Method)
rmqbroker | at java.io.FileInputStream.open(FileInputStream.java:195)
rmqbroker | at java.io.FileInputStream.<init>(FileInputStream.java:138)
rmqbroker | at java.io.FileInputStream.<init>(FileInputStream.java:93)
rmqbroker | at org.apache.rocketmq.broker.BrokerStartup.createBrokerController(BrokerStartup.java:128)
rmqbroker | at org.apache.rocketmq.broker.BrokerStartup.main(BrokerStartup.java:58)
rmqbroker-b exited with code 255
rmqbroker exited with code 255
最终docker-compose.yml配置
version: '2'
services:
#Service for nameserver
namesrv:
image: apache/rocketmq:4.8.0-alpine
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- ./data/namesrv/logs:/root/rocketmq/logs
command: sh mqnamesrv
#Service for broker
broker:
image: apache/rocketmq:4.8.0-alpine
container_name: rmqbroker
links:
- namesrv
ports:
- 10909:10909
- 10911:10911
- 10912:10912
environment:
- NAMESRV_ADDR=namesrv:9876
privileged: true
volumes:
- ./data/broker/logs:/root/rocketmq/logs
- ./data/broker/store:/root/rocketmq/store
- ./data/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
command: sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
#Service for another broker -- broker1
broker1:
image: apache/rocketmq:4.8.0-alpine
container_name: rmqbroker-b
links:
- namesrv
ports:
- 10929:10909
- 10931:10911
- 10932:10912
environment:
- NAMESRV_ADDR=namesrv:9876
privileged: true
volumes:
- ./data1/broker/logs:/root/rocketmq/logs
- ./data1/broker/store:/root/rocketmq/store
- ./data1/broker/conf/broker.conf:/home/rocketmq/rocketmq-4.8.0/conf/broker.conf
command: sh mqbroker -c /home/rocketmq/rocketmq-4.8.0/conf/broker.conf
#console
mqconsole:
image: styletang/rocketmq-console-ng
container_name: mqconsole
ports:
- 19876:8080
environment:
JAVA_OPTS: -Drocketmq.namesrv.addr=namesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=falses
启动容器
./play-docker-compose.sh
提示
Creating rmqnamesrv ... done
Creating mqconsole ... done
Creating rmqbroker-b ... done
Creating rmqbroker ... done
docker ps查看容器启动情况
efb564be9b9b apache/rocketmq:4.8.0-alpine "sh mqbroker -c /hom…" 14 minutes ago Up 14 minutes
95eb8c8e594d apache/rocketmq:4.8.0-alpine "sh mqbroker -c /hom…" 14 minutes ago Up 14 minutes
f071a0b1d9b1 apache/rocketmq:4.8.0-alpine "sh mqnamesrv" 14 minutes ago Up 14 minutes
ed1d1c1deefd styletang/rocketmq-console-ng "sh -c 'java $JAVA_O…" 14 minutes ago Up 14 minutes
访问控制台
http://10.10.0.138:19876
服务访问地址
10.10.0.138:9876