Docker部署RocketMQ
1、安装 Namesrv注册中心拉取镜像docker pull rocketmqinc/rocketmq:4.4.0启动容器docker run -d -p 9876:9876 -v {RmHome}/data/namesrv/logs:/root/logs -v {RmHome}/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_P
1、安装 Namesrv注册中心
拉取镜像
docker pull rocketmqinc/rocketmq:4.4.0
启动容器
docker run -d -p 9876:9876 -v {RmHome}/data/namesrv/logs:/root/logs -v {RmHome}/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq:4.4.0 sh mqnamesrv
{RmHome} 要替换成你的宿主机想保存 MQ 的日志与数据的地方,通过 docker 的 -v 参数使用 volume 功能,把你本地的目录映射到容器内的目录上。否则所有数据都默认保存在容器运行时的内存中,重启之后就又回到最初的起点。
例如
docker run -d -p 9876:9876 -v /root/rocketmq/data/namesrv/logs:/root/logs -v /root/rocketmq/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" 172.16.10.126/library/rocketmq:4.4 sh mqnamesrv
注意: 此处一定要写类似/root/rocketmq
的绝对路径否则会报错
2、安装 broker 服务器
拉取镜像
步骤1中已拉取则无需再次拉取
创建 broker.conf 文件
- 在 {RmHome}/conf 目录下创建 broker.conf 文件
- 在 broker.conf 中写入如下内容
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = {本地外网 IP}
IP写的时候去掉{}
启动容器
docker run -d -p 10911:10911 -p 10909:10909 -v {RmHome}/data/broker/logs:/root/logs -v {RmHome}/rocketmq/data/broker/store:/root/store -v {RmHome}/conf/broker.conf:/opt/rocketmq-4.4.0/conf/broker.conf --name rmqbroker --link rmqnamesrv:namesrv -e "NAMESRV_ADDR=namesrv:9876" -e "MAX_POSSIBLE_HEAP=200000000" rocketmqinc/rocketmq:4.4.0 sh mqbroker -c /opt/rocketmq-4.4.0/conf/broker.conf
{RmHome} 同上步一样,不再缀述。broker.conf 的文件中的 brokerIP1 是你的 broker 注册到 Namesrv 中的 ip。如果不指定他会默认取容器中的内网 IP。除非你的应用也同时部署在网络相通的容器中,本地或容器外就无法连接 broker 服务了,进而导致类似 RemotingTooMuchRequestException 等各种异常。
3、安装 rocketmq 控制台
拉取镜像
docker pull pangliang/rocketmq-console-ng
启动容器
docker run -e "JAVA_OPTS=-Drocketmq.namesrv.addr={本地外网 IP}:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 -t pangliang/rocketmq-console-ng
进入web控制台
http://IP:8080
-----------------------------------分割线----------------------------------------
上述部署运行出现了控制台无法读取到数据的情况,所以换了一种部署方法
首先拉取镜像
docker pull rocketmqinc/rocketmq:4.4.0
接着创建 mq 配置文件broker.conf
,文件放置到/root/rocketmq/conf
配置如下
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = {本地外网 IP}
IP写的时候去掉{}
再创建如下文件夹/root/rocketmq/logs
,/root/rocketmq/store
最后创建docker-compose.yml文件配置如下:
version: '2'
services:
namesrv:
image: rocketmqinc/rocketmq
container_name: rmqnamesrv
ports:
- 9876:9876
volumes:
- /root/rocketmq/logs:/home/rocketmq/logs
- /root/rocketmq/store:/home/rocketmq/store
command: sh mqnamesrv
broker:
image: rocketmqinc/rocketmq
container_name: rmqbroker
ports:
- 10909:10909
- 10911:10911
- 10912:10912
volumes:
- /root/rocketmq/logs:/home/rocketmq/logs
- /root/rocketmq/store:/home/rocketmq/store
- /root/rocketmq/conf/broker.conf:/root/rocketmq/conf/broker.conf
#command: sh mqbroker -n namesrv:9876
command: sh mqbroker -n namesrv:9876 -c ../conf/broker.conf
depends_on:
- namesrv
environment:
- JAVA_HOME=/usr/lib/jvm/jre
console:
image: styletang/rocketmq-console-ng
container_name: rocketmq-console-ng
ports:
- 8087:8080
depends_on:
- namesrv
environment:
- JAVA_OPTS= -Dlogging.level.root=info -Drocketmq.namesrv.addr=rmqnamesrv:9876
- Dcom.rocketmq.sendMessageWithVIPChannel=false
访问地址:
http://IP:8087
更多推荐
所有评论(0)