Target, using 2 machines to deploy RocketMQ multi-master multi-slave mode, asynchronous replication cluster mode.

First, modify the /etc/hosts file

192.168116.115 rocketmq1.192.168116.116 rocketmq2.Copy the code

After the cluster is configured, ping the cluster to ensure that the cluster can communicate with each other.

Compiled environment

git clone -b develop https://github.com/apache/rocketmq.gitCD rocketmq MVN - Prelease - all - DskipTests clean install -u CD distribution/target/apache - rocketmq is based on this version4.1Gz copy all the machines in the cluster to decompress tar -zxvf apache-Rocketmq_4.1.0.tar. gzCopy the code

Configure the cluster mode [Multi-master, multi-Slave, asynchronous replication]

Description of the configured directory:

  • 2m-noslave: indicates the multi-master mode
  • 2m-2s-sync: indicates the multi-master and multi-slave mode
  • 2m-2s-async: asynchronous replication in multi-master and multi-slave mode

Configuration item Configuration of a master

# # belongs to the cluster name brokerClusterName = rocketmq - cluster broker name, pay attention to the different configuration files to fill in different brokerName = broker - a # 0, said the Master, >0 for Slave brokerId=0 #nameServer address, semicolon split namesrvAddr= RocketMQ1: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, Default 72 hours fileReservedTime=120 #commitLog the default file size is 1 gb mapedFileSizeCommitLog=1073741824 #ConsumeQueue the default file size is 30W. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 DiskMaxUsedSpaceRatio =75 storePathRootDir=/appl/ Rocketmq /store #commitLog storage path StorePathCommitLog = / appl/rocketmq/store/commitlog # consumption queue storage paths storage paths storePathConsumeQueue = / appl/rocketmq/store/consumequeue # message index storage paths storePathIndex = / appl/rocketmq/store/index # checkpoint file storage path storeCheckpoint = / appl/rocketmq/store/checkpoint # abort abortFile file storage path = / appl/rocketmq/store / # abort limit default # 4 m maxMessageSize message size = 4194304 # flushCommitLogLeastPages = 4 #flushConsumeQueueLeastPages=2 #flushCommitLogThoroughInterval=10000 #flushConsumeQueueThoroughInterval=60000 #Broker Role #- ASYNC_MASTER Asynchronous replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=ASYNC_MASTER # Flush ASYNC_FLUSH #- SYNC_FLUSH flushDiskType=ASYNC_FLUSHCopy the code

Configuration Item Indicates the configuration of another standby

# # belongs to the cluster name brokerClusterName = rocketmq - cluster broker name, pay attention to the different configuration files to fill in different brokerName = broker - b # 0, said the Master, >0 for Slave brokerId=1 #nameServer address, semicolon split namesrvAddr= RocketMQ1: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 = 11911 # delete files point in time, the default 4 am deleteWhen = 4 # document retention time, Default 72 hours fileReservedTime=120 #commitLog the default file size is 1 gb mapedFileSizeCommitLog=1073741824 #ConsumeQueue the default file size is 30W. Adjust according to the business situation mapedFileSizeConsumeQueue = 120000 # 300000 # destroyMapedFileIntervalForcibly = redeleteHangedFileInterval = 120000 DiskMaxUsedSpaceRatio =75 storePathRootDir=/appl/ RocketMQ -s/store #commitLog storage path StorePathCommitLog =/appl/ RocketMQ -s/store/ COMMITlog # Consume queue storage path Storage path StorePathConsumeQueue =/ Appl/RocketMQ -s/store/ consumeQueue # Message index store storePathIndex=/ Appl/RocketMQ -s/store/index StoreCheckpoint =/appl/ Rocketmq -s/store/checkpoint #abort the file storage path AbortFile =/appl/ RocketMQ -s/store/ ABORT # Limit message size default 4M #maxMessageSize=4194304 #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 flushDiskType=ASYNC_FLUSHCopy the code

Note: The primary and secondary ports and storage paths are different because one machine is deployed in active/standby mode. If multiple machines are deployed, the primary difference is brokerId and brokerRole configuration.

Note that ${user.home} in the logback.*.xml configuration file needs to replace the directory it specified

You can use sed instead:

Sed -i 's#${user.home}#/appl/rocketmq#g' *.xml # sed -i 's#${user.home}#/appl/rocketmq-s#g' *.xmlCopy the code

Modify JVM parameters in the startup script

RocketMQ4.1.0 officially recommends using 64bit JDK 1.8+. The JVM parameters are as follows:

-server -Xms4g -Xmx4g -Xmn2g -XX:PermSize=128m -XX:MaxPermSize=320mCopy the code

Note: metadata space, specifically used to store metadata, it is used in jdK8 to replace perM.

The JVM heap size is adjusted according to machine conditions. If the test machine memory is too small, you need to adjust it otherwise it will not start, for example, as shown below

-Xms1G -Xmx1G -Xmn512m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320mCopy the code

You can use sed to replace all permsizes and maxpermsizes:

sed -i 's#PermSize#MetaspaceSize#g' *
sed -i 's#MaxPermSize#MaxMetaspaceSize#g' *Copy the code

JVM inside runbroker.sh:

-Xms8g -Xmx8g -Xmn4gCopy the code

Modify it according to your situation.

RocketMQ default JVM parameters except heap size should not be adjusted for now. We will see if any other parameters need to be adjusted.

JVM parameters for broker:

JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn512m"
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m 
-XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30
-XX:SoftRefLRUPolicyMSPerMB=0 -XX:SurvivorRatio=8 -XX:+DisableExplicitGC"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log 
-XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime 
-XX:+PrintAdaptiveSizePolicy"
JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 
-XX:GCLogFileSize=30m"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch"
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g"
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking"
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"Copy the code

-xx :+DisableExplicitGC, -xx :MaxDirectMemorySize=15g, but when the threshold is reached, system. gc is called to do a full GC, key system. gc is disabled. I hope that big guy knows, in the comments section, thanks.

Start the service

Remember to start NameServer before starting the Broker, and to close the Broker before closing NameServer.

Start the NameServer:

 nohup sh /appl/apache-rocketmq/bin/mqnamesrv &
tail -f /appl/rocketmq-s/logs/rocketmqlogs/namesrv.log
#tail -f /appl/rocketmq/logs/rocketmqlogs/namesrv.log
INFO main - The Name Server boot success. serializeType=JSONCopy the code

Note: Since namesrv ports are written in code, one machine can only start one Namesrv.

Start the Broker:

Rocketmq1 machine: nohup sh /appl/ apache-RocketMQ /bin/mqbroker -c /appl/ apache-RocketMQ /conf/2m-2s-async/broker-a.properties >/dev/null 2> &1 &

nohup sh /appl/apache-rocketmq-s/bin/mqbroker -c /appl/apache-rocketmq-s/conf/2m-2s-async/broker-b-s.properties >/dev/null 2> &1Nohup sh /appl/ apache-RocketMQ /bin/mqbroker -c /appl/ apache-Rocketmq /conf/2m-2s-async/broker-b.properties >/dev/null 2> &1 &

nohup sh /appl/apache-rocketmq-s/bin/mqbroker -c /appl/apache-rocketmq-s/conf/2m-2s-async/broker-a-s.properties >/dev/null 2> &1& tail -f/appl/rocketmq/logs/rocketmqlogs/broker. The log... INFO main - The broker[broker-a,192.168116.116:10911] boot success. serializeType=JSON and name server is rocketmq1:9876; rocketmq2:9876... Tail -f/appl/rocketmq/logs/rocketmqlogs namesrv. The log...new broker registerd, 192.168116.116:11911 HAServer: 192.168116.116:11912...new broker registerd, 192.168116.115:11911 HAServer: 192.168116.115:11912...Copy the code

Service shutdown:

sh bin/mqshutdown broker
sh bin/mqshutdown namesrvCopy the code

At this point, the RocketMQ cluster environment deployment is complete and to be continued…

If you find it rewarding, please click “like” and follow it.


Personal public account, welcome to pay attention to, consult more wonderful history!!

Originality zero public account