This is the 21st day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

RocketMQ is a distributed, queue-model messaging middleware with the following features

  • 1, can ensure strict message order
  • 2, provide rich message pull mode
  • 3. Efficient subscriber level expansion capability
  • 4. Real-time message subscription mechanism
  • 500 million message accumulation capacity

Build a two-node RocketM

Environmental Background:

  • Vm: VMware12

  • Operating system: centos6.5

  • Memory: 1 GB RAM

  • Hard disk: 20 GB ROM

Under the WMWare virtual machine implementation, to achieve two IP and resource service host, IP is 192.168.1.12 respectively, 192.168.1.13, respectively in the two machines in the hosts file to add.

Vim /etc/hosts # rocketMQ 192.168.1.12 Rocketmq-nameserver1 192.168.1.12 Rocketmq-master1 192.168.1.13 Rocketmq - nameserver2 192.168.1.13 rocketmq - master2Copy the code

Download and install RocketMQ

Run the rz command to upload the alibaba-rocketmq-x.x.x.tar.gz file to the two machines, or download it online directly from the official website.

Unzip RocketMq to /usr/local:

root@localhost local]#tar -zxvf alibaba-rocketmq-x.x.x.tar.gz -C /usr/local/
Copy the code

Establish alibaba-RocketMQ to RocketMQ soft connection as follows:

[root@localhost local]#ln -s alibaba-rocketmq rocketmq
Copy the code

Create the path associated with the RocketMQ store

[root@localhost local]# mkdir /usr/local/rocketmq/store [root@localhost local]# mkdir /usr/local/rocketmq/store/commitlog [root@localhost local]# mkdir /usr/local/rocketmq/store/consumequeue [root@localhost  local]# mkdir /usr/local/rocketmq/store/indexCopy the code

Configure broker-A. perties and broker-B. perties files for both machines respectively

Adjust the configuration of the associated RocketMQ broker

[root @ localhost local] # vim/usr/local/rocketmq/conf / 2 m - noslave/broker - Amy polumbo roperties # belongs to the cluster name BrokerClusterName = Rocketmq-cluster # Broker name, Note 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/rocketmq/store # commitLog storage paths StorePathCommitLog = / usr/local/rocketmq queue storage/store/commitlog # consumption path storage paths StorePathConsumeQueue = / usr/local/rocketmq/store/consumequeue # message index storage paths storePathIndex = / usr/local/rocketmq/store/index StoreCheckpoint # checkpoint file storage path = / usr/local/rocketmq/store/checkpoint # abort file storage path AbortFile = / usr/local/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

Start the nameserver

[root@singlenode rocketmq]# cd /usr/local/rocketmq/bin/
[root@singlenode bin]# nohup sh mqnamesrv &
Copy the code

Start the broker

cd /usr/local/rocketmq/bin
[root@singlenode bin]# nohup sh mqbroker -c /usr/local/rocketmq/conf/2m-noslave/broker-a.properties >/dev/null 2> &1 &

[root@singlenode bin]# tail -f -n 500 /usr/local/rocketmq/logs/rocketmqlogs/broker.log
Copy the code

Deploy the RocketMq management interface

Start by downloading Rocketmq-console. war and tomcat (github.com/apache/rock…

Modify the config.properties file

Rocketmq. Namesrv. Addr = 192.168.1.12:9876; 192.168.1.13:9876 throwDone = trueCopy the code

Start the Tomcat, visit http://192.168.1.128:8080/rocketmq-console

Setting environment variables:

Export NAMESRV_ADDR = 192.168.169.128:9876 \; 192.168.169.129:9876

Run tests:

bash tools.sh com.alibaba.rocketmq.example.quickstart.Producer
bash tools.sh com.alibaba.rocketmq.example.quickstart.Consumer
Copy the code

Disabling the Firewall

[root@singlenode bin]#service iptables status
[root@singlenode bin]#service iptables stop
Copy the code

If centos7 or above is used

systemctl stop firewalld.service
Copy the code

The role of RocketMq

  • producer

  • consumer

  • Broker

  • NameServer

Create a topic
  • The broker address b
  • C Cluster name
  • N Nameserver Address list
  • T the name of the topic
UpdateTopic -b 192.168.0.1:10911 -c rocketmq-cluster-n 192.168.0.1:9876; 192.168.0.2: order - 9876 - t topicCopy the code
Delete the topic
DeleteTopic -c rocketmq-cluster-n 192.168.0.1:9876; 192.168.0.2: order - 9876 - t topicCopy the code
Create or modify a subscription group

Subscription Group name

UpdateSubGroup -b 192.168.0.1:10911 -c rocketmq-cluster -g subGroupName -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code
Deleting a Subscription Group
DeleteSubGroup -b 192.168.0.1:10911 -c rocketmq-cluster -g subGroupName -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

Update broker configuration

Some profile brokers can be dynamically modified while running. -k Broker key -v value of the profile

UpdateBrokerConfig -b 192.168.0.1:10911 -c rocketmq-cluster-n 192.168.0.1:9876; 192.168.0.2:9876 -k deleteWhen -v 05Copy the code

Update topic read and write permissions

UpdateTopicPerm -b 192.168.0.1:10911 -c rocketmq-cluster-n 192.168.0.1:9876; 192.168.0.2: order - 9876 - t topicCopy the code

Query topic routing information

TopicRoute -b 192.168.0.1:10911 -c rocketmq-cluster-n 192.168.0.1:9876; 192.168.0.2: order - 9876 - t topicCopy the code

View topic routing information

TopicList -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

View topic status statistics

TopicStats -t order_top_topic-n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

Query messages by time

PrintMsg -t order_topic -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

Query messages by Id

QueryMsgById -i msgId -n -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

Viewing Cluster Information

ClusterList -n 192.168.0.1:9876; 192.168.0.2:9876Copy the code

Additional instructions

If the Chinese language package is not installed, garbled characters appear, you can pass

[root@localhost local]# yum groupinstall chinese-support
Copy the code

You can modify the log configuration files on both machines and replace ${user.home} in all XML files in the conf directory with /usr/local/rocketmq

[root@localhost rocketmq]# mkdir -p /usr/local/rocketmq/logs
[root@localhost rocketmq]# cd /usr/local/rocketmq/conf && sed -i 's#${user.home}#/usr/local/rocketmq#g' *.xml 
Copy the code

Modify the RocketMQ startup script for each machine

[root@localhost rocketmq]# vim /usr/local/rocketmq/bin/runbroker.sh 
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn800g -XX:PermSize=128m -XX:MaxPermSize=320m"
JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:+DisableExplicitGC"
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${HOME}/rmq_bk_gc.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow"
JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib"
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
Copy the code