Technical work, should be praised and then see, form a habitCopy the code

RocketMQ use tutorial related series of directories


Section one: Download RocketMQ

Demo: RocketMQ version: 4.5.1

Download address

HTTPS: / / archive.apache.org/dist/rocketmq/4.5.1/rocketmq-all-4.5.1-bin-release.zip

Environmental requirements

  • On a system
  • JDK1.8(64位)
  • Maven 3.2.x is required to install the source code

Section two: Install RocketMQ

Install as a binary package

Upload the downloaded installation package to the server

Decompress the installation package

Check whether unzip is installed

unzip
Copy the code

The following picture is installed

The following picture is not installed

Install command

yum install unzip
Copy the code

Decompress the installation package and move it to the specified directory

Create the corresponding directory/usr/local/server/rocketmq

 cd /usr/local/
mkdir server
cd server/
mkdir rocketmq
Copy the code

Unzip rocketmq - all - 4.5.1 - bin - the zip - d/usr/local/server/rocketmqCopy the code

Change the file name

CD/usr/local/server/rocketmq/mv rocketmq - all - 4.5.1 - bin - release/rocketmq CD. Mv RocketMQ/mq # two RocketMQ folders appear, change the last folder to MQCopy the code

Create the RocketMQ storage directory

The existing directory structure looks like this

Creating a Storage Directory

mkdir logs
mkdir store
cd store
mkdir commitlog
mkdir consumequeue
mkdir index
Copy the code

Description of the newly created folder

  • Logs: Directory for storing logs
  • Store: indicates the directory where data files are stored
  • Commitlog: Stores message information
  • Consumequeue, index: Stores the index data of the message

RocketMQ directory introduction

  • Bin: startup scripts, including shell scripts and CMD scripts
  • Conf: instance configuration files, including broker configuration files and logback configuration files
  • Lib: Depends on jar packages, including Netty, Commons-lang, FastJSON, etc

Conf directory description

  • 2m-2s-async: 2 primary and 2 secondary async
  • 2m-2s-sync: 2 Master 2 slave – synchronization
  • 2m-noslave: 2 The master is unavailable

Here is a demonstration of single-node configuration: just modify the 2M-2s-Async configuration implementation first.

cd 2m-2s-async
Copy the code

Broker-a. Broker-b. Broker-b. Broker-b. Broker-b : secondary configuration file of single node BCopy the code

Section 3: Single-node configuration

Configure hosts

vim /etc/hosts
Copy the code

Add nameserver and Broker

# Broker 192.168.88.131 Rocketmq-master1Copy the code

After the configuration is complete, restart the NIC

systemctl restart network
Copy the code

Go to the CONF configuration folder

cd conf
Copy the code

Enter 2 m – 2 s – async

cd 2m-2s-async
Copy the code

Modify the broker – Amy polumbo roperties

vim broker-a.properties
Copy the code

Overwrite broker-a. perties with the following configuration and save

 

# # 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 = Slave brokerId=0 #nameServer address, semicolon split namesrvAddr= RocketMQ-Nameserver1: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 brokerIP1 = 192.168.88.131 listenPort = 10911 # delete files point in time, Default 4 am deleteWhen=04 # 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 = / usr/local/server/mq/rocketmq/store # commitLog storage paths StorePathCommitLog = / usr/local/server/mq queue storage/rocketmq/store/commitlog # consumption path storage paths StorePathConsumeQueue = / usr/local/server/mq/rocketmq/store/consumequeue # message index storage paths StorePathIndex = / usr/local/server/mq/rocketmq/store/index # checkpoint file storage path StoreCheckpoint = / usr/local/server/mq/rocketmq/store/checkpoint # abort file storage path AbortFile = / usr/local/server/mq/rocketmq/store / # 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

Note: The path in the configuration must be the same as the path of the newly created folder, if there is a custom change

Changing a Log Path

Go to the conf directory and replace ${user.home} in all XML files to ensure that the log path is correct

Grammar:

Sed -i batch replacement

Sed -i 's# original string # new string #g' replace the fileCopy the code
sed -i 's#${user.home}#/usr/local/server/mq/rocketmq#g' *.xml
Copy the code

The replacement succeeded

Modify runbroker. Sh

Adjust the memory size (for demonstration purposes only, the actual memory size depends on the production environment)

cd ..
cd bin/
vim runbroker.sh
Copy the code

 

Adjust to 1 g

Modify the runserver then executes. Sh

Adjust the memory size (for demonstration purposes only, the actual memory size depends on the production environment)

vim runserver.sh
Copy the code

Section 4: Environment variable configuration

vim /etc/profile
Copy the code

Add the following command at the end of the profile file

#set rocketmq
ROCKETMQ_HOME=/usr/local/server/mq/rocketmq/
PATH=$PATH:$ROCKETMQ_HOME/bin
export ROCKETMQ_HOME PATH
Copy the code

Input: wq! Save and exit to make the configuration take effect immediately:

source /etc/profile
Copy the code

Start the namesrv

nohup sh mqnamesrv &
Copy the code

The service failed to start. Check the log

cd /usr/local/server/mq/rocketmq/bin/
cat nobup.out
Copy the code

The reason is that the input command is written

## nohup sh mqnamesr& ## nohup sh mqnamesr&Copy the code

The input

ohup sh mqnamesrv &
Copy the code

Then press enter

View through JPS

Start the broker

 nohup sh mqbroker -c /usr/local/server/mq/rocketmq/conf/2m-2s-async/broker-a.properties > /dev/null 2>&1 &
Copy the code

Note:

>/dev/null 2>&1

www.cnblogs.com/ultranms/p/…

Close namesrv and Broker

None example Disable the Namesrv service

Enter bin sh mqshutdown namesrvCopy the code

Closing the Broker service

sh mqshutdown broker
Copy the code

Through the JPS verification

Section 5: Firewall configuration

The host machine requires remote access to the ROCketMQ service and Web service of the VIRTUAL machine, and the associated port number needs to be opened. The simple and crude way is to turn off the firewall directly

Firewall -cmd --state # Disable the firewall startup systemctl disable firewalld.serviceCopy the code

Or for security, only specific port numbers are open. RocketMQ uses three ports by default: 9876, 10911, and 11011. If the firewall is not closed, then the firewall must open these ports:

  • Nameserver uses port 9876 by default
  • Master uses port 10911 by default
  • Slave uses port 11011 by default

Run the following command:

Firewall-cmd --remove-port=9876/ TCP --permanent # Open master default port firewall-cmd --remove-port=10911/ TCP Firewall-cmd --remove-port=11011/ TCP --permanent # restart firewall firewall-cmd --reloadCopy the code

Section 6: RocketMQ Architecture introduction

  • Producer: the sender of messages; Example: sender
  • Consumer: message receiver; Example: recipient
  • Broker: Holds and transmits messages. Example: Post office
  • NameServer: Manage Broker; Example: the administration of various post offices
  • Topic: Distinguish the types of messages; A sender can send messages to one or more topics; The recipient of a message can subscribe to one or more Topic messages
  • Message Queue: equivalent to a Topic partition; Used to send and receive messages in parallel