Docker安装、配置RocketMQ

发布于:2025-04-06 ⋅ 阅读:(12) ⋅ 点赞:(0)

1.创建必要的目录和配置文件

# 创建配置目录
mkdir -p ${HOME}/docker/software/rocketmq/conf

# 创建 broker.conf 配置文件
cat > ${HOME}/docker/software/rocketmq/conf/broker.conf << 'EOF'
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 替换为您的服务器IP
brokerIP1 = 你的服务器IP
EOF

2.如果没有docker-compose.yml文件的话,先创建docker-compose.yml

配置文件一般长这个样子

version: '3'

services:
  namesrv:
    image: foxiswho/rocketmq:server-4.5.1
    container_name: rmqnamesrv
    ports:
      - "9876:9876"
    restart: always

  broker:
    image: foxiswho/rocketmq:broker-4.5.1
    container_name: rmqbroker
    ports:
      - "10911:10911"
      - "10909:10909"
    volumes:
      - ${HOME}/docker/software/rocketmq/conf/broker.conf:/etc/rocketmq/broker.conf
    environment:
      - NAMESRV_ADDR=namesrv:9876
      - JAVA_OPTS=-Duser.home=/opt
      - JAVA_OPT_EXT=-server -Xms512m -Xmx512m
    depends_on:
      - namesrv
    restart: always

  console:
    image: pangliang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - "8088:8080"
    environment:
      - JAVA_OPTS=-Drocketmq.config.namesrvAddr=namesrv:9876 -Drocketmq.config.isVIPChannel=false
    depends_on:
      - namesrv
    restart: always

 3.启动服务

# 启动所有服务
docker compose up -d

# 查看服务状态
docker ps

# 查看日志
docker logs rmqnamesrv
docker logs rmqbroker
docker logs rmqconsole

4.访问控制台

浏览器访问:http://你的服务器IP:8088

注意:

  • 确保防火墙开放了相应端口