zoukankan      html  css  js  c++  java
  • 通过docker部署rocketmq双主双从集群

    1. 环境准备

    阿某云:centos 7,47.77.*.*(172.21.*.*),在安全组策略开启8000-9000之间的端口访问权限。

    2. 创建目录

    mkdir /opt/rocketmq/logs/nameserver-1
    mkdir /opt/rocketmq/logs/nameserver-2
    mkdir /opt/rocketmq/logs/broker-master-1
    mkdir /opt/rocketmq/logs/broker-master-2
    mkdir /opt/rocketmq/logs/broker-slave-1
    mkdir /opt/rocketmq/logs/broker-slave-2
    mkdir /opt/rocketmq/store/nameserver-1
    mkdir /opt/rocketmq/store/nameserver-2
    mkdir /opt/rocketmq/store/broker-master-1
    mkdir /opt/rocketmq/store/broker-master-2
    mkdir /opt/rocketmq/store/broker-slave-1
    mkdir /opt/rocketmq/store/broker-slave-2
    mkdir /root/rocketmq/broker-master-1/conf
    mkdir /root/rocketmq/broker-master-2/conf
    mkdir /root/rocketmq/broker-slave-1/conf
    mkdir /root/rocketmq/broker-slave-2/conf

    3. 获取镜像

    nameserver

    docker pull foxiswho/rocketmq:server-4.3.2

    broker

    docker pull foxiswho/rocketmq:broker-4.3.2

    rocketmq-console

    docker pull styletang/rocketmq-console-ng

    4. 创建容器

    nameserver-1

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

    nameserver-2

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

    master-1

    docker create --net host --name rmq-master-1 -e "JAVA_OPTS=-Duser.home=/opt" -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" -v /root/rocketmq/broker-master-1/conf/broker.conf:/etc/rocketmq/broker.conf -v /opt/rocketmq/logs/broker-master-1:/opt/logs -v /opt/rocketmq/store/broker-master-1:/opt/store foxiswho/rocketmq:broker-4.3.2

    master-2

    docker create --net host --name rmq-master-2 -e "JAVA_OPTS=-Duser.home=/opt" -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" -v /root/rocketmq/broker-master-2/conf/broker.conf:/etc/rocketmq/broker.conf -v /opt/rocketmq/logs/broker-master-2:/opt/logs -v /opt/rocketmq/store/broker-master-2:/opt/store foxiswho/rocketmq:broker-4.3.2

    slave-1

    docker create --net host --name rmq-slave-1 -e "JAVA_OPTS=-Duser.home=/opt" -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" -v /root/rocketmq/broker-slave-1/conf/broker.conf:/etc/rocketmq/broker.conf -v /opt/rocketmq/logs/broker-slave-1:/opt/logs -v /opt/rocketmq/store/broker-slave-1:/opt/store foxiswho/rocketmq:broker-4.3.2

    slave-2

    docker create --net host --name rmq-slave-2 -e "JAVA_OPTS=-Duser.home=/opt" -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" -v /root/rocketmq/broker-slave-2/conf/broker.conf:/etc/rocketmq/broker.conf -v /opt/rocketmq/logs/broker-slave-2:/opt/logs -v /opt/rocketmq/store/broker-slave-2:/opt/store foxiswho/rocketmq:broker-4.3.2

    5. 创建配置文件

    /root/rocketmq/broker-master-1/conf/broker.conf
    namesrvAddr=172.21.*.*:8201;172.21.*.*:8202
    brokerClusterName=myCluster
    brokerName=broker01
    brokerId=0
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    brokerIP1=47.77.*.*
    brokerIp2=47.77.*.*
    listenPort=8111
    /root/rocketmq/broker-master-2/conf/broker.conf
    namesrvAddr=172.21.*.*:8201;172.21.*.*:8202
    brokerClusterName=myCluster
    brokerName=broker02
    brokerId=0
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SYNC_MASTER
    flushDiskType=ASYNC_FLUSH
    brokerIP1=47.77.*.*
    brokerIp2=47.77.*.*
    listenPort=8211
    /root/rocketmq/broker-slave-1/conf/broker.conf
    namesrvAddr=172.21.*.*:8201;172.21.*.*:8202
    brokerClusterName=myCluster
    brokerName=broker01
    brokerId=1
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    brokerIP1=47.77.*.*
    listenPort=8115
    /root/rocketmq/broker-slave-2/conf/broker.conf
    namesrvAddr=172.21.*.*:8201;172.21.*.*:8202
    brokerClusterName=myCluster
    brokerName=broker02
    brokerId=1
    deleteWhen=04
    fileReservedTime=48
    brokerRole=SLAVE
    flushDiskType=ASYNC_FLUSH
    brokerIP1=47.77.*.*
    listenPort=8215

    6. 启动容器

    先启动nameserver

    docker start rmq-nameserver-1 rmq-nameserver-2

    启动broker

    docker start rmq-master-1 rmq-master-2 rmq-slave-1 rmq-slave-2

    启动rocketmq-console

    docker run -dit --name rocketmq-console-ng -e "JAVA_OPTS=-Drocketmq.namesrv.addr=172.21.*.*:8201;172.21.*.*:8202 -Dcom.rocketmq.sendMessageWithVIPChannel=false" -p 8203:8080 styletang/rocketmq-console-ng

    启动完成后查看容器状态

    7. 端口说明

    broker会使用3个端口:

    listenPort:默认10911,监听端口,客户端通过这个端口连接broker,上面分别改成8111和8211

    haListenPort:ha端口,用于主从同步,在listenPort基础上加1,即10912

    vipChannelPort:vip通道端口,在listenPort基础上减2,即10909

    如果启动时出现端口冲突,但是配置文件里面是不同的listenPort,很有可能就是后面2个端口冲突了。

    8. 通过rocketmq-console访问集群

    http://47.77.*.*:8203/#/cluster

  • 相关阅读:
    用jQuery写的一个简单的弹出窗口(IE7\IE8\FF3)
    live write test
    sql2
    查询所有表索引
    java初学问题记录(2012.02.092012.02.16)
    SQL
    centso7网卡bond
    vmware模板
    Dockerfile参考
    Docker简单介绍
  • 原文地址:https://www.cnblogs.com/zhou-920644981/p/14569126.html
Copyright © 2011-2022 走看看