docker 安装RocketMQ集群(主从,同一服务器)
一、安装
1. 选择镜像
(1)镜像搜索:docker search rocketmq
也可以访问网址:https://hub.docker.com/r/apache/rocketmq/tags
(2)下拉镜像:docker pull apache/rocketmq:4.9.0
(3)同样,拉取管理界面镜像:docker pull apacherocketmq/rocketmq-dashboard:latest
2. dokcer启动RocketMQ
2.1 启动name-server
准备容器要映射的目录以及放开目录权限
mkdir -p ./{logs,store}
chmod 777 -R namesrv
启动name-server
启动命令:
docker run -d --name rmqnamesrv --net=host -v /home/rocketmq/namesrv/logs:/home/rocketmq/logs -e "JAVA_OPT_EXT=-server -Xms512m -Xmx512m -Xmn128m" apache/rocketmq:4.9.0 sh mqnamesrv
2.2 启动broker
准备容器要映射的目录以及开放权限
mkdir -p ./{logs-a,store-a}
mkdir -p ./{logs-a-s,store-a-s}chmod 777 -R rocketmq
broker-a(主节点)
brokerClusterName=rocketmq_cluster
brokerName=broker-a
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH
namesrvAddr=10.200.XX.XX:9876;
brokerIP1=10.200.xx.xx
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10911
启动命令:
docker run -d --name rmqbroker-a --net=host -v /home/rocketmq/broker/logs-a:/home/rocketmq/logs -v /home/rocketmq/broker/store-a:/home/rocketmq/store -v /home/rocketmq/conf/broker-a.conf:/home/rocketmq/conf/broker.conf -e "JAVA_OPT_EXT=-server -Xms1g -Xmx1g -Xmn384m" apache/rocketmq:4.9.0 sh mqbroker -c /home/rocketmq/conf/broker.conf
broker-a-s(从节点)
brokerClusterName=rocketmq_cluster
brokerName=broker-a-s
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=SYNC_FLUSH
namesrvAddr=10.200.XX.XX:9876;
brokerIP1=10.200.xx.xx
defaultTopicQueueNums=4
autoCreateTopicEnable=true
autoCreateSubscriptionGroup=true
listenPort=10921
启动命令:
docker run -d --name rmqbroker-a-s --net=host -v /home/rocketmq/broker/logs-a-s:/home/rocketmq/logs -v /home/rocketmq/broker/store-a-s:/home/rocketmq/store -v /home/rocketmq/conf/broker-a-s.conf:/home/rocketmq/conf/broker.conf -e "JAVA_OPT_EXT=-server -Xms1g -Xmx1g -Xmn384m" apache/rocketmq:4.9.0 sh mqbroker -c /home/rocketmq/conf/broker.conf
2.3 启动Mq管理界面
二、Stream Cloud Stream RocketMq
三、常见问题处理
①:org.apache.rocketmq.remoting.execption.RemotingConnectException:connect to <null> failed。
启动rmqconsole时,修改命令JAVA_OPTS=-Drocketmq.namesrv.addr=namesrv:9876 -> JAVA_OPTS=-Drocketmq.namesrv.addr=10.200.xx.xx:9876 (即具体ip)
②:rg.apache.rocketmq.client.exception.MQBrokerException: CODE: 1 DESC: the producer group[] not exist For more information, please visit the url, http://rocketmq.apache.org/docs/faq/
在Producer页面搜索的时候,选择完topic后,需要输入ProducerGroup(注意要完整的producerName)才能搜到且不报错。
③:springboot项目连接rocketmq时,日志一直打印:closeChannel: close the connection to remote address[] result: true,
因为brokerip为内网ip,在broker.conf配置中加上
# broker ip
brokerIP1 = 10.200.xx.xx
broker启动日志变化:
The broker[broker-a, 172.17.0.8:10911] boot success. serializeType=JSON and name server is 10.200.xx.xx:9876
The broker[broker-a, 10.200.xx.xx:10911] boot success. serializeType=JSON and name server is 10.200.xx.xx:9876
四、可能会用到的linux命令
1. 检测端口是否开放 lsof -i
2. 进入容器 docker exec -it --user root rmqbroker-a-s /bin/bash
3. 查看镜像、容器占用磁盘大小:docker system df [-v]
4. 查看容器运行所占内存大小:docker stats
5. 查看目录大小:
du -ah --max-depth=1
du -sh : 查看当前目录总共占的容量。而不单独列出各子项占用的容量
du -lh --max-depth=1 : 查看当前目录下一级子文件和子目录占用的磁盘容量。
6. 根据域名查找IP (windows)
cmd 输入nslookup