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
编写管理脚本: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
将rocketmq服务添加为开机启动服务
chmod a+x rocketmq.sh sudo mv rocketmq.sh /etc/init.d/rocketmq chkconfig --add rocketmq
通过service命令来管理rocketmq
# 启动: service rocketmq start # 关闭 service rocketmq stop # 重启 service rocketmq restart
5、安装可视化服务配置
根据说明文档以及实际需求更改配置文件:application.properties
修改依赖:
修改
pom.xml
,修改RocketMQ相关依赖的版本,找到<rocketmq.version>4.4.0</rocketmq.version>
改为自己的版本,本文使用的为:4.6.1
修改代码
修改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);打包构建:
# 切换到代码根目录 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