RocketMq master-slave asynchronous cluster

Posted by tmbrown on Wed, 23 Feb 2022 11:18:04 +0100

Original link: https://blog.csdn.net/weixin_40533111/article/details/84451219 Author April day may rain ^ ^ ^, Please indicate the source for reprint, thank you

preface

This article is based on the latest edition rocketmq 4.3.2 Construction: 2 nodes. Node a deploys A-m and B-S, and node B deploys A-s and B-m
The functional principle and cluster can be referred to: Chinese documents and roketmq learning practice (III) Part II: Sequential messages and transaction messages

catalogue

1. Prepare the environment
2. Start construction

text

1. Prepare the environment

1. 2 Linux servers( centos7)
2.maven (above 3.5)
3.jdk(1.8 used in this article (some people say that using the built-in system may lead to some problems and is not tested))
4. Tools: used xshell+xftp
The deployment structure is as follows:

2. Start construction

1. Download and upload the installation package

Download the rocketmq binary package installation package from the official apache website and upload it to node 1 (192.168.229.5), address: http://rocketmq.apache.org/release_notes/release-notes-4.3.2/

2. Decompression

Unzip and change the directory of the file to rocketmq

unzip rocketmq-all-4.3.2-bin-release.zip

   
  • 1

3. Modify the configuration file

rocketmq gives three recommended configuration modes by default

  1. 2m-2s-async (master-slave asynchronous), --- this paper adopts this method
  2. 2m-2s-sync (master-slave synchronization)
  3. 2m noslave (master only)

Modify 2m-2s- async Configuration file under

You can modify any one. You only need to specify the configuration file at startup, which generally conforms to the naming constraint
be careful:

  1. autoCreateTopicEnable=true, it is recommended to start the test offline and close it online
  2. When starting multiple brokers on the same machine, you need to use different broker configuration files to start the instance,
    eg node 1 starts a-m and B-S, using broker-a.properties and broker-b-s.properties
  3. listenPort is 10911 by default. When multiple broker examples are started on a machine, the ports need to be distinguished
  4. When the broker is started, the default memory setting is relatively large. Change it to suit the machine. See Step 6 for details
  5. When a node starts multiple broker instances, different storePath paths need to be specified if the storage path is set. (if it is not set, it is different by default.)

3.1 the main contents of modifying broker-a.properties are as follows:

    #Cluster name
    brokerClusterName=rocketmq-cluster
    #The name of the broker can be repeated. For management, each master has a name, and his slave is the same as him. eg:Amaster is called broker-a, and his slave is also called broker-a
    brokerName=broker-a
    #0 means Master and > 0 means Slave
    brokerId=0
    #nameServer address, semicolon split
    namesrvAddr=192.168.229.5:9876;192.168.229.6:9876
    #When sending messages, automatically create topic s that do not exist in the server. The number of queues created by default
    defaultTopicQueueNums=4
    #Whether to allow the Broker to automatically create topics. It is recommended to open offline and close online
    autoCreateTopicEnable=true
    #Whether to allow the Broker to automatically create subscription groups. It is recommended to open offline and close online
    autoCreateSubscriptionGroup=true
    #The listening port of the Broker for external services,
    listenPort=10911
    #Delete file time: 4 am by default
    deleteWhen=04
    #File retention time, 48 hours by default
    fileReservedTime=120
    #commitLog the default size of each file is 1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue stores 30W files by default, which can be adjusted according to business conditions
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #Detect physical file disk space
    diskMaxUsedSpaceRatio=88
    #Storage path
    storePathRootDir=/usr/local/rocketmq/store/broker-a
    #commitLog storage path
    storePathCommitLog=/usr/local/rocketmq/store/broker-a/commitlog
    #Consumption queue storage path storage path
    storePathConsumeQueue=/usr/local/rocketmq/store/broker-a/consumequeue
    #Message index storage path
    storePathIndex=/usr/local/rocketmq/store/broker-a/index
    #checkpoint file storage path
    storeCheckpoint=/usr/local/rocketmq/store/checkpoint
    #abort file storage path
    abortFile=/usr/local/rocketmq/store/abort
    #Limited message size
    maxMessageSize=65536
    #flushCommitLogLeastPages=4
    #flushConsumeQueueLeastPages=2
    #flushCommitLogThoroughInterval=10000
    #flushConsumeQueueThoroughInterval=60000
    #Role of Broker
    #- ASYNC_MASTER asynchronous replication master
    #- SYNC_MASTER synchronous double write master
    #- SLAVE
    brokerRole=ASYNC_MASTER
    #Disc brushing mode
    #- ASYNC_FLUSH asynchronous brush disk
    #- SYNC_FLUSH synchronous brush disc
    flushDiskType=ASYNC_FLUSH
    #checkTransactionMessageEnable=false
    #Number of message sending thread pools
    #sendMessageThreadPoolNums=128
    #Number of pull message thread pools
    #pullMessageThreadPoolNums=128

   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

3.2 the main contents of modifying broker-b-s.properties are as follows:

    #Cluster name
    brokerClusterName=rocketmq-cluster
    #The name of the broker can be repeated. For management, each master has a name, and his slave is the same as him. eg:Amaster is called broker-a, and his slave is also called broker-a
    brokerName=broker-b
    #0 means Master and > 0 means Slave
    brokerId=1
    #nameServer address, semicolon split
    namesrvAddr=192.168.229.5:9876;192.168.229.6:9876
    #When sending messages, automatically create topic s that do not exist in the server. The number of queues created by default
    defaultTopicQueueNums=4
    #Whether to allow the Broker to automatically create topics. It is recommended to open offline and close online
    autoCreateTopicEnable=true
    #Online and offline subscription groups are allowed. It is recommended to enable or disable online and offline subscription groups automatically
    autoCreateSubscriptionGroup=true
    #The listening port of the Broker for external services,
    listenPort=10920
    #Delete file time: 4 am by default
    deleteWhen=04
    #File retention time, 48 hours by default
    fileReservedTime=120
    #commitLog the default size of each file is 1G
    mapedFileSizeCommitLog=1073741824
    #ConsumeQueue stores 30W files by default, which can be adjusted according to business conditions
    mapedFileSizeConsumeQueue=300000
    #destroyMapedFileIntervalForcibly=120000
    #redeleteHangedFileInterval=120000
    #Detect physical file disk space
    diskMaxUsedSpaceRatio=88
    #Storage path
    storePathRootDir=/usr/local/rocketmq/store/broker-b-s
    #commitLog storage path
    storePathCommitLog=/usr/local/rocketmq/store/broker-b-s/commitlog
    #Consumption queue storage path storage path
    storePathConsumeQueue=/usr/local/rocketmq/store/broker-b-s/consumequeue
    #Message index storage path
    storePathIndex=/usr/local/rocketmq/store/broker-b-s/index
    #checkpoint file storage path
    storeCheckpoint=/usr/local/rocketmq/store/checkpoint
    #abort file storage path
    abortFile=/usr/local/rocketmq/store/abort
    #Limited message size
    maxMessageSize=65536
    #flushCommitLogLeastPages=4
    #flushConsumeQueueLeastPages=2
    #flushCommitLogThoroughInterval=10000
    #flushConsumeQueueThoroughInterval=60000
    #Role of Broker
    #- ASYNC_MASTER asynchronous replication master
    #- SYNC_MASTER synchronous double write master
    #- SLAVE
    brokerRole=SLAVE
    #Disc brushing mode
    #- ASYNC_FLUSH asynchronous brush disk
    #- SYNC_FLUSH synchronous brush disc
    flushDiskType=ASYNC_FLUSH
    #checkTransactionMessageEnable=false
    #Number of message sending thread pools
    #sendMessageThreadPoolNums=128
    #Number of pull message thread pools
    #pullMessageThreadPoolNums=128

   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60

4. Configure the second machine (192.168.229.6)

  1. The clone virtual machine used in this paper can quickly obtain a machine that is the same as the original machine. Because it is exactly the same, it is necessary to change the mac address. If you use static ip, you can change the configuration of the gateway. Of course, you can rebuild one manually
  2. The configuration is the same as the previous step. You can change the specific information of ip and broker

5. Start nameServer

  1. The above configuration file specifies the storage path of commitLog, queue, log, etc., and creates this folder
Node 1 execution:
 mkdir -p /usr/local/rocketmq/store/broker-a /usr/local/rocketmq/store/broker-a/nsumequeue /usr/local/rocketmq/store/broker-a/commitlog /usr/local/rocketmq/store/broker-a/index /usr/local/rocketmq/logs /usr/local/rocketmq/store/broker-b-s /usr/local/rocketmq/store/broker-b-s/nsumequeue /usr/local/rocketmq/store/broker-b-s/commitlog /usr/local/rocketmq/store/broker-b-s/index
 Node 2 execution:
 mkdir -p /usr/local/rocketmq/store/broker-a-s /usr/local/rocketmq/store/broker-a-s/nsumequeue /usr/local/rocketmq/store/broker-a-s/commitlog /usr/local/rocketmq/store/broker-a-s/index /usr/local/rocketmq/logs /usr/local/rocketmq/store/broker-b /usr/local/rocketmq/store/broker-b/nsumequeue /usr/local/rocketmq/store/broker-b/commitlog /usr/local/rocketmq/store/broker-b/index

   
  • 1
  • 2
  • 3
  • 4

2. Start nameserver of node 1 (192.168.229.5)

nohup sh /usr/local/rocketmq/bin/mqnamesrv >/usr/local/rocketmq/logs/mqnamesrv.log 2>&1 &

   
  • 1

Output the log file to the specified file, and then view the log, jps and other java processes. The results are in line with expectations

3. Start nameserver of node 2 (192.168.229.5)
The steps are as follows: node 1 is started successfully

6. Start the broker

  1. Start the master of broker-a of node 1 and the corresponding configuration file broker-a.properties
    When starting multiple instances, specify the corresponding configuration file
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a.properties > /usr/local/rocketmq/logs/broker-a.log 2>&1 &

   
  • 1


The memory of the default configuration is large, because the virtual machine is deployed, so it should be smaller

vi /usr/local/rocketmq/bin/runbroker.sh

   
  • 1


Start broker-a again

  1. Start broker-a-s of node 2
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-a-s.properties > /usr/local/rocketmq/logs/broker-a-s.log 2>&1 &

   
  • 1
  1. Start broker-b of node 2
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b.properties > /usr/local/rocketmq/logs/broker-b.log 2>&1 &

   
  • 1

  1. Start broker-b-s of node 1
nohup sh /usr/local/rocketmq/bin/mqbroker -c /usr/local/rocketmq/conf/2m-2s-async/broker-b-s.properties > /usr/local/rocketmq/logs/broker-b-s.log 2>&1 &

   
  • 1

  1. Check the startup status of the cluster: four nodes meet the expectations. So far, the first version of the cluster has been built

7. Start the web management interface

rocketmq provides a variety of management methods, including command line and interface,
apache provides an open source extension project: https://github.com/apache/rocketmq-externals It contains a sub project, rocketmq console, which can be used after packaging under configuration

  1. This is a springboot project. The default name service (rocketmq.config.namesrvAddr) is empty and needs to be changed to its own

    2. Package with maven
mvn clean package -Dmaven.test.skip=true

   
  • 1

  1. Upload to the server and start Java jar
java -jar rocketmq-console-ng-1.0.0.jar >/usr/local/rocketmq/logs/mq-console.log 2>&1 &

   
  • 1
  1. Page validation

    So far, the construction is completed

When will the endless cycle of the spring flower and the autumn moon come to an end?

How much do you know about the past?

Last night, there was another east wind in the small building. My hometown can't bear to look back on the moonlight.

Carved fences and jade masonry should still exist, but Zhu Yan has changed.

How much can you worry? It's like a river of spring water flowing eastward.

Topics: Java Apache Zookeeper