Install RocketMQ 4.7.1 on CentOS7

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).

Install RocketMQ 4.7.1 on CentOS7

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:

  1. Add a new Name Server configuration file namesrv.conf, save the content:
    listenPort=10076
  2. Specify the configuration file when starting the Name Server:
    nohup sh bin/mqnamesrv -c namesrv.conf >/dev/null 2>&1 &
  3. View the RocketMQ process:
    ps -ef | grep rocketmq
  4. Check the port number of RocketMQ Name Server:
    netstat -tnlp | grep <nameserver_pid>
  5. 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*.jarplaced 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 Serverand Brokererror, 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 javato check the path of java, for example /usr/bin/java.

Modify bin/runserver.shand bin/runbroker.shand bin/tools.sh, comment out the verification JAVA_HOMEstatement 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

Guess you like

Origin blog.51cto.com/mageedu/2539862