The author The date of The version number
Yuan childe 2019-12-14 v1.0.0

The less you know, the less you don’t know

You can’t level up without your friends’ likes

A, gossip

RocketMQ is alibaba’s messaging middleware. It is a distributed messaging and streaming platform with low latency, high performance and reliability, trillions of capacity and flexible scalability… (This must be registered in the delay queue to read the source code)

First, learn what roles the software uses through the official explanation of the software architecture. Take you to fly the address, through Google Translate or relatively easy to understand…

Since these concepts are used in deployment, here is a brief description of my understanding.

  • NameServer: Leader. The default port is 9876. Multiple services need to be started in a cluster and do not communicate with each other.

    Function description: Receives client requests (configuration information in the development project, that is, the address and port number information), manages the Broker(by heartbeat, not by eye), and receives the routing information of the Broker, and records the full routing information for each.

  • Broker Server: known as the Follower of NameServer and the core role of RocketMQ, the default port is 10911. Multiple services need to be started in a cluster, and they do not communicate with each other. However, when HA services (high availability) are deployed, brokers are divided into Master and Slave brokers, with data synchronization between them.

    Main functions: receives client requests, manages producer and consumer clients, and manages messages (including physical storage).

  • They are both producers and consumers. At deployment time, we don’t have to worry about it. Roles that produce and consume messages as applied to development projects.

    So when we deploy, keep in mind that there are only two concepts: NameServer and Broker Server.

Download the installation package

Official address: Installation documentation, 4.6.0 download address

Download the latest version of the software: Rocketmq-all-4.6.0-bin-release.zip

Iii. System environment check/preparation

  • Java JDK1.8 or above
  • The Centos7 operating system is used as an example
  • If you are not a female driver, use root at all times
  • High-energy remindIf the guest officer uses a non-root user, in consideration of permissions, it is necessary to change the root level directories, such as /var, in the article to the user home directory, or modify the permissions of the directory
  • Unzip zip command, installation mode:yum install -y unzip zip
  • For details on how to map domain names, see the extended content section of other articles

Four, LAN

This section describes the installation of a NameServer and a Broker service on a machine.

1. Select the installation directory (place the tools in the /soft folder, or as you wish)

unzip

Root @ dev/soft # unzip rocketmq - all - 4.6.0 - bin - release. ZipCopy the code

Create a soft connection to facilitate software upgrade or multi-version switchover

[root@dev /soft]# ln -s Rocketmq-all-4.6.0-bin-release RocketMQCopy the code

2. Set environment variables

Append the following to the bottom of the file. Try not to change the ROCKETMQ_HOME variable name because scripts in the software bin directory will use the environment variable with this name.

[root@dev /soft]# vi /etc/profile export ROCKETMQ_HOME=/soft/ RocketMQ export PATH=$PATH:$ROCKETMQ_HOME/bin  Esc :wq [root@dev /soft]# source /etc/profileCopy the code

3. Simple start and touch the bottom

#Start the NameServer
[root@dev /soft]# mqnamesrv
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
#The startup is successful. CTRL + C exits

#Start the Broker
[root@dev /soft]# mqbroker
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
#
# There is insufficient memory for the Java Runtime Environment to continue.
# Native memory allocation (mmap) failed to map 8589934592 bytes for committing reserved memory.
# An error report file with more information is saved as:
# /soft/hs_err_pid127774.log
#I beep beep beep. I'm out of memory
Copy the code

4. Find something to change

  1. The JVM parameter

The default JVM parameters that NameServer and Broker start are somewhat large and can be reduced if the environment is not production.

NameServer: From the bin/mqnamesrv script, I learned that bin/runserver.sh is used to set up the JVM.

Locate the place where -xms is set and comment out the line to adjust as shown below. (See this configuration for JDK 1.8 or higher)

[root@dev /soft/rocketmq/bin]# vi runserver.sh
#JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"JAVA_OPT="${JAVA_OPT} -server-xms128m -xmx128m-xmn32m-xx :MetaspaceSize= 32m-xx :MaxMetaspaceSize=64m" Run the Esc :wq command to save the configurationCopy the code

Broker: Through the bin/mqbroker script, you learned to use bin/runbroker.sh to set up the JVM, so continue to disk.

Locate the place where -xms is set and comment out the line to adjust as shown below.

[root@dev /soft/rocketmq/bin]# vi runbroker.sh
#JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g -Xmn4g"JAVA_OPT="${JAVA_OPT} -server-xms128m -xmx128m -xmn32m "Run Esc :wq to save the configurationCopy the code
  1. Log path

The default path is the home directory of the current startup user ${user.home}. You can change the storage path as required. (In fact, the adjustment is also troublesome, the future update should remember to restore)

NameServer log: conf/logback_namesrv. XML, find the content configuration line and define a log path variable substitution with the same name below. The log path directory is automatically created when the service is started.

[root@dev /soft/rocketmq/conf]# vi logback_namesrv.xml
<configuration>
     <property name="user.home" value="/var/rocketmq"/> Run the following command to save the configuration: Esc :wqCopy the code

Broker log: conf/logback_broker.xml, do the same.

[root@dev /soft/rocketmq/conf]# vi logback_broker.xml <configuration> <property name="user.home" value="/var/rocketmq" /> Run the following command to save the configuration: Esc :wqCopy the code
  1. Adjust the address of the NameServer that the Broker specifies by default (if both are installed on the same machine)

First, make a copy of conf/broker.conf for backup and add a line namesrvAddr at the bottom of the file. (IP addresses are also recommended for domain name mapping)

[root@dev /soft/rocketmq/conf]# cp broker.conf broker.conf.bak
[root@dev /soft/rocketmq/conf]# vi broker.conf
#See flushDiskType = ASYNC_FLUSHNamesrvAddr = 127.0.0.1:9876Copy the code

When the Broker starts, it takes the -c parameter, specifying the configuration file path.

[root@dev /soft/rocketmq]# mqbroker -c /soft/rocketmq/conf/broker.conf
Copy the code

Five, the cluster

This chapter focuses on multi-node clustering of NameServer and Broker. To increase the difficulty, prepare to deploy the cluster on a single machine.

A NameServer cluster starts multiple NameServer services. Broker clusters are divided into three modes: multiple Masters, multiple masters, and multiple slaves-asynchronous replication and synchronous double-write. Slave Backs up messages from the Master, does not receive messages written by the client, and can consume messages. The difference between asynchronous and synchronous modes is when the Master sends the response information back to the client after writing the message.

  • Multiple masters, no Slave

    If one fails, unconsumed messages on that machine will not be consumed by subscriptions until they recover.

  • BrokerRole =ASYNC_MASTER – Asynchronous Replication (Parameter Control: brokerRole=ASYNC_MASTER)

    In asynchronous mode, if data is written successfully to the Master, the Master sends a message to the client immediately and asynchronously writes data to the Slave. There is a short message delay between the active and standby nodes.

  • BrokerRole =SYNC_MASTER – Synchronous Double write (Parameter Control: brokerRole=SYNC_MASTER)

    The write success status is reported to the client only after data is successfully written to the Master and Slave.

In addition, we will pay attention to the parameter flushDiskType, asynchronous flush and synchronous flush.

  • FlushDiskType =ASYNC_FLUSH

    Once the message is written to the memory, the client is informed of the write success status. When the number of messages in the memory reaches a certain level, the disk write operation is triggered.

  • FlushDiskType =SYNC_FLUSH

    The write success status is reported to the client only after the message confirms that the data has been written to the disk.

    The default Broker configuration for these three modes is also provided in the conf directory: 2m-noslave (two masters), 2m-2s-async (two masters, one slave for each Master), and 2m-2s-sync (two masters, one slave for each Master).

Here I thought about how to write in order to achieve the effect of full scene coverage. The end result is that you choose to put all your cluster deployments on one machine, because one machine is much more important than multiple machines, such as port conflicts and file directory scenarios. However, if possible, deploy one per node, since the whole point of clustering is to minimize single points of failure and improve overall performance.

All right, it’s time to start your stand-alone deployment cluster journey. Our cluster target is 2 Nameservers and 4 brokers (2 Master, 2 Slave, each Master corresponds to one Slave, asynchronous replication). Use the official configuration 2M-2s-Async extension to explain.

NameServer cluster

  1. Preparing configuration Files

The main focus is to resolve port conflicts through NameServer configuration files. First, we create the master folder for the cluster configuration and the NameServer configuration file.

#In the user root directory, create a cluster configuration folder
[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster
#Create two configuration files for NameServer
[root@dev /soft/rocketmq]# touch ~/rocketmq/cluster/nameserver-a.properties
[root@dev /soft/rocketmq]# touch ~/rocketmq/cluster/nameserver-b.properties
Copy the code

nameserver-a.properties

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/nameserver-a.properties
listenPort=9876
#Home directory, where the main is changed to specify the log files to be usedRocketmqHome = / root/rocketmq/cluster/nameserver - a savings: Esc: wqCopy the code

nameserver-b.properties

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/nameserver-b.properties listenPort=9877 RocketmqHome = / root/rocketmq/cluster/nameserver - b perform save: Esc: wqCopy the code
  1. createrocketmqHomePath, and check into the log configuration file so that each NameServer service generates a different log file. (Multiple nodes of the same type will write log files with the same name upon startup, causing some interference)

Nameserver – a log

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/nameserver-a/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_namesrv.xml ~/rocketmq/cluster/nameserver-a/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/nameserver-a/conf/logback_namesrv.xml <configuration> <property name="user.home" Value ="/var/rocketmq/nameserver-a" /> Save the configuration: Esc :wqCopy the code

Nameserver – b logs

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/nameserver-b/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_namesrv.xml ~/rocketmq/cluster/nameserver-b/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/nameserver-b/conf/logback_namesrv.xml <configuration> <property name="user.home" Value ="/var/rocketmq/nameserver-b" /> Save the configuration: Esc :wqCopy the code
  1. Start the
[root@dev /soft/rocketmq]# nohup mqnamesrv -c ~/rocketmq/cluster/nameserver-a.properties >/dev/null 2>&1 & [root@dev /soft/rocketmq]# nohup mqnamesrv -c ~/rocketmq/cluster/nameserver-b.properties >/dev/null 2>&1 & [root@dev ~]# jps 35538  Jps 35401 NamesrvStartup 35454 NamesrvStartup [root@dev /soft/rocketmq]# tail -f /var/rocketmq/nameserver-a/logs/rocketmqlogs/namesrv.log [root@dev /soft/rocketmq]# tail -f /var/rocketmq/nameserver-b/logs/rocketmqlogs/namesrv.logCopy the code

Other related instructions:

  • View all parameters of NameServer: mqnamesrv -p

The Broker cluster

  1. Preparing configuration Files

Copy the configuration file from conf/2m-2s-async to the cluster configuration folder.

[root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/2m-2s-async/* ~/rocketmq/cluster/
Copy the code

Take a look at the Broker configuration, which may need to be changed, such as the port number, the associated path, and specifying the connection to the NameServer.

Broker-a. perties, the first Master broker

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-a.properties
#============ Default parameter ============
#The default cluster name. If there are too many brokers in one cluster, a new cluster name can be added to connect its later extended brokers to another cluster.
brokerClusterName=DefaultCluster
#The name of the broker, if slave, is saved as master. If they are both masters, they cannot be consistent.
brokerName=broker-a
#The sequence number of the broker is 0 if it is master. If it is slave, 1, 2, 3 are incremented.
brokerId=0
#The time when expired files are deleted. The default value is 4 am every day. The default expiration time for each file is 72 hours, regardless of whether all messages on the file are consumed.
deleteWhen=04
#The file expiration time is not specified as 72 by default, but changed to 48 in the official configuration file, in hours.
fileReservedTime=48
#The broker role. SYNC_MASTER (synchronous double write), ASYNC_MASTER (asynchronous replication), SLAVE (backup node)
brokerRole=ASYNC_MASTER
#Flush mode: ASYNC_FLUSH (asynchronous flush), SYNC_FLUSH (synchronous flush)
flushDiskType=ASYNC_FLUSH
#Add ============ below ============
#The broker ports. For example, the same machine, whether master or slave, can not be the same.
#A Broker occupies three ports, plus +1 and -2 for port numbers. When installing the same machine, pay attention to setting in increments of at least 4 steps
listenPort=10911
#Specifies the connection NameServer, multiple in English; Space. IP addresses are best replaced with domain name mappings to reduce the hassle of changing machines.NamesrvAddr = 192.168.0.215:9876; 192.168.0.215:9877#The root directory where messages are stored
storePathRootDir=/var/rocketmq/broker-a/store
#CommitLog Storage path
storePathCommitLog=/var/rocketmq/broker-a/store/commitlog
#Home directory, where the primary is used to specify the log files to be used, will read the log files in the conf folder in this directory. If not set, log files in the conf folder of the ROCKETMQ_HOME environment variable are read
rocketmqHome=/root/rocketmq/cluster/broker-a
#Broker MACHINE IP address, which can be set if multiple network cards are used and the IP address needs to be manually specified
#BrokerIP1 = 192.168.0.215Run the Esc :wq command to save the configurationCopy the code

Broker-a-s. perties, Slave nodes of the first Master broker

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-a-s.properties
#============ Default parameter ============
brokerClusterName=DefaultCluster
brokerName=broker-a
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Add ============ below ============ListenPort = 10915 namesrvAddr = 127.0.0.1:9876; 127.0.0.1: storePathRootDir = 9877 / var/rocketmq/broker - a - s/store StorePathCommitLog = / var/rocketmq/broker - a - s/store/commitlog rocketmqHome = / root/rocketmq/cluster/broker - a - s perform save: Esc: wqCopy the code

Broker-b. perties, the second Master broker

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-b.properties
#============ Default parameter ============
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=0
deleteWhen=04
fileReservedTime=48
brokerRole=ASYNC_MASTER
flushDiskType=ASYNC_FLUSH
#Add ============ below ============ListenPort = 10919 namesrvAddr = 127.0.0.1:9876; 127.0.0.1: storePathRootDir = 9877 / var/rocketmq/broker - b/store storePathCommitLog = / var / / store/commitlog rocketmq/broker - b RocketmqHome = / root/rocketmq/cluster/broker - b perform save: Esc: wqCopy the code

Broker-b-s.perties, Slave nodes of the second Master broker

[root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-b-s.properties
#============ Default parameter ============
brokerClusterName=DefaultCluster
brokerName=broker-b
brokerId=1
deleteWhen=04
fileReservedTime=48
brokerRole=SLAVE
flushDiskType=ASYNC_FLUSH
#Add ============ below ============ListenPort = 10923 namesrvAddr = 127.0.0.1:9876; 127.0.0.1: storePathRootDir = 9877 / var/rocketmq/broker - b - s/store StorePathCommitLog = / var/rocketmq/broker - b - s/store/commitlog rocketmqHome = / root/rocketmq/cluster/broker - b - s perform save: Esc: wqCopy the code
  1. createrocketmqHomePath and log configuration files so that each Broker service generates different log files.

Broker – a log

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/broker-a/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_broker.xml ~/rocketmq/cluster/broker-a/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-a/conf/logback_broker.xml <configuration> <property name="user.home" Value ="/var/rocketmq/broker-a" /> Save: Esc :wqCopy the code

Broker – a – s log

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/broker-a-s/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_broker.xml ~/rocketmq/cluster/broker-a-s/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-a-s/conf/logback_broker.xml <configuration> <property name="user.home" Value ="/var/rocketmq/broker-a-s" /> Save the configuration: Esc :wqCopy the code

Broker – b logs

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/broker-b/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_broker.xml ~/rocketmq/cluster/broker-b/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-b/conf/logback_broker.xml <configuration> <property name="user.home" Value ="/var/rocketmq/broker-b" /> Save: Esc :wqCopy the code

Broker – b – s log

[root@dev /soft/rocketmq]# mkdir -p ~/rocketmq/cluster/broker-b-s/conf [root@dev /soft/rocketmq]# cp ${ROCKETMQ_HOME}/conf/logback_broker.xml ~/rocketmq/cluster/broker-b-s/conf/ [root@dev /soft/rocketmq]# vi ~/rocketmq/cluster/broker-b-s/conf/logback_broker.xml <configuration> <property name="user.home" Value ="/var/rocketmq/broker-b-s" /> Save the configuration: Esc :wqCopy the code
  1. Start the
[root@dev /soft/rocketmq]# nohup mqbroker -c ~/rocketmq/cluster/broker-a.properties >/dev/null 2>&1 & [root@dev /soft/rocketmq]# nohup mqbroker -c ~/rocketmq/cluster/broker-a-s.properties >/dev/null 2>&1 & [root@dev /soft/rocketmq]#  nohup mqbroker -c ~/rocketmq/cluster/broker-b.properties >/dev/null 2>&1 & [root@dev /soft/rocketmq]# nohup mqbroker -c  ~/rocketmq/cluster/broker-b-s.properties >/dev/null 2>&1 & [root@dev /soft/rocketmq]# tail -f /var/rocketmq/broker-a/logs/rocketmqlogs/broker.log [root@dev /soft/rocketmq]# tail -f /var/rocketmq/broker-a-s/logs/rocketmqlogs/broker.log [root@dev /soft/rocketmq]# tail -f /var/rocketmq/broker-b/logs/rocketmqlogs/broker.log [root@dev /soft/rocketmq]# tail -f /var/rocketmq/broker-b-s/logs/rocketmqlogs/broker.logCopy the code

Other related instructions:

  • View the main or all of the Broker parameters: mqbroker-m or mqbroker-p

  • Mqadmin clusterList -n localhost:9876 mqadmin clusterList -n localhost:9876

Vi. Service starts automatically

  1. How NameServer and Broker are started at the same time
[root@dev /soft/rocketmq]# cd /etc/init.d/
[root@dev /etc/init.d]# vi rocketmq
#! /bin/sh
# chkconfig: 345 85 15
# description: service forRocketmq 4.6.0
# processname: rocketmqROCKETMQ_DIR="/soft/ RocketMQ "case "$1" in start) echo "Starting RocketMQ Server $ROCKETMQ_DIR/bin/mqnamesrv >/dev/null 2>&1 & echo "The Name Server boot success..." nohup sh $ROCKETMQ_DIR/bin/mqbroker -c $ROCKETMQ_DIR/conf/broker.conf >/dev/null 2>&1 & echo "The Broker boot success..." echo "RocketMQ started" ;; stop) echo "Stopping RocketMQ Server" sh $ROCKETMQ_DIR/bin/mqshutdown broker sleep 1 sh $ROCKETMQ_DIR/bin/mqshutdown namesrv echo "RocketMQ stoped!" ;; restart) echo "Restarting RocketMQ Server" $0 stop sleep 5 $0 start ;; *) echo "Usage: $0 {start | stop | restart}" exit 1 esac perform save:  Esc :wq [root@dev /etc/init.d]# chmod 755 rocketmq [root@dev /etc/init.d]# chkconfig --add rocketmq [root@dev /etc/init.d]# chkconfig rocketmq onCopy the code

Other related instructions:

  • Start: service Rocketmq start
  • Stop: service Rocketmq stop
  • Restart: service RocketMQ restart
  • To disable automatic startup: chkconfig RocketMQ off
  • Delete self-booting: chkconfig –del RocketMQ
  • Displays all current Java processes: JPS
  1. How NameServer and Broker are started separately

NameServer

[root@dev /soft/rocketmq]# cd /etc/init.d/
[root@dev /etc/init.d]# vi rocketmq-nameserver-a
#! /bin/sh
# chkconfig: 345 85 15
# description: service forRocketmq 4.6.0
# processname: rocketmq-nameserver-aROCKETMQ_DIR="/soft/rocketmq" case "$1" in start) echo "Starting RocketMQ NameServer" nohup sh $ROCKETMQ_DIR/bin/mqnamesrv -c /root/rocketmq/cluster/nameserver-a.properties >/dev/null 2>&1 & echo "RocketMQ NameServer started" ;; stop) echo "Stopping RocketMQ NameServer" sh $ROCKETMQ_DIR/bin/mqshutdown namesrv echo "RocketMQ NameServer stoped!" ;; restart) echo "Restarting RocketMQ NameServer" $0 stop sleep 5 $0 start ;; *) echo "Usage: $0 {start | stop | restart}" exit 1 esac perform save:  Esc :wq [root@dev /etc/init.d]# chmod 755 rocketmq-nameserver-a [root@dev /etc/init.d]# chkconfig --add rocketmq-nameserver-a [root@dev /etc/init.d]# chkconfig rocketmq-nameserver-a onCopy the code

Broker

[root@dev /soft/rocketmq]# cd /etc/init.d/
[root@dev /etc/init.d]# vi rocketmq-broker-a
#! /bin/sh
# chkconfig: 345 85 15
# description: service forRocketmq 4.6.0
# processname: rocketmq-broker-aROCKETMQ_DIR="/soft/rocketmq" case "$1" in start) echo "Starting RocketMQ Broker" nohup sh $ROCKETMQ_DIR/bin/mqbroker -c  /root/rocketmq/cluster/broker-a.properties >/dev/null 2>&1 & echo "RocketMQ Broker started" ;; stop) echo "Stopping RocketMQ Broker" sh $ROCKETMQ_DIR/bin/mqshutdown broker echo "RocketMQ Broker stoped!" ;; restart) echo "Restarting RocketMQ Broker" $0 stop sleep 5 $0 start ;; *) echo "Usage: $0 {start | stop | restart}" exit 1 esac perform save:  Esc :wq [root@dev /etc/init.d]# chmod 755 rocketmq-broker-a [root@dev /etc/init.d]# chkconfig --add rocketmq-broker-a [root@dev /etc/init.d]# chkconfig rocketmq-broker-a onCopy the code

If multiple nodes are installed on the same platform, the stopping script will stop all nodes of the same type. If you want to close it separately, you need to extend some of our custom close scripts on the basis of the official script. (As an aside, you can guess from the script that it is officially not recommended to deploy multiple nodes on a single machine.)

Instead of grep Java, replace it with grep $2.properties

[root@dev /soft/rocketmq/bin]# cp mqshutdown mqshutdownsingle
[root@dev /soft/rocketmq/bin]# vi mqshutdownsingle
#! /bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
#contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
#the License. You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.case $1 in broker) pid=`ps ax | grep -i 'org.apache.rocketmq.broker.BrokerStartup' |grep $2.properties | grep -v grep | awk '{print $1}'` if [ -z "$pid" ] ; then echo "No mqbroker running." exit -1; fi echo "The mqbroker(${pid}) is running..." kill ${pid} echo "Send shutdown request to mqbroker(${pid}) OK" ;; namesrv) pid=`ps ax | grep -i 'org.apache.rocketmq.namesrv.NamesrvStartup' |grep $2.properties | grep -v grep | awk '{print $1}'` if [ -z "$pid" ] ; then echo "No mqnamesrv running." exit -1; fi echo "The mqnamesrv(${pid}) is running..." kill ${pid} echo "Send shutdown request to mqnamesrv(${pid}) OK" ;; *) echo "Useage: mqshutdown broker | namesrv" esac perform save: Esc: wqCopy the code

The stop script adds a parameter specifying the node name

[root@dev /soft/rocketmq]# mqshutdownsingle namesrv nameserver-a
[root@dev /soft/rocketmq]# mqshutdownsingle broker broker-a
Copy the code

Vii. Expanded content

1. Broker configuration parameters:

Message store parameter (MessageStoreConfig source class name) Key name Key/description
maxMessageSize Maximum message size, default 1024*1024*4 (4M), in bytes B
mappedFileSizeCommitLog CommitLog Size of each file, default 1024 x 1024 x 10241(1G), unit: byte B
mappedFileSizeConsumeQueue ConsumeQueue Specifies the default number of files to be stored. The default value is 300,000 x 20(30W). 20 is the storage unit
flushIntervalConsumeQueue ConsumeQueue Indicates the interval between flushing disks. The default value is 1000 milliseconds

2. Thinking about not losing information

Without losing messages, and with performance in mind, I came to this conclusion:

  1. The master must flushDiskType=SYNC_FLUSH to ensure that messages are flushed on the hard disk.

  2. BrokerRole =ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole=ASYNC_MASTER brokerRole

  3. The slave flushing mode can be considered as asynchronous flushing, since it is mainly used for backup and there are multiple slave siblings. With sync, it feels like a waste of performance.

    But theory is theory, and this is purely empirical. If you want to fully, also need to see more source code, combat, just upgrade play strange.

3. The mqadmin instructions

  1. Query the usage of instructions
  • View all commands

    [root@dev ~]# mqadmin The most commonly used mqadmin commands are: updateTopic Update or create topic deleteTopic Delete topic from broker and NameServer. updateSubGroup Update or create subscription group deleteSubGroup Delete subscription group from broker. updateBrokerConfig Update broker's config .Copy the code
  • See how each directive is used, using updateTopic as an example (the parameters used should be easy to understand).

    [root@dev ~]# mqadmin help updateTopic usage: mqadmin updateTopic -b <arg> | -c <arg> [-h] [-n <arg>] [-o <arg>] [-p <arg>] [-r <arg>] [-s <arg>] -t <arg> [-u <arg>] [-w <arg>] -b,--brokerAddr <arg> create topic to which broker -c,--clusterName <arg> create topic to which cluster -h,--help Print help -n,--namesrvAddr <arg> Name server address list, eg: 192.168.0.1:9876; 192.168.0.2:9876 - o - order < arg > set topic 's order (true | false) - p - perm < arg > set topic' s permission (2 | | 4. 6). intro[2:W 4:R;  6:RW] -r,--readQueueNums <arg> set read queue nums -s,--hasUnitSub <arg> has unit sub (true|false) -t,--topic <arg> topic name -u,--unit <arg> is unit topic (true|false) -w,--writeQueueNums <arg> set write queue numsCopy the code
  1. Memorandum of Common Instructions
#Create a message subject. Basically CNT,BNT...
#Why command creation? Still, it is recommended to disable the automatic theme creation function, in case the development in the project creates themes randomly, resulting in final maintenance difficulties.
#By specifying a cluster
[root@dev ~]# mqadmin updateTopic -c DefaultCluster -n localhost:9876 -t xx-topic
#By specifying the broker
[root@dev ~]# mqadmin updateTopic -b localhost:10911 -n localhost:9876 -t xx-topic
#Delete the topic
[root@dev ~]# mqadmin deleteTopic -c DefaultCluster -n localhost:9876 -t xx-topic
#Check the topic
[root@dev ~]# mqadmin topicRoute -n localhost:9876 -t xx-topic
Copy the code

Appendix:

  • Official documents:
    • Rocketmq.apache.org/docs/quick-…
    • Rocketmq.apache.org/docs/rmq-de…
    • Github.com/apache/rock…
  • Information Retrieval:
    • Blog.csdn.net/trycatchme/…
    • Blog.csdn.net/leexide/art…
    • Blog.csdn.net/zhaominpro/…