单机搭建
1 拉取rocketMq镜像
docker pull rocketmqinc/rocketmq:4.3.2
2 创建挂在目录
mkdir -p /mydata/rocketmq/data/namesrv/logs /mydata/rocketmq/data/namesrv/store
mkdir -p /mydata/rocketmq/data/broker/logs /mydata/rocketmq/data/broker/store
mkdir -p /mydata/rocketmq/data/conf
3 配置broker配置文件
cd /mydata/rocketmq/data/conf
vi broker.conf
输入一下内容:
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#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
#namesrv地址
namesrvAddr=192.168.56.102:9876
# 设置broker节点所在服务器的ip地址,也就是centosOS7的服务ip
brokerIP1 = 192.168.56.102
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95
4 启动nameserver服务
docker run -d --name rocketmq_nameserver -p 9876:9876 -v /mydata/rocketmq/data/namesrv/logs:/root/logs -v /mydata/rocketmq/data/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq:4.3.2 sh mqnamesrv
sh mqnamesrv ---启动nameserver服务
5 启动broker服务
docker run -d --name rmqbroker-m -p 10911:10911 -p 10909:10909 -v /mydata/rocketmq/data/broker/logs:/root/logs -v /mydata/rocketmq/data/broker/store:/root/store -v /mydata/rocketmq/data/conf/broker.conf:/opt/rocketmq-4.3.2/conf/broker.conf rocketmqinc/rocketmq:4.3.2 sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf
6 拉取rocketmq-console镜像
docker pull styletang/rocketmq-console-ng:1.0.0
- -link rocketmq_nameserver:namesrv 和rocketmq_nameserver容器通信(跟nameserv容器名称对应)
-e “NAMESRV_ADDR=namesrv:9876” 指定namesrv的地址为本机namesrv的ip地址:9876
sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf 指定配置文件启动broker节点
7 启动rocketmq-console服务
docker run -d --name rocketmq_console -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.56.102:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 styletang/rocketmq-console-ng:1.0.0
集群搭建
1 准备2台服务器:
192.168.56.102,192.168.56.103
2 102上操作
a 拉取rocketMq镜像
docker pull rocketmqinc/rocketmq:4.3.2
b 创建挂在目录
mkdir -p /mydata/rocketmq/data/namesrv/logs /mydata/rocketmq/data/namesrv/store
mkdir -p /mydata/rocketmq/data/broker/logs /mydata/rocketmq/data/broker/store
mkdir -p /mydata/rocketmq/data/conf
c 配置broker配置文件
cd /mydata/rocketmq/data/conf
vi broker.conf
输入一下内容:
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-a
#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
#namesrv地址
namesrvAddr=192.168.56.102:9876
# 设置broker节点所在服务器的ip地址,也就是centosOS7的服务ip
brokerIP1 = 192.168.56.102
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95
d 启动nameserver服务
docker run -d --name rocketmq_nameserver -p 9876:9876 -v /mydata/rocketmq/data/namesrv/logs:/root/logs -v /mydata/rocketmq/data/namesrv/store:/root/store -e "MAX_POSSIBLE_HEAP=100000000" rocketmqinc/rocketmq:4.3.2 sh mqnamesrv
e 启动broker服务
docker run -d --name rmqbroker-s -p 10911:10911 -p 10909:10909 -v /mydata/rocketmq/data/broker/logs:/root/logs -v /mydata/rocketmq/data/broker/store:/root/store -v /mydata/rocketmq/data/conf/broker.conf:/opt/rocketmq-4.3.2/conf/broker.conf rocketmqinc/rocketmq:4.3.2 sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf
f 拉取rocketmq-console镜像
docker pull styletang/rocketmq-console-ng:1.0.0
- -link rocketmq_nameserver:namesrv 和rocketmq_nameserver容器通信(跟nameserv容器名称对应)
-e “NAMESRV_ADDR=namesrv:9876” 指定namesrv的地址为本机namesrv的ip地址:9876
sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf 指定配置文件启动broker节点
g 启动rocketmq-console服务
docker run -d --name rocketmq_console -e "JAVA_OPTS=-Drocketmq.namesrv.addr=192.168.56.102:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8080:8080 styletang/rocketmq-console-ng:1.0.0
3 103 上操作
a 拉取rocketMq镜像
docker pull rocketmqinc/rocketmq:4.3.2
b 创建挂在目录
mkdir -p /mydata/rocketmq/data/broker/logs /mydata/rocketmq/data/broker/store
mkdir -p /mydata/rocketmq/data/conf
c 配置broker配置文件
cd /mydata/rocketmq/data/conf
vi broker.conf
输入一下内容:
# 所属集群名称,如果节点较多可以配置多个
brokerClusterName = DefaultCluster
#broker名称,master和slave使用相同的名称,表明他们的主从关系
brokerName = broker-b
#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
#namesrv地址
namesrvAddr=192.168.56.102:9876
# 设置broker节点所在服务器的ip地址,也就是centosOS7的服务ip
brokerIP1 = 192.168.56.103
# 磁盘使用达到95%之后,生产者再写入消息会报错 CODE: 14 DESC: service not available now, maybe disk full
diskMaxUsedSpaceRatio=95
d 启动broker服务
docker run -d --name rmqbroker-s -p 10911:10911 -p 10909:10909 -v /mydata/rocketmq/data/broker/logs:/root/logs -v /mydata/rocketmq/data/broker/store:/root/store -v /mydata/rocketmq/data/conf/broker.conf:/opt/rocketmq-4.3.2/conf/broker.conf rocketmqinc/rocketmq:4.3.2 sh mqbroker -c /opt/rocketmq-4.3.2/conf/broker.conf
4 此时登录控制界面查看:
http://192.168.56.102:8080