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

RocketMQ use tutorial related series of directories


Section 1: Server preparation

Install two VMS, one master and one slave.

IP hostname mastername
192.168.88.133 rocketmq-nameserver2 rocketmq-master1-slave1
192.168.88.131 rocketmq-nameserver1 rocketmq-master1

Install virtual machine portal –>

Section 2: Installation and Configuration (Salve)

RocketMQ has already been installed on one server, so the Salve server (192.168.88.133) only needs to install slave nodes.

Note: If you don’t know how rocketMQ is installed, portal –> Chapter 1: rocketMQ Installation

Create a directory on the Salve server where the installation files are stored

mkdir server
Copy the code

Copy the installation files to the Salve server and unzip the installation

SCP rocketmq - all - 4.5.1 - bin - release. Zip 192.168.88.133: / usr/local/server /Copy the code

Unzip rocketmq - all - 4.5.1 - bin - release. ZipCopy the code

 

Mkdir mq mv rocketmq-all-4.5.1-bin-release MQ/rocketMQCopy 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

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 'new string original string s # # # g' replacement file sed -i 's # # ${user. Home} / usr/local/server/mq/rocketmq# g' *. XMLCopy 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 3: Configuration

Configure hosts

Configure the mapping between addresses and IP addresses in the host file

Add the following mapping to the /etc/hosts file of the two hosts

Vim /etc/hosts 192.168.88.131 Rocketmq-nameserver1 192.168.88.131 Rocketmq-master1 192.168.88.133 Rocketmq-nameserver2 192.168.88.133 rocketmq master1 -- slave1Copy the code

After the configuration is complete, restart the NIC

systemctl restart network
Copy the code

Rocketmq 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

The JDK installation

Centos installation open-jdk8–> portal

Modify the master server configuration

Host; 192.168.88.131

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

A master-slave configuration

Host: 192.168.88.131

cd /usr/local/server/mq/rocketmq/conf
cd 2m-2s-async/
vim broker-a.properties
Copy the code

 

BrokerName =broker- A #0 = Master >0 = Slave brokerId=0 #nameServer address, semicolon split namesrvAddr= RocketMQ-Nameserver1:9876; Rocketmq-nameserver2:9876 # Create a topic that does not exist on the server. DefaultTopicQueueNums =4 # 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 = / 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 replication Master #- SYNC_MASTER Synchronous double write Master #- SLAVE brokerRole=ASYNC_MASTER # Flush ASYNC_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

Adjustments:

BrokerClusterName = xuZHU_cluster brokerClusterName= brokerClusterName BrokerRole to determine who is master and who is from brokerName=broker-a #nameServer address namesrvAddr= RocketMQ-Nameserver1:9876; Rocketmx-nameserver 2:9876 #brokerID 0 is master, >0 is slave brokerID =0 # Master, Asynchronous copy brokerRole=ASYNC_MASTER # flush mode, FlushDiskType =ASYNC_FLUSHCopy the code

From machine: 192.168.88.133

Modify the broker – a – supachai panitchpakdi roperties

vim broker-a-s.properties
Copy the code

Modify, save

BrokerName =broker- A #0 = Master >0 = Slave brokerId=1 #nameServer address, semicolon split namesrvAddr= RocketMQ-Nameserver1:9876; Rocketmq-nameserver2:9876 # Create a topic that does not exist on the server. DefaultTopicQueueNums =4 # 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 = / 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 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

Adjustments:

BrokerClusterName = xuZHU_cluster brokerClusterName= brokerClusterName BrokerRole to determine who is master and who is from brokerName=broker-a #nameServer address namesrvAddr= RocketMQ-Nameserver1:9876; Rocketmq-nameserver 2:9876 #brokerID 0 is master, >0 is brokerID =1 # Role is brokerRole=SLAVE # Flush mode, flushDiskType=ASYNC_FLUSHCopy the code

Section 4: Start namesRV and master/slave Brokers

The master and slave hosts go to the bin directory

Start namesRV of master and slave hosts

nohup sh mqnamesrv > /dev/null 2>&1 &
Copy the code

Start the broker for the master host

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

Start the broker for the slave host again

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

Section 5: Viewing cluster monitoring platform

Start the

Check whether docker container Rocketmq-console-ng exists in advance. If so, delete it first

For those of you who are not familiar with Docker, portal -> Docker is used to manipulate container commands

If the RocketMQ-Console image has not been downloaded, portal –>RocketMQ cluster monitoring platform RocketMQ-Console is set up

Docker run - e "JAVA_OPTS = - Drocketmq. Namesrv. Addr = 192.168.88.131:9876; 192.168.88.133:9876 - Dcom. Rocketmq. SendMessageWithVIPChannel = false "-p 8080-8080 - t - name rocketmq - the console - ng styletang/rocketmq-console-ngCopy the code