IT数码 购物 网址 头条 软件 日历 阅读 图书馆
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
图片批量下载器
↓批量下载图片,美女图库↓
图片自动播放器
↓图片自动播放器↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁
 
   -> 开发工具 -> Centos7下RocketMQ单机环境搭建 -> 正文阅读

[开发工具]Centos7下RocketMQ单机环境搭建

1 下载源码

# 进入/srv/source 目录, 没有目录的自行创建source目录
cd /srv
mkdir source
# git克隆源码
 git clone https://gitee.com/apache/rocketmq.git
 # 进入源码目录
 cd /srv/source/rocketmq
 # 切换release-4.9.2分支到本地
 git checkout -b release-4.9.2 origin/release-4.9.2

2 项目构建

cd /srv/source/rocketmq
#mvn源码构建: 源码编译太久了,建议官网直接下载编译文件
mvn -Prelease-all -DskipTests clean install -U
# 这里的4.9.2是版本号,可能不同,请注意自己的版本
cd distribution/target/rocketmq-4.9.2/rocketmq-4.9.2
#把这个rocketmq-4.9.2复制到 /srv 目录下

等待时间太久了, 就不使用源码构建,可以去官网下载编译包
在这里插入图片描述
在这里插入图片描述
把下载好的rocketmq-4.9.2编译包上传到服务器上,放在 /srv 目录下

3 启动 NameServer

#进入rocketmq-4.9.2目录下
cd /srv/rocketmq-4.9.2
#启动NameServer
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

# 启动Broker, 在/srv/rocketmq-4.9.2目录下执行一下命令
nohup sh bin/mqbroker -n localhost:9876 &
# 查看日志,确认是否成功
tail -f ~/logs/rocketmqlogs/broker.log 
# 如果出现以下信息,则Broker启动成功
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文件

#进入/srv/rocketmq-4.9.2 目录发现多了一个nohup.out文件
cd /srv/rocketmq-4.9.2
#查看nohup.out文件
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

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

if [ -z "$ROCKETMQ_HOME" ] ; then
  ## resolve links - $0 may be a link to maven's home
  PRG="$0"

  # need this for relative symlinks
  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"`/..

  # make it fully qualified
  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

# 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:${CLASSPATH}

#===========================================================================================
# JVM Configuration
#===========================================================================================
# The RAMDisk initializing size in MB on Darwin OS for gc-log
DIR_SIZE_IN_MB=600

choose_gc_log_directory()
{
    case "`uname`" in
        Darwin)
            if [ ! -d "/Volumes/RAMDisk" ]; then
                # create ram disk on Darwin systems as gc-log directory
                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"
        ;;
        *)
            # check if /dev/shm exists on other systems
            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} -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} $@
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成功

  开发工具 最新文章
Postman接口测试之Mock快速入门
ASCII码空格替换查表_最全ASCII码对照表0-2
如何使用 ssh 建立 socks 代理
Typora配合PicGo阿里云图床配置
SoapUI、Jmeter、Postman三种接口测试工具的
github用相对路径显示图片_GitHub 中 readm
Windows编译g2o及其g2o viewer
解决jupyter notebook无法连接/ jupyter连接
Git恢复到之前版本
VScode常用快捷键
上一篇文章      下一篇文章      查看所有文章
加:2021-12-23 15:56:13  更:2021-12-23 15:57:44 
 
开发: C++知识库 Java知识库 JavaScript Python PHP知识库 人工智能 区块链 大数据 移动开发 嵌入式 开发工具 数据结构与算法 开发测试 游戏开发 网络协议 系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程
数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁

360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 -2024/11/15 14:57:17-

图片自动播放器
↓图片自动播放器↓
TxT小说阅读器
↓语音阅读,小说下载,古典文学↓
一键清除垃圾
↓轻轻一点,清除系统垃圾↓
图片批量下载器
↓批量下载图片,美女图库↓
  网站联系: qq:121756557 email:121756557@qq.com  IT数码