1 下载源码
cd /srv
mkdir source
git clone https://gitee.com/apache/rocketmq.git
cd /srv/source/rocketmq
git checkout -b release-4.9.2 origin/release-4.9.2
2 项目构建
cd /srv/source/rocketmq
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/rocketmq-4.9.2/rocketmq-4.9.2
等待时间太久了, 就不使用源码构建,可以去官网下载编译包 把下载好的rocketmq-4.9.2编译包上传到服务器上,放在 /srv 目录下
3 启动 NameServer
cd /srv/rocketmq-4.9.2
nohup sh bin/mqnamesrv &
tail -f ~/logs/rocketmqlogs/namesrv.log
出现以下信息则成功启动
[root@hadoop101 rocketmq-4.9.2] tail -f ~/logs/rocketmqlogs/namesrv.log
2021-12-22 17:35:10 INFO main - tls.client.keyPassword = null
2021-12-22 17:35:10 INFO main - tls.client.certPath = null
2021-12-22 17:35:10 INFO main - tls.client.authServer = false
2021-12-22 17:35:10 INFO main - tls.client.trustCertPath = null
2021-12-22 17:35:10 INFO main - Using JDK SSL provider
2021-12-22 17:35:11 INFO main - SSLContext created for server
2021-12-22 17:35:11 INFO main - Try to start service thread:FileWatchService started:false lastThread:null
2021-12-22 17:35:11 INFO NettyEventExecutor - NettyEventExecutor service started
2021-12-22 17:35:11 INFO main - The Name Server boot success. serializeType=JSON
2021-12-22 17:35:11 INFO FileWatchService - FileWatchService service started
4 启动 Broker
nohup sh bin/mqbroker -n localhost:9876 &
tail -f ~/logs/rocketmqlogs/broker.log
2021-12-22 18:05:44 INFO main - Try to start service thread:PullRequestHoldService started:false lastThread:null
2021-12-22 18:05:44 INFO FileWatchService - FileWatchService service started
2021-12-22 18:05:44 INFO PullRequestHoldService - PullRequestHoldService service started
2021-12-22 18:05:44 INFO main - Try to start service thread:TransactionalMessageCheckService started:false lastThread:null
2021-12-22 18:05:44 INFO brokerOutApi_thread_1 - register broker[0]to name server localhost:9876 OK
2021-12-22 18:05:44 INFO main - The broker[hadoop101, 192.168.111.101:10911] boot success. serializeType=JSON and name server is localhost:9876
5 排查问题 启动broker, 执行tail -f ~/logs/rocketmqlogs/broker.log, 发现没日志, 则没有启动成功 进入/srv/rocketmq-4.9.2 目录发现多了一个nohup.out文件
cd /srv/rocketmq-4.9.2
tail -fn100 nohup.out
Java HotSpot(TM) 64-Bit Server VM warning: Using the DefNew young collector with the CMS collector is deprecated and will likely be removed in a future release
Java HotSpot(TM) 64-Bit Server VM warning: UseCMSCompactAtFullCollection is deprecated and will likely be removed in a future release.
The Name Server boot success. serializeType=JSON
Java HotSpot(TM) 64-Bit Server VM warning: INFO: os::commit_memory(0x00000005c0000000, 8589934592, 0) failed; error='Cannot allocate memory' (errno=12)
在/srv/rocketmq-4.9.2目录,找到 bin/mqbroker 启动文件, 查看里面的内容
cat /srv/rocketmq-4.9.2/bin/mqbroker
展示内容如下
#!/bin/sh
if [ -z "$ROCKETMQ_HOME" ] ; then
PRG="$0"
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG="`dirname "$PRG"`/$link"
fi
done
saveddir=`pwd`
ROCKETMQ_HOME=`dirname "$PRG"`/..
ROCKETMQ_HOME=`cd "$ROCKETMQ_HOME" && pwd`
cd "$saveddir"
fi
export ROCKETMQ_HOME
sh ${ROCKETMQ_HOME}/bin/runbroker.sh org.apache.rocketmq.broker.BrokerStartup $@
最后一行 sh ${ROCKETMQ_HOME}/bin/runbroker.sh 在rocketmq-4.9.2的目录下找到/bin/runbroker.sh 的shell脚本文件, 然后查看这个脚本文件
#!/bin/sh
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:${CLASSPATH}
DIR_SIZE_IN_MB=600
choose_gc_log_directory()
{
case "`uname`" in
Darwin)
if [ ! -d "/Volumes/RAMDisk" ]; then
DEV=`hdiutil attach -nomount ram://$((2 * 1024 * DIR_SIZE_IN_MB))` > /dev/null
diskutil eraseVolume HFS+ RAMDisk ${DEV} > /dev/null
echo "Create RAMDisk /Volumes/RAMDisk for gc logging on Darwin OS."
fi
GC_LOG_DIR="/Volumes/RAMDisk"
;;
*)
if [ -d "/dev/shm" ]; then
GC_LOG_DIR="/dev/shm"
else
GC_LOG_DIR=${BASE_DIR}
fi
;;
esac
}
choose_gc_log_directory
JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"
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:${GC_LOG_DIR}/rmq_broker_gc_%p_%t.log -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -XX:+PrintAdaptiveSizePolicy"
JAVA_OPT="${JAVA_OPT} -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=5 -XX:GCLogFileSize=30m"
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} -Djava.ext.dirs=${JAVA_HOME}/jre/lib/ext:${BASE_DIR}/lib:${JAVA_HOME}/lib/ext"
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} $@
fi
修改runbroker.sh文件的参数, 也就是JVM启动的内存大小修改
原来的:JAVA_OPT="${JAVA_OPT} -server -Xms8g -Xmx8g"
修改后: JAVA_OPT="${JAVA_OPT} -server -Xms128m -Xmx128m"
原来的JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=15g"
修改后JAVA_OPT="${JAVA_OPT} -XX:MaxDirectMemorySize=256m"
然后按照第4个步骤: “4 启动 Broker”,再次执行, 启动Broker成功
|