RocketMQ环境搭建 ( docker )
南江烂柯人 JAVA劝退师

安装前先要安装好docker以及docker-compose

常用资料地址

配置解析

创建数据挂载目录

mkdir -p /home/rocketmq/{broker/conf,broker/logs,broker/store,console/logs,namesrv/logs}

broker.conf

目录:/home/rocketmq/broker/conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# 是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭
autoCreateTopicEnable=true

# 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
autoCreateSubscriptionGroup=true

# Broker角色
# - ASYNC_MASTER 异步复制Master
# - SYNC_MASTER 同步双写Master
# - SLAVE
brokerRole=ASYNC_MASTER

# 所属集群名字
brokerClusterName = DefaultCluster

# broker 名字,注意此处不同的配置文件填写的不一样,如果在 broker-a.properties 使用: broker-a,
# 在 broker-b.properties 使用: broker-b
brokerName = broker-a

# 0 表示 Master,> 0 表示 Slave
brokerId = 0

# 启动 IP,修改为你宿主机的 IP
# 如果是正式环境,这里一定要填写内网地址(安全)
# 如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网
#brokerIP1 = 192.168.199.10

# 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
defaultTopicQueueNums=4

# 删除文件时间点,默认凌晨4点
deleteWhen=04

# 文件保留时间,默认48小时
fileReservedTime = 120

# 刷盘方式
# - ASYNC_FLUSH 异步刷盘
# - SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

# Broker 对外服务的监听端口
listenPort=10911

# 检测物理文件磁盘空间
diskMaxUsedSpaceRatio=88

# commitLog 每个文件的大小默认 1G,单位 b
mapedFileSizeCommitLog=1073741824

# ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整
mapedFileSizeConsumeQueue=300000

# 限制的消息大小,单位 b
maxMessageSize=524288

# nameServer地址,分号分割
# namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876

# 存储路径
# storePathRootDir=/home/ztztdata/rocketmq-all-4.1.0-incubating/store
# commitLog 存储路径
# storePathCommitLog=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/commitlog
# 消费队列存储
# storePathConsumeQueue=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/consumequeue
# 消息索引存储路径
# storePathIndex=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/index
# checkpoint 文件存储路径
# storeCheckpoint=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/checkpoint
# abort 文件存储路径
# abortFile=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/abort
# 发消息线程池数量
# sendMessageThreadPoolNums=128
# 拉消息线程池数量
# pullMessageThreadPoolNums=128

# 未标注
# destroyMapedFileIntervalForcibly=120000
# redeleteHangedFileInterval=120000

设置管理界面账号密码 /home/rocketmq/console/data/users.properties

1
2
3
4
5
6
7
8
9
10
11
12
13
# This file supports hot change, any change will be auto-reloaded without Console restarting.
# Format: a user per line, username=password[,N] #N is optional, 0 (Normal User); 1 (Admin)

# Define Admin
# =============用户名和密码规则「用户名=密码,权限」,这里的权限为1表示管理员,为0表示普通用户=============
# 例如:admin=admin123,1
admin=123456,1


# Define Users
# =============屏蔽下边两个账户=============
#user1=user1
#user2=user2

docker-compose

rocketmq.config.loginRequired:开启控制台访问密码

rocketmq.config.aclEnabled: broker acl开启

rocketmq.config.accessKey: broker acl账号

rocketmq.config.secretKey: broker acl密码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
version: '3.5'
services:
rmqnamesrv:
image: apache/rocketmq:5.1.0
container_name: rmqnamesrv
restart: always
ports:
- 9876:9876
environment:
# 内存分配
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms1g -Xmx1g"
volumes:
- /data/rocketmq/namesrv/logs:/home/rocketmq/logs
command: [ "sh", "mqnamesrv" ]
networks:
rmq:
aliases:
- rmqnamesrv

rmqbroker:
image: apache/rocketmq:5.1.0
container_name: rmqbroker
restart: always
depends_on:
- rmqnamesrv
ports:
- 10909:10909
- 10911:10911
volumes:
- /data/rocketmq/broker/logs:/root/logs
- /data/rocketmq/broker/store:/root/store
- /data/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf
command: [ "sh", "mqbroker", "-c", "/home/rocketmq/broker.conf" ]
environment:
NAMESRV_ADDR: "rmqnamesrv:9876"
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms1g -Xmx1g -Xmn1g"
networks:
rmq:
aliases:
- rmqbroker

rmqdashboard:
image: apacherocketmq/rocketmq-dashboard:latest
container_name: rmqdashboard
restart: always
ports:
- 18080:8080
depends_on:
- rmqnamesrv
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/rocketmq/console/data:/tmp/rocketmq-console/data
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876;rmqnamesrv1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.loginRequired=true"
networks:
rmq:
aliases:
- rmqdashboard

networks:
rmq:
name: rmq
driver: bridge

集群docker-compose.yml参考

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
version: '3.5'
services:
rmqnamesrv:
image: apache/rocketmq:5.1.4
container_name: rmqnamesrv
restart: always
ports:
- 9876:9876
environment:
# 内存分配
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms128m -Xmx128m"
volumes:
- /home/rocketmq/namesrv/logs:/home/rocketmq/logs
command: [ "sh", "mqnamesrv" ]
networks:
rmq:
aliases:
- rmqnamesrv

rmqnamesrv1:
image: apache/rocketmq:5.1.4
container_name: rmqnamesrv1
restart: always
ports:
- 9886:9876
environment:
# 内存分配
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms128m -Xmx128m"
volumes:
- /home/rocketmq/namesrv1/logs:/home/rocketmq/logs
command: [ "sh", "mqnamesrv" ]
networks:
rmq:
aliases:
- rmqnamesrv1

rmqbroker:
image: apache/rocketmq:5.1.4
container_name: rmqbroker
restart: always
ports:
- 10909:10909
- 10911:10911
volumes:
- /home/rocketmq/broker/logs:/home/rocketmq/logs
- /home/rocketmq/broker/store:/home/rocketmq/store
- /home/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf
command: [ "sh", "mqbroker", "-c", "/home/rocketmq/broker.conf" ]
environment:
NAMESRV_ADDR: "rmqnamesrv:9876;rmqnamesrv1:9876"
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms128m -Xmx128m -Xmn128m"
depends_on:
- rmqnamesrv
- rmqnamesrv1
networks:
rmq:
aliases:
- rmqbroker

rmqbroker1:
image: apache/rocketmq:5.1.4
container_name: rmqbroker1
restart: always
ports:
- 10919:10909
- 10921:10911
volumes:
- /home/rocketmq/broker1/logs:/home/rocketmq/logs
- /home/rocketmq/broker1/store:/home/rocketmq/store
- /home/rocketmq/broker1/conf/broker.conf:/home/rocketmq/broker.conf
command: [ "sh", "mqbroker", "-c", "/home/rocketmq/broker.conf" ]
environment:
NAMESRV_ADDR: "rmqnamesrv:9876;rmqnamesrv1:9876"
JAVA_OPT_EXT: "-Duser.home=/home/rocketmq -server -Xms128m -Xmx128m -Xmn128m"
depends_on:
- rmqnamesrv
- rmqnamesrv1
networks:
rmq:
aliases:
- rmqbroker1
# 开启监控,并设置登录密码
rmqdashboard:
image: apacherocketmq/rocketmq-dashboard:latest
container_name: rmqdashboard
restart: always
ports:
- 18080:8080
volumes:
- /etc/localtime:/etc/localtime:ro
- /home/rocketmq/console/data:/tmp/rocketmq-console/data
environment:
JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876;rmqnamesrv1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false -Drocketmq.config.loginRequired=true"
depends_on:
- rmqnamesrv
- rmqnamesrv1
networks:
rmq:
aliases:
- rmqdashboard

networks:
rmq:
name: rmq
driver: bridge

常见问题:

  • 本文标题:RocketMQ环境搭建 ( docker )
  • 本文作者:南江烂柯人
  • 创建时间:2023-06-27 16:29:29
  • 本文链接:https://www.mattjia.com/2023/06/27/RocketMQ单机环境搭建 ( docker )/
  • 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
 评论