docker安装rocketmq
拉取rocketmq镜像
docker pull apache/rocketmq:4.9.4
创建文件夹
mkdir -p /home/lihaiyang/docker/rocketmq/broker/logs
mkdir -p /home/lihaiyang/docker/rocketmq/broker/store
mkdir -p /home/lihaiyang/docker/rocketmq/broker/conf
mkdir -p /home/lihaiyang/docker/rocketmq/nameserver/logs
mkdir -p /home/lihaiyang/docker/rocketmq/nameserver/store
运行rmqnamesrv
docker run -d --restart=always \
--privileged=true \
--name rmqnamesrv \
-p 9876:9876 \
-v /home/lihaiyang/docker/rocketmq/nameserver/logs:/home/rocketmq/logs \
-v /home/lihaiyang/docker/rocketmq/nameserver/store:/root/store \
-e "MAX_HEAP_SIZE=256M" \
-e "HEAP_NEWSIZE=128M" \
-e "MAX_POSSIBLE_HEAP=100000000" \
apache/rocketmq:4.9.4 sh mqnamesrv
编辑配置文件 /home/lihaiyang/docker/rocketmq/broker/conf/broker.conf
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker1
#0表示Master,大于0表示不同的slave
brokerId = 0
#表示几点做消息删除动作,默认是凌晨4点
deleteWhen = 04
#在磁盘上保留消息的时长,单位是小时
fileReservedTime = 48
#有三个值:SYNC_MASTER,ASYNC_MASTER,SLAVE;同步和异步表示Master和Slave之间同步数据的机制;
brokerRole = ASYNC_MASTER
#刷盘策略,取值为:ASYNC_FLUSH,SYNC_FLUSH表示同步刷盘和异步刷盘;SYNC_FLUSH消息写入磁盘后才返回成功状态,ASYNC_FLUSH不需要;
flushDiskType = ASYNC_FLUSH
# 设置broker节点所在服务器的ip地址(**这个非常重要,主从模式下,从节点会根据主节点的brokerIP2来同步数据,如果不配置,主从无法同步,brokerIP1设置为自己外网能访问的ip,服务器双网卡情况下必须配置,比如阿里云这种,主节点需要配置ip1和ip2,从节点只需要配置ip1即可)
# 此ip由使用环境决定 本机使用 127 局域网使用 192 外网使用 外网ip
brokerIP1 = 192.168.209.102
#nameServer地址,分号分割
namesrvAddr = 192.168.209.102:9876
#Broker 对外服务的监听端口,
listenPort = 10911
#是否允许Broker自动创建Topic
autoCreateTopicEnable = true
#是否允许 Broker 自动创建订阅组
autoCreateSubscriptionGroup = true
#linux开启epoll
useEpollNativeSelector = true
Note:namesrvAddr和brokerIP1必须是具体的IP地址
运行rmqbroker
docker run -d --restart=always \
--name rmqbroker \
--link rmqnamesrv:namesrv \
-p 10911:10911 -p 10909:10909 \
--privileged=true \
-v /home/lihaiyang/docker/rocketmq/broker/logs:/root/logs \
-v /home/lihaiyang/docker/rocketmq/broker/store:/root/store \
-v /home/lihaiyang/docker/rocketmq/broker/conf/broker.conf:/home/rocketmq/broker.conf \
-e "MAX_POSSIBLE_HEAP=200000000" \
-e "MAX_HEAP_SIZE=512M" \
-e "HEAP_NEWSIZE=256M" \
-e "NAMESRV_ADDR=namesrv:9876" \
apache/rocketmq:4.9.4 \
sh mqbroker -c /home/rocketmq/broker.conf
拉取rocketmq-dashboard镜像
docker pull apacherocketmq/rocketmq-dashboard:1.0.0
运行rocketmq-dashboard
docker run -d --restart=always --name rocketmq-dashboard \
-e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.209.102:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" \
-p 9999:8080 apacherocketmq/rocketmq-dashboard:1.0.0