“This is the 25th day of my participation in the Gwen Challenge in November. See details: The Last Gwen Challenge in 2021”

The most commonly used MQ is divided into three types: RabbitMQ, RocketMQ and Kafka. This article mainly introduces the installation of RocketMQ single version, to help small white quickly start, can quickly start RocketMQ. In order to quickly get started with RocketMQ, you can install a stand-alone version of RocketMQ on the VIRTUAL machine for learning and getting started. In the following steps, I will record my own installation for future reference. The standalone VERSION of MQ is not allowed in the production environment. RocketMQ supports cluster installation and is installed in cluster mode online. A brief description of several components of MQ before installation:

  • NameServer: Similar to ZK, provides a registration service center that provides lightweight route registration services for brokers
  • Broker: The core component that actually processes, stores, and forwards messages
  • Produer: Business system maintenance, responsible for sending MQ messages (producers)
  • Consumer: Business system maintenance, responsible for the consumption of MQ messages (consumers)

To install NameServer and Broker, start NameServer and then Broker.

Environment to prepare

  • Centos 7 One VM
  • JDK 1.8 environment installation
  • RocketMQ installation package Release package

Download address: rocketmq.apache.org/docs/quick-…

  • RocketMQ interface console

Since consoles are not officially available, the open source community has a console interface gitcode.net/mirrors/apa…

RocketMQ installation

  • Decompress rocketmq-all-4.9.2-bin-release.zip and move it to: /usr/local/rocketMQ, then go to /usr/local/RocketMQ to start

Start the NameServer

To start NameServer, use ROCKETMQHOME/bin to start the NameServer service. RocketMQ starts NameServer on a virtual machine. By default, the configuration file has 4G memory. You need to reduce the memory size of the JVM or it won’t start. To start the NameServer service, modify the MQNamesrv in ROCKETMQ_HOME/bin. However, we start the NameServer service on a VIRTUAL machine. RocketMQ starts NameServer with the default configuration file memory of 4G. Modify the mqNamesrv in the ROCKETMQHOME/bin directory to start the NameServer service. However, we started the NameServer service on the VIRTUAL machine. RocketMQ starts NameServer with the default configuration file memory of 4G, so we need to reduce the MEMORY of the JVM, otherwise it will not start. Example Modify the JAVA_OPT parameter in the ROCKETMQ_HOME/bin/runserver.sh file

JAVA_OPT=”${JAVA_OPT} -server -Xms512m -Xmx512m -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m”

Start command:

cd /usr/local/rocketmq
nohup bin/mqnamesrv &
Copy the code

The startup log is printed to nohup.out in the current folder

Start the Broker

The process of starting the Broker is the same as NameServer. You need to start the MQBroker in the ROCKETMQHOME/bin directory. During the virtual machine installation, you also need to reduce the MEMORY size of the Jvm. Modify the MQBroker in ROCKETMQ_HOME/bin to reduce the MEMORY size of the Jvm during vm installation. The default memory size of the Broker is 8GB. Modify the MQBroker in the ROCKETMQHOME/bin directory to reduce the MEMORY size of the Jvm when the VM is installed. The default memory size of the Broker is 8GB. Modify the JAVA_OPT parameter in the ROCKETMQ_HOME/bin/runbroker.sh file

JAVA_OPT=”${JAVA_OPT} -server -Xms512m -Xmx512m -Xmx512m -Xmn256m”

Start command:

During startup, you must specify the startup configuration file; otherwise, the parameter: broker.conf does not take effect

cd /usr/local/rocketmq
nohup bin/mqbroker -c conf/broker.conf  &  
Copy the code
  • Installation console

Since the console downloads the source code, it needs to be packaged into jars using the Maven command

mvn clean package -Dmaven.test.skip=true

Upload rocketmq-console-ng-1.0.0.jar to /usr/local/rocketmq:

cd /usr/local/rocketmq
nohup  java -jar rocketmq-console-ng1.01..jar &
Copy the code

After the VM is successfully started, the VM can be accessed using IP address 8080If download the source code, is not in the configuration file (rocketmq. Config. NamesrvAddr) of the specified NameServer addresses, you need to in a virtual machine environment configuration NameServer address

#if this value is empty,use env value rocketmq.config.namesrvAddr NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876 rocketmq.config.namesrvAddr=

Here, you configure the NAMESRV_ADDR address in the virtual machine environment, append the following parameters to the /etc/profile file, and then validate the configuration file

#rocketmq 
export NAMESRV_ADDR=localhost:9876
Copy the code

source /etc/profile

Restart Rocketmq-console-ng

Service validation

View port use startup

netstat -ntlp |grep java
Copy the code

You can see that a bunch of ports are started

  • 9876: Port started by NameServer to register the address
  • 8080: Console startup port for interface access
  • 1099/10911/10912: Internal communication port of the Broker

Use producer tools to send messages

Since the RocketMQ configuration does not allow Topic creation when in use, you need to add a configuration at the end of $ROCKETMQ_HOME/conf/broker.conf to allow Topic creation automatically

autoCreateTopicEnable=true

Run bin/tools.sh to send messages. By default, 1000 messages are sent

cd /usr/local/rocketmq/
bin/tools.sh org.apache.rocketmq.example.quickstart.Producer 
Copy the code

Use consumer tools to receive messages

Run bin/tools.sh to receive messages

cd /usr/local/rocketmq/
bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Copy the code

The RocketMQ standalone version is installed here

Stop the RocketMQ service

Close the NameServer

cd /usr/local/rocketmq/
sh bin/mqshutdown namesrv 
Copy the code

Close the Broker

cd /usr/local/rocketmq/
sh bin/mqshutdown broker
Copy the code

Close the console

Find the PID of port 8080 and run the kill -9 command to kill it

 netstat -ntlp |grep 8080
 kill 9 - 1836
 
Copy the code