Preface
The low version of Ali's fastjson (<=1.2.68) was revealed to have security vulnerabilities, and RocketMQ 4.7.0 uses fastjson 1.2.62, so it is necessary to upgrade RocketMQ to RocketMQ 4.7.1 (fastjson 1.2.69).
This article describes the process of installing RocketMQ 4.7.1 on CentOS7, which is only used as a development and test environment:
- Stand-alone deployment, both Name Server and Broker are installed on one server;
- Reduced the default JVM size of RocketMQ;
- No self-starting and daemon processes are set.
Installation process
OpenJDK 8 has been installed and set up on the server JAVA_HOME
.
Download and unzip RocketMQ
Find the link to download RocketMQ 4.7.1 on RocketMQ official website, download and decompress RocketMQ:
# 下载
wget http://ftp.cuhk.edu.hk/pub/packages/apache.org/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip
# 解压
unzip rocketmq-all-4.7.1-bin-release.zip
# 安装到/usr/local/rocketmq
mv rocketmq-all-4.7.1-bin-release /usr/local
ln -s /usr/local/rocketmq-all-4.7.1-bin-release /usr/local/rocketmq
Reduce the JVM size of RocketMQ
The default JVM of RocketMQ is too large to be used in the development and test environment, and the JVM size needs to be reduced.
In the installation directory of RocketMQ (/usr/local/rocketmq in this example), find the JVM parameter settings in the sh script:
find . -name '*.sh' | xargs egrep 'Xms'
The JVM parameters of the following sh scripts need to be modified:
bin/runserver.sh
bin/runbroker.sh
bin/tools.sh
Remember to back up the corresponding script before modification. The specific JVM size is set according to the actual situation.
- bin/runserver.sh
before fixing:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
After modification:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
- bin/runserver.sh
before fixing:
JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
After modification:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
-Before bin/tools.sh is
modified:
JAVA_OPT="${JAVA_OPT} -server -Xms1g -Xmx1g -Xmn256m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
After modification:
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=128m"
Start Name Server
# 后台启动
nohup sh bin/mqnamesrv >/dev/null 2>&1 &
The default port of Name Server is 9876. Run sh bin/mqnamesrv -p to view the configuration items of Name Server, and start by specifying the configuration file by -c namesrv.conf;
The default log path of RocketMQ is `~/logs/rocketmqlogs/``;
You can save the startup Name Server command as a script to facilitate the next startup.
Start Broker
You need to specify the Name Server you want to connect to when starting Broker:
# 后台启动
nohup sh bin/mqbroker -n localhost:9876 >/dev/null 2>&1 &
You can save the startup Broker command as a script to facilitate the next startup.
View RocketMQ process
ps -ef | grep -v grep | grep rocketmq
Test RocketMQ
Test sending and receiving messages
Use RocketMQ's own message producer and consumer examples to test sending and receiving messages:
export NAMESRV_ADDR=localhost:9876
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
Close RocketMQ
Close Broker
sh bin/mqshutdown broker
You can save the Broker shutdown command as a script to facilitate the next shutdown.
Close Name Server
sh bin/mqshutdown namesrv
Broker needs to be closed before closing Name Server;
You can save the command to close the Name Server as a script to facilitate the next shutdown.
Modify the port of the Name Server
The default port of RocketMQ Name Server is 9876. You can modify the port of Name Server by the following methods:
- Add a new Name Server configuration file namesrv.conf, save the content:
listenPort=10076
- Specify the configuration file when starting the Name Server:
nohup sh bin/mqnamesrv -c namesrv.conf >/dev/null 2>&1 &
- View the RocketMQ process:
ps -ef | grep rocketmq
- Check the port number of RocketMQ Name Server:
netstat -tnlp | grep <nameserver_pid>
- Broker needs to specify the new Name Server address (port) after modification.
Install RocketMQ console
Clone the rocketmq-externals project and compile rocketmq-console.
Command example:
git clone https://github.com/apache/rocketmq-externals.git
cd rocketmq-externals/rocketmq-console
mvn clean package -Dmaven.test.skip=true
It will be target/rocketmq-console-ng*.jar
placed in the RocketMQ installation directory (/usr/local/rocketmq in this example).
Create a script to start RocketMQ console in the RocketMQ installation directory to start RocketMQ console:
nohup java -jar rocketmq-console-ng*.jar --server.port=8080 --rocketmq.config.namesrvAddr=localhost:9876 > /dev/null 2>&1 &
By default, the RocketMQ console does not require a password to log in. Please refer to the RocketMQ documentation for configuration.
See:
Troubleshooting
Question 1: Start Name Server
and Broker
error, or when the test Please set the JAVA_HOME variable in your environment, We need java(x64)!
but the system is already installed OpenJDK8, and has been set JAVA_HOME
.
Solution: Run which java
to check the path of java, for example /usr/bin/java
.
Modify bin/runserver.sh
and bin/runbroker.sh
and bin/tools.sh
, comment out the verification JAVA_HOME
statement and explicitly specify the JAVA路
path:
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=$HOME/jdk/java
#[ ! -e "$JAVA_HOME/bin/java" ] && JAVA_HOME=/usr/java
#[ ! -e "$JAVA_HOME/bin/java" ] && error_exit "Please set the JAVA_HOME variable in your environment, We need java(x64)!"
#export JAVA_HOME
export JAVA="/usr/bin/java"
Reference documents
- Detailed explanation of RocketMQ installation and deployment tutorial
- RocketMQ installation detailed instructions
Original from: http://suo.im/6197rC
Author: nklinsirui