消息中间件RocketMQ(二):使用Docker搭建二主二从集群

使用Docker安装RocketMQ

1.拉取镜像

docker pull foxiswho/rocketmq:server-4.3.2
docker pull foxiswho/rocketmq:broker-4.3.2

2.创建nameserver容器

docker create -p 9876:9876 --name rmqserver \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-e "JAVA_OPTS=-Duser.home=/opt" \
-v /data/rmq/rmqserver/logs:/opt/logs \
-v /data/rmq/rmqserver/store:/opt/store \
foxiswho/rocketmq:server-4.3.2

3.创建broker容器

docker create -p 10911:10911 -p 10909:10909 --name rmqbroker \
-e "JAVA_OPTS=-Duser.home=/opt" \
-e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
-v /data/rmq/rmqbroker/conf/broker.conf:/etc/rocketmq/broker.conf \
-v /data/rmq/rmqbroker/logs:/opt/logs \
-v /data/rmq/rmqbroker/store:/opt/store \
foxiswho/rocketmq:broker-4.3.2

4.配置broker文件

创建配置文件
mkdir -p /data/rmq/rmqbroker/conf
vi broker.conf
#增加
brokerIP1=192.168.56.129
namesrvAddr=192.168.56.129:9876
brokerName=my_broker

4.启动容器

docker start rmqserver rmqbroker

5.停止删除容器

docker stop rmqbroker rmqserver 
docker rm rmqbroker rmqserver

使用Docker搭建RocketMQ集群

创建2个nameserver

  • nameserver1
    docker create -p 9876:9876 --name rmqserver01 \
     -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
     -e "JAVA_OPTS=-Duser.home=/opt" \
     -v /data/rmq/rmqserver01/logs:/opt/logs \
     -v /data/rmq/rmqserver01/store:/opt/store \
     foxiswho/rocketmq:server-4.3.2
    
  • nameserver2
    docker create -p 9877:9876 --name rmqserver02 \ 
    -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \ 
    -e "JAVA_OPTS=-Duser.home=/opt" \ 
    -v /data/rmq/rmqserver02/logs:/opt/logs \ 
    -v /data/rmq/rmqserver02/store:/opt/store \
    foxiswho/rocketmq:server-4.3.2
    

创建第2个master broker

  • master broker01
    docker create --net host --name rmqbroker01 \
    -e "JAVA_OPTS=-Duser.home=/opt" \
    -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
    -v /data/rmq/rmqbroker01/conf/broker.conf:/etc/rocketmq/broker.conf \
    -v /data/rmq/rmqbroker01/logs:/opt/logs \
    -v /data/rmq/rmqbroker01/store:/opt/store \
    foxiswho/rocketmq:broker-4.3.2
    
  • master broker01 配置
    #创建配置文件
    mkdir -p /data/rmq/rmqbroker01/conf
    vi /data/rmq/rmqbroker01/conf/broker.conf
    
    namesrvAddr=192.168.56.129:9876;192.168.56.129:9877 
    brokerClusterName=myCluster 
    brokerName=broker01 
    brokerId=0 
    deleteWhen=04 
    fileReservedTime=48 
    brokerRole=SYNC_MASTER 
    flushDiskType=ASYNC_FLUSH 
    brokerIP1=192.168.56.129
    brokerIp2=192.168.56.129
    listenPort=10911
    
  • master broker02
    docker create --net host --name rmqbroker02 \
    -e "JAVA_OPTS=-Duser.home=/opt" \
    -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
    -v /data/rmq/rmqbroker02/conf/broker.conf:/etc/rocketmq/broker.conf \
    -v /data/rmq/rmqbroker02/logs:/opt/logs \
    -v /data/rmq/rmqbroker02/store:/opt/store \
    foxiswho/rocketmq:broker-4.3.2
    
  • master broker02 配置
    #创建配置文件
    mkdir -p /data/rmq/rmqbroker02/conf
    vi /data/rmq/rmqbroker02/conf/broker.conf
    
    namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
    brokerClusterName=myCluster
    brokerName=broker02 
    brokerId=0 
    deleteWhen=04 
    fileReservedTime=48 
    brokerRole=SYNC_MASTER 
    flushDiskType=ASYNC_FLUSH 
    brokerIP1=192.168.56.129 
    brokerIp2=192.168.56.129
    listenPort=10811
    

创建第2个slave broker

  • slave broker01
    docker create --net host --name rmqbroker03 \
    -e "JAVA_OPTS=-Duser.home=/opt" \
    -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
    -v /data/rmq/rmqbroker03/conf/broker.conf:/etc/rocketmq/broker.conf \
    -v /data/rmq/rmqbroker03/logs:/opt/logs \
    -v /data/rmq/rmqbroker03/store:/opt/store \
    foxiswho/rocketmq:broker-4.3.2
    
  • slave broker01 配置
    #创建配置文件
    mkdir -p /data/rmq/rmqbroker03/conf
    vi /data/rmq/rmqbroker03/conf/broker.conf
    
    namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
    brokerClusterName=myCluster
    brokerName=broker01
    brokerId=1
    deleteWhen=04 
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    brokerIP1=192.168.56.129
    brokerIp2=192.168.56.129
    listenPort=10711
    
  • slave broker02
    docker create --net host --name rmqbroker04 \
    -e "JAVA_OPTS=-Duser.home=/opt" \
    -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
    -v /data/rmq/rmqbroker04/conf/broker.conf:/etc/rocketmq/broker.conf \
    -v /data/rmq/rmqbroker04/logs:/opt/logs \
    -v /data/rmq/rmqbroker04/store:/opt/store \
    foxiswho/rocketmq:broker-4.3.2
    
  • slave broker02 配置
    #创建配置文件
    mkdir -p /data/rmq/rmqbroker04/conf
    vi /data/rmq/rmqbroker04/conf/broker.conf
    
    namesrvAddr=192.168.56.129:9876;192.168.56.129:9877
    brokerClusterName=myCluster
    brokerName=broker02
    brokerId=1
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    brokerIP1=192.168.56.129
    brokerIp2=192.168.56.129
    listenPort=10611
    

启动容器

docker start rmqserver01 rmqserver02 
docker start rmqbroker01 rmqbroker02 rmqbroker03 rmqbroker04
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值