1、新建所需的挂载目录:
mkdir -p /mydata/config/rocketmq mkdir -p /mydata/rocketmq/broker-logs mkdir -p /mydata/rocketmq/broker-store mkdir -p /mydata/rocketmq/logs mkdir -p /mydata/rocketmq/store
2、提前pull好相关的镜像:
docker pull foxiswho/rocketmq:server-4.5.2 docker pull foxiswho/rocketmq:broker-4.5.2 docker pull styletang/rocketmq-console-ng
3、编写核心配置文件:
cd /mydata/config/rocketmq/ vim broker.conf
内容如下:
brokerClusterName = DefaultCluster brokerName = broker-a brokerId = 0 deleteWhen = 04 fileReservedTime = 48 brokerRole = ASYNC_MASTER flushDiskType = ASYNC_FLUSH autoCreateTopicEnable = true # 如果是本地程序调用云主机 mq,这个需要设置成 云主机 IP brokerIP1=<主机IP> namesrvAddr=<主机IP>:9876
4、编写docker-compose.yml文件:
cd /mydata/rocketmq vim docker-compose.yaml
内容如下:
version: '3.5' services: rmqnamesrv: image: foxiswho/rocketmq:server-4.5.2 container_name: rmqnamesrv restart: always ports: - 9876:9876 volumes: - /mydata/rocketmq/logs:/opt/logs - /mydata/rocketmq/store:/opt/store networks: rmq: aliases: - rmqnamesrv rmqbroker: image: foxiswho/rocketmq:broker-4.5.2 container_name: rmqbroker restart: always ports: - 10909:10909 - 10911:10911 volumes: - /mydata/rocketmq/broker-logs:/root/logs/rocketmqlogs - /mydata/rocketmq/broker-store:/opt/store - /mydata/config/rocketmq/broker.conf:/etc/rocketmq/broker.conf environment: NAMESRV_ADDR: "rmqnamesrv:9876" JAVA_OPTS: " -Duser.home=/opt" JAVA_OPT_EXT: "-server -Xmx256m -Xms256m -Xmn128m" command: mqbroker -c /etc/rocketmq/broker.conf depends_on: - rmqnamesrv networks: rmq: aliases: - rmqbroker rmqconsole: image: styletang/rocketmq-console-ng container_name: rmqconsole restart: always ports: - 8087:8080 environment: JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" depends_on: - rmqnamesrv networks: rmq: aliases: - rmqconsole networks: rmq: name: rmq driver: bridge
5、启动RocketMQ:
docker-compose up -d
6、访问rocketmq-console:
http://192.168.56.34:8087/