RocketMQ本地Docker测试
参考文档
- https://bbs.huaweicloud.com/blogs/255821
- https://blog.csdn.net/ming19951224/article/details/109063041
- https://blog.csdn.net/qq_41489540/article/details/116401284
版本信息
- 镜像: apache/rocketmq:4.9.2
- Console: styletang/rocketmq-console-ng
安装&启动
1.拉取镜像
docker pull apache/rocketmq:4.9.2
2. 配置网络
- 使用bridge模式(推荐)。网段可自行更改。
docker network create --subnet=172.18.0.0/16 rmqnetwork
- 使用host模式,那么下面使用的RocketMQ name server、broker均为127.0.0.1
- –network=host
3. 启动nameserver
# 使用bridge模式网络
docker run -d --net rmqnetwork --ip 172.18.0.2 -p 9876:9876 -v /tmp/rocketmq/data/namesrv/logs:/root/logs -v /tmp/rocketmq/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" apache/rocketmq:4.9.2 sh mqnamesrv
# 使用host模式网络
docker run -d --network=host -v /tmp/rocketmq/data/namesrv/logs:/root/logs -v /tmp/rocketmq/data/namesrv/store:/root/store --name rmqnamesrv -e "MAX_POSSIBLE_HEAP=100000000" apache/rocketmq:4.9.2 sh mqnamesrv
docker start rmqnamesrv
4. 启动broker
- 编辑broker conf
cd /tmp/rocketmq/conf
touch broker.conf
vi broker.conf
brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId = 0
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
brokerIP1 = 172.18.0.3 # bridge模式使用这个
brokerIP1 = 127.0.0.1 # host模式使用这个
- 启动broker
# 使用bridge模式网络
docker run -d --net rmqnetwork --ip 172.18.0.3 -p 10911:10911 -p 10909:10909 -v /tmp/rocketmq/data/broker/logs:/root/logs -v /tmp/rocketmq/data/broker/store:/root/store -v /tmp/rocketmq/conf/broker.conf:/opt/rocketmq/conf/broker.conf --name rmqbroker -e "NAMESRV_ADDR=172.18.0.2:9876" -e "MAX_POSSIBLE_HEAP=200000000" apache/rocketmq:4.9.2 sh mqbroker -c /opt/rocketmq/conf/broker.conf
# 使用host模式网络
docker run -d --network=host -v /tmp/rocketmq/data/broker/logs:/root/logs -v /tmp/rocketmq/data/broker/store:/root/store -v /tmp/rocketmq/conf/broker.conf:/opt/rocketmq/conf/broker.conf --name rmqbroker -e "NAMESRV_ADDR=127.0.0.1:9876" -e "MAX_POSSIBLE_HEAP=200000000" apache/rocketmq:4.9.2 sh mqbroker -c /opt/rocketmq/conf/broker.conf
docker start rmqbroker
5. 启动RocketMQ console
- 拉取镜像
docker pull styletang/rocketmq-console-ng
- 启动console
# 使用bridge模式网络
docker run -d --net rmqnetwork --name rmqconsole -p 9800:8080 -e "JAVA_OPTS=-Drocketmq.namesrv.addr=172.18.0.2:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -t styletang/rocketmq-console-ng
# 使用host模式网络
docker run -d --name rmqconsole -p 9800:8080 -e "JAVA_OPTS=-Drocketmq.namesrv.addr=127.0.0.1:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -t styletang/rocketmq-console-ng
- 访问console
- http://localhost:9800/#/
其他问题
1. 本地访问Bridge模式下的RocketMQ
bridge模式下将name server和broker的端口和本机端口做了映射,所以可以通过localhost来访问对应的name server和broker。
- 例如,name server address可以使用: localhost:9876
若本地连接broker时使用了172.18.0.3地址,可以将这个broker ip映射到localhost对应的网卡:
# lo0为127.0.0.1所在网卡
sudo ifconfig lo0 alias 172.18.0.3