rocketmq

安装包:rocketmq-all-4.5.1-bin-release.zip

安装unzip:sudo wget http://downloads.sourceforge.net/infozip/unzip552.tar.gz

解压:tar zxvf unzip552.tar.gz

进入目录:cd unzip-5.52/

将Makefile从unix子目录复制到当前目录:cp unix/Makefile ./

安装:make generic

    make install

解压文件到指定文件opt:unzip rocketmq-all-4.5.1-bin-release.zip -d /opt

进入到解压的文件:cd /opt

修改文件名:mv rocketmq-all-4.5.1-bin-release/ rocket

配置rocket环境变量:vi /etc/profile

export ROCKET_HOME=/opt/rocket
export PATH=$PATH:$ROCKET_HOME/bin

 使环境变量生效:. /etc/profile

启动:

先启动:mqnamesrv

再开窗口启动:mqbroker -n localhost:9876

整合(有时候不生效):mqnamesrv -->mqbroker -n localhost:9876

加载配置文件启动:mqbroker -n localhost:9876 -c /opt/rocket/conf/broker.conf

  mqbroker -n localhost:9876

停止:mqshutdown broker-->mqshutdown namesrv

jsp:查看启动的项目

注jdk11不兼容需要该以下参数:

vi bin/runserver.sh

:%d   删除所有

#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more 
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. 
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with 
# the License. You may obtain a copy of the License at 
#
# http://www.apache.org/licenses/LICENSE-2.0 
#
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License.

#========================================================================== ================= 
# Java Environment Setting 
#========================================================================== =================

error_exit () 
{
echo "ERROR: $1 !!" 
exit 1 
}

[ ! -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="$JAVA_HOME/bin/java" 
export BASE_DIR=$(dirname $0)/.. 
export CLASSPATH=.:${BASE_DIR}/conf:${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib/*

#========================================================================== ================= 
# JVM Configuration 
#========================================================================== ================= 
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=64m -XX:MaxMetaspaceSize=160m" 
JAVA_OPT="${JAVA_OPT} -XX:CMSInitiatingOccupancyFraction=70 -XX:+CMSParallelRemarkEnabled -XX:SoftRefLRUPolicyMSPerMB=0 -XX:+CMSClassUnloadingEnabled -XX:SurvivorRatio=8" 
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xlog:gc:/dev/shm/rmq_srv_gc.log -XX:+PrintGCDetails" 
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow" 
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages" 
# JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib" 
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n" 
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" 
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}" 

$JAVA ${JAVA_OPT} $@

  

mqbroker -n localhost:9876

vi bin/runbroker.sh

#!/bin/sh

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with 
# this work for additional information regarding copyright ownership. 
# The ASF licenses this file to You under the Apache License, Version 2.0 123456
# (the "License"); you may not use this file except in compliance with 
# the License. You may obtain a copy of the License at 
#
# http://www.apache.org/licenses/LICENSE-2.0 
#
# Unless required by applicable law or agreed to in writing, software 
# distributed under the License is distributed on an "AS IS" BASIS, 
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
# See the License for the specific language governing permissions and 
# limitations under the License. 
#========================================================================== ================= 
# Java Environment Setting 
#========================================================================== =================
error_exit () 
{ 
	echo "ERROR: $1 !!" 
	exit 1 
}

[ ! -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="$JAVA_HOME/bin/java" 
export BASE_DIR=$(dirname $0)/.. 
export CLASSPATH=.${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}

#========================================================================== ================= 
# JVM Configuration 
#========================================================================== =================
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m" 
JAVA_OPT="${JAVA_OPT} -XX:+UseG1GC -XX:G1HeapRegionSize=16m -XX:G1ReservePercent=25 -XX:InitiatingHeapOccupancyPercent=30 -XX:SoftRefLRUPolicyMSPerMB=0" 
JAVA_OPT="${JAVA_OPT} -verbose:gc -Xloggc:/dev/shm/mq_gc_%p.log -XX:+PrintGCDetails" 
JAVA_OPT="${JAVA_OPT} -XX:-OmitStackTraceInFastThrow" 
JAVA_OPT="${JAVA_OPT} -XX:+AlwaysPreTouch" 
JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g" 
JAVA_OPT="${JAVA_OPT} -XX:-UseLargePages -XX:-UseBiasedLocking" 
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n" 
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}" 
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}" 

numactl --interleave=all pwd > /dev/null 2>&1 
if [ $? -eq 0 ]
then
	if [ -z "$RMQ_NUMA_NODE" ] ; then 
		numactl --interleave=all $JAVA ${JAVA_OPT} $@
	else
		numactl --cpunodebind=$RMQ_NUMA_NODE --membind=$RMQ_NUMA_NODE $JAVA ${JAVA_OPT} $@ 
	fi 
else
	$JAVA ${JAVA_OPT} --add-exports=java.base/jdk.internal.ref=ALL-UNNAMED $@
fi 

  

测试工具

vi bin/tools.sh

修改:

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m -XX:PermSize=128m -XX:MaxPermSize=128m"

# export CLASSPATH=.:${BASE_DIR}/conf:${CLASSPATH}
export CLASSPATH=.${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib/*:${BASE_DIR}/conf:${CLASSPATH}

删除:JAVA_OPT="${JAVA_OPT} -Djava.ext.dirs=${BASE_DIR}/lib:${JAVA_HOME}/jre/lib/ext"

 

测试:通过环境变量指定server的位置

先设置环境变量,在启动消费者:export NAMESRV_ADDR=localhost:9876 && tools.sh org.apache.rocketmq.example.quickstart.Consumer

先设置环境变量,在启动生产者:export NAMESRV_ADDR=localhost:9876 && tools.sh org.apache.rocketmq.example.quickstart.Producer

posted @ 2022-05-24 21:25  a快乐码农  阅读(45)  评论(0编辑  收藏  举报