This article describes how to set up a RocketMQ cluster with 2 master and 2 slave synchronous replication servers.

Cluster architecture

  • The nodes of the NameServer cluster are stateless, there is no message synchronization between nodes, and the Broker starts connected to the NameServer node.
  • Broker clusters are divided into primary and secondary nodes. A set of clusters of primary and secondary brokers are separated according to BrokerNames. Within the cluster, primary and secondary nodes are separated according to Brokerids, where 0 is the primary node and non-0 is the secondary node.

Basic Server Information

  • Two Tencent cloud servers are used here; (Use the internal IP address for internal communication and the public IP address for external communication.)

Configuring the Server Environment

  • The JDK installation:sudo apt-get install openjdk-8-jdk

  • Install RocketMQ

    • Upload the installation package: SCP rocketmq-all-4.8.0-bin-release.zip Username @tencent cloud IP address :/home/ubuntu/rocketmq-all-4.8.0-bin-release.zip

    • Unpack, configure environment variables, and test whether NameServer and Broker have started successfully

      • Start the NameServer:nohup sh mqnamesrv &
      • Start the Broker:nohup sh mqbroker -n localhost:9876 &

    • RocketMQ startup error: NameServer startup error, bin/runserver.sh: 70: Not found Unrecognized option: -Xlog:gc*:file=/dev/shm/rmq_srv_gc_%p_%t.log:time,tags:filecount=5,filesize=30M…

      • Solution: Comment out higher JDK commands

Server Cluster Role

IP role Architectural patterns
172.17.0.3 NameServer, Broker Master1, Slave2
172.17.0.4 NameServer, Broker Master2, Slave1

Server Configuration

  • Create the message store path, which is the default home path. Start two broker clusters and create storage directories.
    • 172.17.0.3 path:
    • 172.17.0.4 path:

The Broker configuration

  • Use the sample configuration from the RocketMQ installation package conf/ 2M-2s-sync;
  • Configure Master1 and Slave2 on host 172.17.0.3.
    • Broker-a. perties file configuration:
    BrokerIP1 =1.116.250.158 brokerIP2=1.116.250.158 brokerClusterName= Rocketmq-cluster # Broker name BrokerName =broker- A #0 for Master, >0 for Slave brokerId=0 #nameServer address, NamesrvAddr =172.17.0.3:9876; DefaultTopicQueueNums =4 # Allow the Broker to automatically create topics. # Allow the Broker to automatically create subscription groups. Online closed autoCreateSubscriptionGroup = true # Broker foreign service listening on port listenPort = 10911 # delete files point in time, the default 4 am deleteWhen = 4 # document retention time, MapedFileSizeCommitLog =1073741824 #ConsumeQueue by default, 30W files are stored in each file. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 # test physical file disk space diskMaxUsedSpaceRatio = 88 # storage paths storePathRootDir = / home/ubuntu/rocketmq/store/broker - a # commitLog storage paths StorePathCommitLog = / home/ubuntu/rocketmq/store/broker queue storage - a/commitlog # consumption path storage paths StorePathConsumeQueue = / home/ubuntu/rocketmq/store/broker - a/consumequeue # message index storage paths StorePathIndex = / home/ubuntu/rocketmq/store/broker - a/index # checkpoint file storage path StoreCheckpoint = / home/ubuntu/rocketmq/store/broker - a/checkpoint # abort file storage path AbortFile = / home/ubuntu/rocketmq/store/broker - a / # abort message limit maxMessageSize = 65536 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous copy Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SYNC_MASTER # Flush Asynchronous flush #- SYNC_FLUSH synchronous brush plate flushDiskType = # SYNC_FLUSH checkTransactionMessageEnable = false number # # message thread pool sendMessageThreadPoolNums = 128 # message thread pool number # pullMessageThreadPoolNums = 128Copy the code

    • Broker – b – supachai panitchpakdi roperties file:
    BrokerIP1 =1.116.250.158 brokerIP2=1.116.250.158 brokerClusterName= Rocketmq-cluster # Broker name BrokerName =broker- B #0 for Master, >0 for Slave brokerId=1 #nameServer address, NamesrvAddr =172.17.0.3:9876; DefaultTopicQueueNums =4 # Allow the Broker to automatically create topics. # Allow the Broker to automatically create subscription groups. Online closed autoCreateSubscriptionGroup = true # Broker foreign service listening on port listenPort = 11011 # delete files point in time, the default 4 am deleteWhen = 4 # document retention time, MapedFileSizeCommitLog =1073741824 #ConsumeQueue by default, 30W files are stored in each file. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 # test physical file disk space diskMaxUsedSpaceRatio = 88 # storage paths storePathRootDir = / home/ubuntu/rocketmq/store/broker - b - # s commitLog storage paths StorePathCommitLog = / home/ubuntu/rocketmq/store/broker - b - # s/commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / home/ubuntu/rocketmq/store/broker - b - # s/consumequeue message index storage paths StorePathIndex = / home/ubuntu/rocketmq/store/broker - - s/b index # checkpoint file storage path StoreCheckpoint = / home/ubuntu/rocketmq/store/broker - b - s/checkpoint # abort file storage path AbortFile = / home/ubuntu/rocketmq/store/broker - b - s / # abort message limit maxMessageSize = 65536 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SLAVE # Flush Flush Asynchronous flush #- SYNC_FLUSH synchronous brush plate flushDiskType = # ASYNC_FLUSH checkTransactionMessageEnable = false number # # message thread pool sendMessageThreadPoolNums = 128 # message thread pool number # pullMessageThreadPoolNums = 128Copy the code
  • Configure clusters for Master2 and Slave1 on host 172.17.0.4:
    • Broker – p. roperties:
    BrokerClusterName = Rocketmq-cluster # brokerClusterName= RocketMq-cluster # Broker name BrokerName =broker -B #0 for Master, >0 for Slave brokerId=0 #nameServer address, NamesrvAddr =172.17.0.3:9876; DefaultTopicQueueNums =4 # Allow the Broker to automatically create topics. # Allow the Broker to automatically create subscription groups. Online closed autoCreateSubscriptionGroup = true # Broker foreign service listening on port listenPort = 10911 # delete files point in time, the default 4 am deleteWhen = 4 # document retention time, MapedFileSizeCommitLog =1073741824 #ConsumeQueue by default, 30W files are stored in each file. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 # test physical file disk space diskMaxUsedSpaceRatio = 88 # storage paths storePathRootDir = / home/ubuntu/rocketmq/store/broker - b # commitLog storage paths StorePathCommitLog = / home/ubuntu/rocketmq/store/broker - # b/commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / home/ubuntu/rocketmq/store/broker - b/consumequeue # message index storage paths StorePathIndex = / home/ubuntu/rocketmq/store/broker - b/index # checkpoint file storage path StoreCheckpoint = / home/ubuntu/rocketmq/store/broker - b/checkpoint # abort file storage path AbortFile = / home/ubuntu/rocketmq/store/broker - b / # abort message limit maxMessageSize = 65536 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous copy Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SYNC_MASTER # Flush Asynchronous flush #- SYNC_MASTER Synchronous Double Write Master # -Slave brokerRole=SYNC_MASTER # Flush Mode #- ASYNC_FLUSH Asynchronous flush # -SynC_Flush Synchronous flush # # flushDiskType = SYNC_FLUSH checkTransactionMessageEnable = false message thread pool number # sendMessageThreadPoolNums = 128 # number message thread pool #pullMessageThreadPoolNums=128Copy the code

    • Broker – a – supachai panitchpakdi roperties file:
    BrokerClusterName = Rocketmq-cluster # brokerClusterName= RocketMq-cluster # Broker name BrokerName =broker- A #0 for Master, >0 for Slave brokerId=1 #nameServer address NamesrvAddr =172.17.0.3:9876; DefaultTopicQueueNums =4 # Allow the Broker to automatically create topics. # Allow the Broker to automatically create subscription groups. Online closed autoCreateSubscriptionGroup = true # Broker foreign service listening on port listenPort = 11011 # delete files point in time, the default 4 am deleteWhen = 4 # document retention time, MapedFileSizeCommitLog =1073741824 #ConsumeQueue by default, 30W files are stored in each file. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = ConsumeQueue each file by default article 30 w, Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 # test physical file disk space diskMaxUsedSpaceRatio = 88 # storage paths storePathRootDir = / home/ubuntu/rocketmq/store/broker - a - s # commitLog storage paths StorePathCommitLog = / home/ubuntu/rocketmq/store/broker - a - s / # commitlog consumption queue storage paths storage paths StorePathConsumeQueue = / home/ubuntu/rocketmq/store/broker - a - s / # consumequeue message index storage paths StorePathIndex = / home/ubuntu/rocketmq/store/broker - a - s/index # checkpoint file storage path StoreCheckpoint = / home/ubuntu/rocketmq/store/broker - a - s/checkpoint # abort file storage path AbortFile = / home/ubuntu/rocketmq/store/broker - a - s / # abort message limit maxMessageSize = 65536 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=SLAVE # Flush Flush Asynchronous flush #- SYNC_FLUSH synchronous brush plate flushDiskType = # ASYNC_FLUSH checkTransactionMessageEnable = false number # # message thread pool sendMessageThreadPoolNums = 128 # message thread pool number # pullMessageThreadPoolNums = 128Copy the code
  • Pay attention to:
    • Two broker ports configured for the same host must be different.
    • Two brokers in a unified host configuration need to specify store directories.
    • You need to configure a public IP address; otherwise, the IP address cannot be accessed.

The cluster start

  • Start the NameServer cluster
    • Run the command on 172.17.0.3 and 172.17.0.4nohup mqnamesrv &;
  • Start a Broker cluster
    • Start Master1 and Slave2 in 172.17.0.3:
    Nohup mqbroker - c/usr/local/rocketmq/rocketmq - all - 4.8.0 - bin - release/conf / 2 m - 2 s - sync/broker - Amy polumbo roperties & nohup Mqbroker - c/usr/local/rocketmq/rocketmq - all - 4.8.0 - bin - release/conf / 2 m - 2 s - sync/broker - b - supachai panitchpakdi roperties &Copy the code

    • Start Master2 and Slave1 in 172.17.0.4:
    Nohup mqbroker - c/usr/local/rocketmq/rocketmq - all - 4.8.0 - bin - release/conf / 2 m - 2 s - sync/broker - p. roperties & nohup Mqbroker - c/usr/local/rocketmq/rocketmq - all - 4.8.0 - bin - release/conf / 2 m - 2 s - sync/broker - a - supachai panitchpakdi roperties &Copy the code

Use RocketmQ-Console to view the cluster

  • Download Rocketmq-externals, modify the NameServer configuration in rocketMq-Console application. Properties to the cluster configuration, compile it into a JAR, upload it to the server, and execute the jar.

  • accesshttp://1.116.250.158:8080/To view the cluster status:

  • New theme, test message sending and other functions;

reference

  • B RocketMQ video tutorial
  • RocketMQ [1] introduces and distributes the multi-master multi-slave mode on the server