RocketMQ 4.9.4 uses (1) Ubuntu20.04 installation and deployment - stand-alone

1. Official website and version features

Official website: https://rocketmq.apache.org/
Features and version release information: https://www.oschina.net/p/rocketmq

2. Download

https://rocketmq.apache.org/release_notes/release-notes-4.9.4/
insert image description here

3. Upload and decompress

unzip rocketmq-all-4.9.4-bin-release.zip
mv rocketmq-all-4.9.4-bin-release rocketmq-4.9.4

4. Modify the JVM configuration

The default virtual machine memory of RocketMQ is large, starting Broker or NameServer may fail due to insufficient memory, so you need to edit the following two configuration files to modify the JVM memory size.

Modify the default JVM size of bin/runbroker.sh

JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"

Modify the default JVM size of bin/runserver.sh

choose_gc_options()
{
    # Example of JAVA_MAJOR_VERSION value : '1', '9', '10', '11', ...
    # '1' means releases befor Java 9
    JAVA_MAJOR_VERSION=$("$JAVA" -version 2>&1 | sed -r -n 's/.* version "([0-9]*).*$/\1/p')
    if [ -z "$JAVA_MAJOR_VERSION" ] || [ "$JAVA_MAJOR_VERSION" -lt "9" ] ; then
      JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -Xmn2g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
      JAVA_OPT="${JAVA_OPT} -XX:+UseConcMarkSweepGC -XX:+UseCMSCompactAtFullCollection -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8 -XX:-UseParNewGC"
      JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:${GC_LOG_DIR}/rmq_srv_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps"
      JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
    else
      JAVA_OPT="${JAVA_OPT} -server -Xms4g -Xmx4g -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
      JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0"
      JAVA_OPT="${JAVA_OPT} -Xlog:gc*:file=${GC_LOG_DIR}/rmq_srv_gc_%p_%t.log:time,tags:filecount=5,filesize=30M"
    fi
}

5. Add environment variables

Edit /etc/profile to add the following

export ROCKETMQ_HOME=/opt/rocketmq-4.9.4/
export PATH=${ROCKETMQ_HOME}/bin:$PATH

Execute the following command to take effect environment variable

source /etc/profile

6. Start

# 首先启动Name Server
nohup bash mqnamesrv &

# 验证Name Server 是否启动成功
tail -f ~/logs/rocketmqlogs/namesrv.log
The Name Server boot success...

# 启动Broker
nohup bash mqbroker -n localhost:9876 &

# 验证Broker是否启动成功,例如Broker的IP为:192.168.1.2,且名称为broker-a
tail -f ~/logs/rocketmqlogs/broker.log 
The broker[VM-4-15-ubuntu, 10.0.4.15:10911] boot success. serializeType=JSON and name server is localhost:9876

# 关闭
bash mqshutdown namesrv
bash mqshutdown broker

7. Test

# 发送消息
cd /opt/rocketmq-4.9.4/bin/
export NAMESRV_ADDR=localhost:9876
bash bin/tools.sh org.apache.rocketmq.example.quickstart.Producer

# 接收消息
export NAMESRV_ADDR=localhost:9876
bash bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer

Guess you like

Origin blog.csdn.net/q283614346/article/details/126527212