RocketMQ (2) --- Docker cluster deployment RocketMQ

RocketMQ (2) -Docker cluster deployment RocketMQ

=前言=

1、因为自己只买了一台阿里云服务器,所以RocketMQ集群都部署在单台服务器上只是端口不同,如果实际开发,可以分别部署在多台服务器上。
2、这里有关 Broker 和 NameServer 分别都做了了集群部署(各部署两个),且BroKer是按两主进行部署。

Docker was selected to deploy mainly consider:通过Docker部署RocketMQ集群更快速,而且对系统的资源利用更好!

Liunx written before on how to deploy Docker's blog: [Docker] (3) --- linux deployment Docker, Docker commonly used commands

Before the relevant RocketMQ concept made the introduction of the blog: RocketMQ (1) - Architecture Principle

First written below the required configuration file, run the configuration file, see the final operating results!

First, write a configuration file

1, create the required folder

mkdir -p  /opt/rocketmq/logs/nameserver-a
mkdir -p  /opt/rocketmq/logs/nameserver-b
mkdir -p /opt/rocketmq/store/nameserver-a
mkdir -p /opt/rocketmq/store/nameserver-b
mkdir -p /opt/rocketmq/logs/broker-a
mkdir -p /opt/rocketmq/logs/broker-b
mkdir -p /opt/rocketmq/store/broker-a
mkdir -p /opt/rocketmq/store/broker-b
mkdir -p /home/rocketmq/broker-a/
mkdir -p /home/rocketmq/broker-b/

2. Create broker.conf

broker.conf是Broker的配置文件, Because the image has not RocketMQ pull, so it is not the default broker.conf. So direct written here, time to replace the default broker.conf command.

Since the deployment is a dual master mode, so there will be two broker.conf, this time being named broker-a.conf and broker-b.conf

1) broker-a.conf

brokerClusterName = rocketmq-cluster
brokerName = broker-a
brokerId = 0
# 这个ip配置为内网访问,让mq只能内网访问,不配置默认为内网
#brokerIP1 = xxxxx
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=172.18.0.5:9876;172.18.0.5:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 11911
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

The main information configured here are:

1, the port number of the current exposure of Foreign Broker
2, registered to the address NameServer, see here there are two addresses, indicating NameServer also cluster deployment.
3, the current Broker's role is to or from the master, the master is represented here.

2)broker-b.conf

brokerClusterName = rocketmq-cluster
brokerName = broker-b
brokerId = 0
# 这个ip配置为内网访问,让mq只能内网访问,不配置默认为内网
#brokerIP1 = xxxxx
deleteWhen = 04
fileReservedTime = 48
brokerRole = ASYNC_MASTER
flushDiskType = ASYNC_FLUSH
# 内网的(阿里云有内网IP和外网IP)
namesrvAddr=172.18.0.5:9876;172.18.0.5:9877
autoCreateTopicEnable=true
#Broker 对外服务的监听端口,
listenPort = 11909
#Broker角色
#- ASYNC_MASTER 异步复制Master
#- SYNC_MASTER 同步双写Master
#- SLAVE
brokerRole=ASYNC_MASTER
#刷盘方式
#- ASYNC_FLUSH 异步刷盘
#- SYNC_FLUSH 同步刷盘
flushDiskType=ASYNC_FLUSH

The above is no difference, but the external current Brocker exposed port is not the same.

3, write docker-compose.yml

We can simply put docker-compose.yml understood as a script similar to Shell, the script defines the information to run multiple container applications.

version: '3.5'
services:
  rmqnamesrv-a:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: rmqnamesrv-a
    ports:
      - 9876:9876
    volumes:
      - /opt/rocketmq/logs/nameserver-a:/opt/logs
      - /opt/rocketmq/store/nameserver-a:/opt/store
    command: sh mqnamesrv
    networks:
        rmq:
          aliases:
            - rmqnamesrv-a

  rmqnamesrv-b:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: rmqnamesrv-b
    ports:
      - 9877:9877
    volumes:
      - /opt/rocketmq/logs/nameserver-b:/opt/logs
      - /opt/rocketmq/store/nameserver-b:/opt/store
    command: sh mqnamesrv
    networks:
        rmq:
          aliases:
            - rmqnamesrv-b

  rmqbroker-a:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: rmqbroker-a
    ports:
      - 11911:10911
    volumes:
      - /opt/rocketmq/logs/broker-a:/opt/logs
      - /opt/rocketmq/store/broker-a:/opt/store
      - /home/rocketmq/broker-a/broker-a.conf:/opt/rocketmq-4.3.0/conf/broker.conf 
    environment:
        TZ: Asia/Shanghai
        NAMESRV_ADDR: "rmqnamesrv-a:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker.conf autoCreateTopicEnable=true &
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-a

  rmqbroker-b:
    image: rocketmqinc/rocketmq:4.3.0
    container_name: rmqbroker-b
    ports:
      - 11909:10909
    volumes:
      - /opt/rocketmq/logs/broker-b:/opt/logs
      - /opt/rocketmq/store/broker-b:/opt/store
      - /home/rocketmq/broker-b/broker-b.conf:/opt/rocketmq-4.3.0/conf/broker.conf 
    environment:
        TZ: Asia/Shanghai
        NAMESRV_ADDR: "rmqnamesrv-b:9876"
        JAVA_OPTS: " -Duser.home=/opt"
        JAVA_OPT_EXT: "-server -Xms256m -Xmx256m -Xmn256m"
    command: sh mqbroker -c /opt/rocketmq-4.3.0/conf/broker.conf autoCreateTopicEnable=true &
    links:
      - rmqnamesrv-a:rmqnamesrv-a
      - rmqnamesrv-b:rmqnamesrv-b
    networks:
      rmq:
        aliases:
          - rmqbroker-b
  rmqconsole:
    image: styletang/rocketmq-console-ng
    container_name: rmqconsole
    ports:
      - 9001:8080
    environment:
        JAVA_OPTS: -Drocketmq.namesrv.addr=rmqnamesrv-a:9876;rmqnamesrv-b:9877 -Dcom.rocketmq.sendMessageWithVIPChannel=false
    networks:
      rmq:
        aliases:
          - rmqconsole
networks:
  rmq:
    name: rmq
    driver: bridge

From the configuration file can be generally seen that:

1, by pulling Docker total of five image recording. rmqnamesrv-a, rmqnamesrv-b, rmqbroker-a, rmqbroker-b, rmqconsole.
2, rmqconsole是一个可视化的工具can be viewed RocketMQ related information page.
3, it can be seen that for profile broker.conf broker has been replaced broker-a / b.conf.


Second, the deployment environment

The above is only the profile written, but there are many preconditions to start RocketMQ

1, the required environment

1. 建议使用64位操作系统,Linux / Unix / Mac;
2. 64位JDK 1.8+;
3. Maven 3.2.x;
4. Git的;
5. 4g +免费磁盘用于Broker服务器

At the same time need to run docker-compose.yml also need to install docker-compose

2, mounting docker-compose

You can see the official introduction about GitHub: https://github.com/docker/compose

Installation docker-compose

curl -L https://github.com/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

To see if the installation was successful

[root@izbp13196wp34obmnd4avdz ~]# docker-compose --version
docker-compose version 1.24.1, build 4667896b

3, a key step

All the operations front, are paving the way for this step, through docker-compose执行docker-compose.ymlthe configuration file

docker-compose -f docker-compose.yml up -d

If you see that, it means you're done!

View visual interface

perfect!

注意 It involves the relevant port to remember Ali goes back open!


reference

1、Apache RocketMQ

2、docker-compose

3, Docker deployment RocketMQ cluster (thank you very much)




只要自己变优秀了,其他的事情才会跟着好起来(中将9)

Guess you like

Origin www.cnblogs.com/qdhxhz/p/11096682.html