RocketMQ安装教程

 受众

本文档要求读者有一定的linux运维基础,从事Java开发为佳,了解mvn项目构建.

简介

RocketMQ 是由阿里用java语言开发的一款高性能、高吞吐量的分布式消息中间件,于2017年正式捐赠 Apache 基金会并成为顶级开源项目。

环境要求

官网的描述:

The following softwares are assumed installed:

  1. 64bit OS, Linux/Unix/Mac is recommended;
  2. 64bit JDK 1.8+;
  3. Maven 3.2.x;
  4. Git;
  5. 4g+ free disk for Broker server

笔者的环境:

  • ubuntu-14.04.6-server-amd64
  • java version 1.8.0_141

一、RocketMQ安装

安装必要软件

安装 jdk:

sudo apt-get update
复制代码
sudo apt-get install default-jdk
复制代码

或者 Linux安装JDK1.8(wget方式)

安装maven:

sudo apt-get install maven
复制代码

安装git:

sudo apt-get update
sudo apt-get install git
复制代码

下载源码包并构建

下载源码包:

  wget http://mirrors.tuna.tsinghua.edu.cn/apache/rocketmq/4.2.0/rocketmq-all-4.2.0-source-release.zip
复制代码

通过maven构建:

 unzip rocketmq-all-4.2.0-source-release.zip
 cd rocketmq-all-4.2.0/
 mvn -Prelease-all -DskipTests clean install -U
 cd distribution/target/apache-rocketmq
复制代码

修改默认配置:
开发调试的话,不需要使用太高的配置.默认的配置占用的内存太高.

vim bin/runserver.sh
vim bin/runbroker.sh
vim bin/tools.sh
复制代码

修改JAVA_HOME及Xms,Xmx,Xmn等内存配置,默认最小4G

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m -XX:MetaspaceSize=128m -XX:MaxMetaspaceSize=320m"

启动name server

nohup sh bin/mqnamesrv & tail -f ~/logs/rocketmqlogs/namesrv.log
复制代码

启动 broker

nohup sh bin/mqbroker -n localhost:9876 & tail -f ~/logs/rocketmqlogs/broker.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
复制代码

二、RocketMQ控制台

文档地址: RocketMQ-Console-Ng

拉取源码:

cd /opt
git clone https://github.com/apache/rocketmq-externals.git
复制代码

修改配置:

cd rocketmq-console/src/main/resources
vi application.properties
复制代码

配置文件内容:
将项目使用的rocketmq.config.namesrvAddr配置上去,设置rocketmq.config.isVIPChannel=false

server.contextPath=
server.port=8080

### SSL setting
#server.ssl.key-store=classpath:rmqcngkeystore.jks
#server.ssl.key-store-password=rocketmq
#server.ssl.keyStoreType=PKCS12
#server.ssl.keyAlias=rmqcngkey

#spring.application.index=true
spring.application.name=rocketmq-console
spring.http.encoding.charset=UTF-8
spring.http.encoding.enabled=true
spring.http.encoding.force=true
logging.config=classpath:logback.xml
#if this value is empty,use env value rocketmq.config.namesrvAddr  NAMESRV_ADDR | now, you can set it in ops page.default localhost:9876
rocketmq.config.namesrvAddr=
#if you use rocketmq version < 3.5.8, rocketmq.config.isVIPChannel should be false.default true
rocketmq.config.isVIPChannel=
#rocketmq-console's data path:dashboard/monitor
rocketmq.config.dataPath=/tmp/rocketmq-console/data
#set it false if you don't want use dashboard.default true
rocketmq.config.enableDashBoardCollect=true
#set the message track trace topic if you don't want use the default one
rocketmq.config.msgTrackTopicName=
rocketmq.config.ticketKey=ticket

#Must create userInfo file: ${rocketmq.config.dataPath}/users.properties if the login is required
rocketmq.config.loginRequired=false
复制代码

将rocktmq-console打成jar包,得到rocketmq-console-ng-1.0.0.jar:

mvn clean package -Dmaven.test.skip=true
复制代码

运行jar包,启动项目,这里也可以设置rocketmq.config.namesrvAdd:

java -jar rocketmq-console-ng-1.0.0.jar --server.port=12581 --rocketmq.config.namesrvAddr=182.254.140.224:9876
复制代码

NOTE: 笔者使用的是虚拟机安装,为了方便在宿主机上看到控制台,因此,笔者将ubuntu的防火墙关闭. 命令: sudo ufw disable

DEMO

TODO: github link

你可能感兴趣的:(rocketmq,docker,mysql,容器,运维,数据库)