常用命令
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
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
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
注意 9876 , 10909 -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
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
rocketmq.config.namesrvAddr= 12.23 .123.4:9876
rocketmq.config.loginRequired= true
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"
启动注意
nohup sh bin/mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log
sh bin/mqbroker -m > broker.p
cat broker.p
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
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Producer
sh bin/tools.sh org.apache.rocketmq.example.quickstart.Consumer
安全关闭
sh bin/mqshutdown broker
sh bin/mqshutdown namesrv
日志轮转
yum -y install 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 }' `
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
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 }' `
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 sh bin/${APP_NAME} & tail -f ~/logs/rocketmqlogs/namesrv.log
fi
}
stop ( ) {
is_exist
if [ $? -eq "0" ] ; then
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 }' `
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 sh bin/${APP_NAME} -c conf/broker.conf & tail -f ~/logs/rocketmqlogs/broker.log
fi
}
stop ( ) {
is_exist
if [ $? -eq "0" ] ; then
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
sh all-run.sh status
sh all-run.sh restart