RocketMQ系列:1.CentOS7安装单机版RocketMQ

1、安装JDK

Oracle官网下载jdk,并上传到/usr/local/目录下,本文采用的为:jdk-8u192-linux-x64.tar.gz

# 解压
tar zxvf jdk-8u192-linux-x64.tar.gz
# 配置环境变量
vim /etc/profile
export JAVA_HOME=/usr/local/jdk1.8.0_192
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
# 重新加载环境变量
source /etc/profile
# 测试
java -version

2、安装RocketMQ

# 进入安装目录
cd /usr/local/
# 下载RocketMQ
wget https://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.6.1/rocketmq-all-4.6.1-bin-release.zip
# 解压
unzip rocketmq-all-4.6.1-bin-release.zip
# 重命名安装目录
mv rocketmq-all-4.6.1-bin-release rocketmq

3、调整启动内存

RocketMQ默认的虚拟机内存较大,启动时可能会因为内存不足导致失败,所以需要调整默认内存

vim /usr/local/rocketmq/bin/runserver.sh
JAVA_OPT="${JAVA_OPT} -server -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"
vim /usr/local/rocketmq/bin/runbroker.sh
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

参考设置:

JAVA_OPT=“${JAVA_OPT} -server -xms256m -xmx256m -xmn128m -xx

4、启动RocketMQ

nohup sh /usr/local/rocketmq/bin/mqnamesrv > /usr/local/rocketmq/logs/namesrv.log &
nohup sh /usr/local/rocketmq/bin/mqbroker -n localhost:9876 > /usr/local/rocketmq/logs/broker.log &

5、使用脚本管理RocketMQ

  1. 编写管理脚本:rocketmq.sh

    #!/usr/bin/env bash
    
    #
    # rocketmq - this script starts and stops the rocketmq daemon
    #
    # chkconfig: - 85 15
    
    ROCKETMQ_HOME=/usr/local/rocketmq
    ROCKETMQ_BIN=${ROCKETMQ_HOME}/bin
    ADDR=`hostname -i`:9876
    LOG_DIR=${ROCKETMQ_HOME}/logs
    NAMESERVER_LOG=${LOG_DIR}/namesrv.log
    BROKER_LOG=${LOG_DIR}/broker.log
     
    start() {
        if [ ! -d ${LOG_DIR} ];then
            mkdir ${LOG_DIR}
        fi
        cd ${ROCKETMQ_HOME}
        nohup sh bin/mqnamesrv > ${NAMESERVER_LOG} 2>&1 &
        echo -n "The Name Server boot success..."
        nohup sh bin/mqbroker -n ${ADDR} > ${BROKER_LOG} 2>&1 &
        echo -n "The broker[%s, ${ADDR}] boot success..."
    }
    stop() {
        cd ${ROCKETMQ_HOME}
        sh bin/mqshutdown broker
        sleep 1
        sh bin/mqshutdown namesrv
    }
    restart() {
        stop
        sleep 10
        start
    }
      
    case "$1" in
        start)
            start
        ;;
        stop)
            stop
        ;;
        restart)
            restart
        ;;
        *)
    echo $"Usage: $0 {start|stop|restart}"
    exit 2
    esac
    
  2. 将rocketmq服务添加为开机启动服务

    chmod a+x rocketmq.sh
    sudo mv rocketmq.sh /etc/init.d/rocketmq
    chkconfig --add rocketmq
    
  3. 通过service命令来管理rocketmq

    # 启动:
    service rocketmq start
    # 关闭
    service rocketmq stop
    # 重启
    service rocketmq restart
    

5、安装可视化服务配置

  1. 下载源码:https://github.com/apache/incubator-rocketmq-externals

  2. 根据说明文档以及实际需求更改配置文件:application.properties

  3. 修改依赖:

    修改 pom.xml ,修改RocketMQ相关依赖的版本,找到

    <rocketmq.version>4.4.0</rocketmq.version>
    

    改为自己的版本,本文使用的为:4.6.1

  4. 修改代码

    修改pom.xml后,org.apache.rocketmq.console.service.impl.MessageServiceImpl#queryMessageByTopic编译会报错,所以需要修改一下:将:
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, null);
    改为:
    RPCHook rpcHook = null;
    DefaultMQPullConsumer consumer = new DefaultMQPullConsumer(MixAll.TOOLS_CONSUMER_GROUP, rpcHook);

  5. 打包构建:

    # 切换到代码根目录
    cd rocketmq-externals
    # 切换到控制台目录
    cd rocketmq-console
    # 构建
    mvn clean package -DskipTests
    

    ```bash

    创建数据目录

    mkdir -p /usr/local/rocketmq/rocketmq-console/data

    上传rocketmq-console-ng-1.0.1.jar到/usr/local/rocketmq/rocketmq-console

    在/usr/local/rocketmq/rocketmq-console/data 创建账号脚本users.properties

    内容:

    username=password[,N] 1:管理员,0:普通用户

    #定义管理员
    admin=admin,1

#定义普通用户
user1=user0
user2=user0

启动

java -jar /usr/local/rocketmq/rocketmq-console/rocketmq-console-ng-1.0.1.jar
```


转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。可以在下面评论区评论,也可以邮件至 jiang4yu@126.com

文章标题:RocketMQ系列:1.CentOS7安装单机版RocketMQ

字数:820

本文作者:

发布时间:2020-06-20, 00:29:36

最后更新:2024-03-30, 14:44:25

原始链接:https://blog.jiang4yu.com/2020/06/19/RocketMQ%E7%B3%BB%E5%88%97%EF%BC%9A1-CentOS7%E5%AE%89%E8%A3%85%E5%8D%95%E6%9C%BA%E7%89%88RocketMQ/

版权声明: "署名-非商用-相同方式共享 4.0" 转载请保留原文链接及作者。

×

喜欢就点赞,疼爱就打赏