centos 安装rocketmq

常用命令

#解压
tar -zxvf xxx.tar.gz
unzip xxx.zip

#查看端口进程
jps -m
lsof -i
lsof -i:端口号
netstat -tunlp
netstat -tunlp|grep 端口号

#不启动日志
nohup  java -jar xxx.jar >/dev/null 2>&1 &

环境变量

vim /etc/profile

# java 环境
export JAVA_HOME=/usr/local/software/jdk1.8.0_301
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH

# maven环境
export MAVEN_HOME=/usr/local/software/apache-maven-3.8.3
export MAVEN_HOME
export PATH=$MAVEN_HOME/bin:$PATH


source /etc/profile

注意端口放行

netstat -tunlp

#如下
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      5968/sshd           
tcp        0      0 0.0.0.0:8888            0.0.0.0:*               LISTEN      1597427/python      
tcp6       0      0 :::10911                :::*                    LISTEN      1813778/java        
tcp6       0      0 :::10912                :::*                    LISTEN      1813778/java        
tcp6       0      0 :::9999                 :::*                    LISTEN      1813960/java        
tcp6       0      0 :::9876                 :::*                    LISTEN      1813858/java        
tcp6       0      0 :::22                   :::*                    LISTEN      5968/sshd           
tcp6       0      0 :::10909                :::*                    LISTEN      1813778/java        
udp        0      0 127.0.0.1:323           0.0.0.0:*                           5578/chronyd        
udp6       0      0 ::1:323                 :::*                                5578/chronyd   

注意 987610909-10912 为rocketmq vip端口

资源下载

rocketmq

二进制版本

源代码版本

rocketmq-dashboard

源代码版本

rocketmq 编译安装

unzip rocketmq-all-4.9.1-source-release.zip
cd rocketmq-all-4.9.1/
mvn -Prelease-all -DskipTests clean install -U
cd distribution/target/rocketmq-4.9.1/rocketmq-4.9.1

rocketmq-dashboard 编译安装

编译

unzip rocketmq-dashboard-rocketmq-dashboard-1.0.0.zip
cd /rocketmq-dashboard-rocketmq-dashboard-1.0.0
vim pom.xml
#修改 rocketmq.version 为 4.9.1
#编译
mvn clean package -Dmaven.test.skip=true

配置

#配置文件
cd target
mkdir rocketmq-dashboard-1.0.0
cp classes/application.properties rocketmq-dashboard-1.0.0/
cp classes/users.properties rocketmq-dashboard-1.0.0/
cp rocketmq-dashboard-1.0.0.jar rocketmq-dashboard-1.0.0/

cd rocketmq-dashboard-1.0.0

# 修改 application.properties
rocketmq.config.namesrvAddr=12.23.123.4:9876 #(外网地址)
rocketmq.config.loginRequired=true #(开启登录验证)

# 用户权限见 users.properties

rocketmq 小内存设置


vim runserver.sh

#找到这里设置小内存
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

vim runbroker.sh

#找到这里设置小内存
JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

启动注意

# 启动 mqnamesrv
nohup sh bin/mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log

# 生成启动配置文件
sh bin/mqbroker -m >broker.p

# 查看生成的配信
cat broker.p

# 整体替换掉
# conf/broker.conf
# 注意这两个关键配置
# namesrvAddr=localhost:9876
# brokerIP1=1.117.92.53  这里写外网ip

# 启动 mqbroker
nohup sh bin/mqbroker -c conf/broker.conf & tail -f ~/logs/rocketmqlogs/broker.log


#启动 控制台
nohup java -jar rocketmq-dashboard-1.0.0.jar >> ~/logs/rocketmq-dashboard.log 2>&1 & tail -f ~/logs/rocketmq-dashboard.log

测试

export NAMESRV_ADDR=localhost:9876
# 测试Producer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
# SendResult [sendStatus=SEND_OK, msgId= ...

# 测试Consumer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
# ConsumeMessageThread_%d Receive New Messages: [MessageExt...

安全关闭

sh bin/mqshutdown broker
# The mqbroker(36695) is running...
# Send shutdown request to mqbroker(36695) OK

sh bin/mqshutdown namesrv
# The mqnamesrv(36664) is running...
# Send shutdown request to mqnamesrv(36664) OK

日志轮转

# logrotate日志轮转安装
yum -y install logrotate

# logrotate配置文件
cd /etc/logrotate.d

vim rocketmqlogs_watermark
# 添加如下轮转配置

/root/logs/rocketmqlogs/watermark.log {
        create 644 root root
        rotate 10
        daily
        nocompress
        missingok
        extension .log
        dateext
        dateformat -%Y%m%d-%H%M%S
        copytruncate
        createolddir
        olddir watermark
}

shell 启动文件

dshboard-rocketmq.sh

#!/bin/bash
cd /usr/local/software/rocketmq-dashboard-1.0.0
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=rocketmq-dashboard-1.0.0.jar

#日志路径
APP_LOG_PATH=./logs/rocketmq-dashboard

#日志文件名
APP_LOG_FILE=rocketmq-dashboard.log

#日志整体路径和文件名
APP_LOG=$APP_LOG_PATH/$APP_LOG_FILE


#使用说明,用来提示输入参数
usage() {
  echo "Usage: sh demo.sh [start|stop|restart|status]"
  exit 1
}

#检查程序是否在运行
is_exist() {
  pid=`ps -ef | grep $APP_NAME | grep -v grep | awk '{print $2}' `
  #如果不存在返回1,存在返回0
  if [ -z "$pid" ]; then
    return 1
  else
    return 0
  fi
}

#启动方法
start() {
  is_exist
  if [ $? -eq "0" ]; then
    echo "$APP_NAME is already running. pid=$pid ."
  else
    #不带日志
    #nohup java -jar ${APP_NAME} >/dev/null 2>&1 &
    #带日志

    if [ ! -d $APP_LOG_PATH  ];then
      mkdir -p $APP_LOG_PATH
    fi
    nohup java -jar $APP_NAME >> $APP_LOG 2>&1 & tail -f $APP_LOG
    echo "log path:"$APP_LOG_PATH$APP_LOG_FILE
  fi
}

#停止方法
stop() {
  is_exist
  if [ $? -eq "0" ]; then
    kill -9 $pid
  else
    echo "$APP_NAME is not running"
  fi
}

#输出运行状态
status() {
  is_exist
  if [ $? -eq "0" ]; then
    echo "$APP_NAME is running. Pid is $pid"
  else
    echo "$APP_NAME is not running."
  fi
}

#重启
restart() {
  stop
  start
}

#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
  "start")
    start
  ;;
  "stop")
    stop
  ;;
  "status")
    status
  ;;
  "restart")
    restart
  ;;
  *)
    usage
  ;;
esac

server-rocketmq.sh

#!/bin/bash
cd /usr/local/software/rocketmq-4.9.1
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=mqnamesrv
 
#使用说明,用来提示输入参数
usage() {
    echo "Usage: sh demo.sh [start|stop|restart|status]"
    exit 1
}
 
#检查程序是否在运行
is_exist() { 
    pid=`ps -ef | grep "tools.jar org.apache.rocketmq.namesrv.NamesrvStartup" | grep -v grep | awk '{print $2}' `
    #如果不存在返回1,存在返回0
    if [ -z "${pid}" ]; then
      return 1
    else
      return 0
    fi
}
 
#启动方法
start() {
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is already running. pid=${pid} ."
   else
   	 #不带日志
   	 #nohup java -jar ${APP_NAME} >/dev/null 2>&1 &
   	 #带日志
     #nohup java -jar ${APP_NAME} >> ~/logs/console-plus.log 2>&1 & tail -f ~/logs/console-plus.log
     nohup sh bin/${APP_NAME} & tail -f ~/logs/rocketmqlogs/namesrv.log
   fi
}
 
#停止方法
stop() {
   is_exist
   if [ $? -eq "0" ]; then
     #kill -9 $pid
     sh bin/mqshutdown namesrv
   else
     echo "${APP_NAME} is not running"
   fi
}
 
#输出运行状态
status() {
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is running. Pid is ${pid}"
   else
     echo "${APP_NAME} is not running."
   fi
}
 
#重启
restart() {
   stop
   start
}
 
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
   "start")
     start
     ;;
   "stop")
     stop
     ;;
   "status")
     status
     ;;
   "restart")
     restart
     ;;
   *)
     usage
     ;;
esac

broker-rocketmq.sh

#!/bin/bash
cd /usr/local/software/rocketmq-4.9.1
#这里可替换为你自己的执行程序,其他代码无需更改
APP_NAME=mqbroker
 
#使用说明,用来提示输入参数
usage() {
    echo "Usage: sh demo.sh [start|stop|restart|status]"
    exit 1
}
 
#检查程序是否在运行
is_exist() { 
    pid=`ps -ef | grep "tools.jar org.apache.rocketmq.broker.BrokerStartup" | grep -v grep | awk '{print $2}' `
    #如果不存在返回1,存在返回0
    if [ -z "${pid}" ]; then
      return 1
    else
      return 0
    fi
}
 
#启动方法
start() {
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is already running. pid=${pid} ."
   else
   	 #不带日志
   	 #nohup java -jar ${APP_NAME} >/dev/null 2>&1 &
   	 #带日志
     #nohup java -jar ${APP_NAME} >> ~/logs/console-plus.log 2>&1 & tail -f ~/logs/console-plus.log
     nohup sh bin/${APP_NAME} -c conf/broker.conf & tail -f ~/logs/rocketmqlogs/broker.log
   fi
}
 
#停止方法
stop() {
   is_exist
   if [ $? -eq "0" ]; then
     #kill -9 $pid
     sh bin/mqshutdown broker
   else
     echo "${APP_NAME} is not running"
   fi
}
 
#输出运行状态
status() {
   is_exist
   if [ $? -eq "0" ]; then
     echo "${APP_NAME} is running. Pid is ${pid}"
   else
     echo "${APP_NAME} is not running."
   fi
}
 
#重启
restart() {
   stop
   start
}
 
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
   "start")
     start
     ;;
   "stop")
     stop
     ;;
   "status")
     status
     ;;
   "restart")
     restart
     ;;
   *)
     usage
     ;;
esac

all-run.sh

#!/bin/bash
cd /usr/local/software/app-start
 
#使用说明,用来提示输入参数
usage() {
    echo "Usage: sh demo.sh [start|stop|restart|status]"
    exit 1
}
 
 
#启动方法
start() {
    sh server-rocketmq.sh start >/dev/null 2>&1 &
    echo "server-rocketmq running"
    sh broker-rocketmq.sh start >/dev/null 2>&1 &
    echo "broker-rocketmq running"
    sh dshboard-rocketmq.sh start >/dev/null 2>&1 &
    echo "dshboard-rocketmq running"
}
 
#停止方法
stop() {
   sh server-rocketmq.sh stop && sh broker-rocketmq.sh stop && sh dshboard-rocketmq.sh stop
}
 
#输出运行状态
status() {
    sh server-rocketmq.sh status
    sh broker-rocketmq.sh status
    sh dshboard-rocketmq.sh status
}
 
#重启
restart() {
   stop
   echo "正在停止服务中"
   sleep 10s #表示延迟一秒
   echo "准备启动服务中"
   start
}
 
#根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
   "start")
     start
     ;;
   "stop")
     stop
     ;;
   "status")
     status
     ;;
   "restart")
     restart
     ;;
   *)
     usage
     ;;
esac

启动整合

# 开启服务
sh all-run.sh start
# 关闭服务
sh all-run.sh stop
# 查看服务pid
sh all-run.sh status
# 重启服务
sh all-run.sh restart
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值