0


RocketMQ在Linux中的安装教程

安装教程

一.环境说明

  1. 对于 RocketMQ 4.3.0版本,官方要求环境如下,其中 Git 用于从 GitHub 获取源码,没有安装也没关系,可以直接下载
  2. 官方推荐的流程是:Linux 系统上安装 Git 工具 、Maven、Java JDK
  3. Git 工具用于直接从 GitHub 获取 RocketMQ 项目源码下载到 Linux 系统上
  4. 然后 Maven 将 RocketMQ 源码进行编译成二进制文件
  5. 安装了 Java JDK 就可以运行 RocketMQ 了

二.JDK和RocketMQ 版本说明

在这里插入图片描述

三.源码安装

1.可以从apache的文件库下载 https://archive.apache.org/dist/rocketmq/这里我们选择最新版
在这里插入图片描述
2.利用wget命令下载

wget https://archive.apache.org/dist/rocketmq/4.7.1/rocketmq-all-4.7.1-bin-release.zip

3.项目解压命令

unzip rocketmq-all-4.7.1-bin-release.zip  -d  /usr/local/rocketmq

4.修改RocketMQ启动配置

修改目录 /usr/local/rocketmq/rocketmq-all-4.7.1-bin-release/bin 下的 3 个配置文件: runserver.sh、runbroker.sh 、tools.sh不然会报insufficient memory

5.runserver.sh

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

6.runbroker.sh

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn128m"

7.tools.sh

JAVA_OPT="${JAVA_OPT} -server -Xms256m -Xmx256m -Xmn256m -XX:PermSize=128m -XX:MaxPermSize=128m"

8.启动 NameServer

进入 RocketMQ 安装目录下的 /usr/local/rocketmq/rocketmq-all-4.7.1-bin-release 目录进行操作

nohup sh bin/mqnamesrv &

9.启动 Broker

同样进入 RocketMQ 安装目录下的 /usr/local/rocketmq/rocketmq-all-4.7.1-bin-release 目录进行操作

nohup sh bin/mqbroker -n 192.168.44.128:9876 &

四.RocketMQ_双主双从集群_docker安装

1.前提

1.安装关系图
在这里插入图片描述
2.服务部署情况
在这里插入图片描述
在这里插入图片描述
3.端口号作用

  1. vip 通道端口(10909)一般没什么作用
  2. HA 高可用端口用于主从集群时,创建 Master 和 Slave 之间的 socket 连接

4.主从配置注意事项
3. brokerName需要一致,才可以形成主备关系
4. brokerId为0以及brokerRole为ASYNC_MASTER或者SYNC_MASTER代表为master.
5. broker不为0以及brokerRole为SLAVE代表为slave

2.broker-master-a配置文件

1.添加集群部署目录

mkdir -p /opt/rocketmq-docker/conf

2.创建 broker-master-a配置文件

vi /opt/rocketmq-docker/conf/broker-master-a.conf

3.添加文件内容

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId =0
deleteWhen = 04
fileReservedTime =48#namesrvAddr 地址 填写docker内网地址即可namesrvAddr=172.18.0.3:9876;172.18.0.4:9876
#启用自动创建主题autoCreateTopicEnable=true
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。#当前broker监听的IP
brokerIP1 =192.168.56.101
#存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步。
brokerIP2 =192.168.56.101
#Broker 对外服务的监听端口
listenPort =10909#Broker角色#- ASYNC_MASTER 异步复制Master#- SYNC_MASTER 同步双写Master#- SLAVEbrokerRole=SYNC_MASTER
#刷盘方式#- ASYNC_FLUSH 异步刷盘#- SYNC_FLUSH 同步刷盘flushDiskType=ASYNC_FLUSH

3.broker-slave-a配置文件

1.创建 broker-slave-a配置文件

vi /opt/rocketmq-docker/conf/broker-slave-a.conf

2.添加文件内容

brokerClusterName = DefaultCluster
brokerName = broker-a
brokerId =1
deleteWhen = 04
fileReservedTime =48#namesrvAddr 地址 填写docker内网地址即可namesrvAddr=172.18.0.3:9876;172.18.0.4:9876
#启用自动创建主题autoCreateTopicEnable=true
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。#当前broker监听的IP
brokerIP1 =192.168.56.101
#存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步。
brokerIP2 =192.168.56.101
#Broker 对外服务的监听端口
listenPort =10911#Broker角色#- ASYNC_MASTER 异步复制Master#- SYNC_MASTER 同步双写Master#- SLAVEbrokerRole=SLAVE
#刷盘方式#- ASYNC_FLUSH 异步刷盘#- SYNC_FLUSH 同步刷盘flushDiskType=ASYNC_FLUSH

4.broker-master-b配置文件

1.创建 broker-master-b配置文件

vi /opt/rocketmq-docker/conf/broker-master-b.conf

2.添加文件内容

brokerClusterName = DefaultCluster
brokerName = broker-b
brokerId =0
deleteWhen = 04
fileReservedTime =48#namesrvAddr 地址 填写docker内网地址即可namesrvAddr=172.18.0.3:9876;172.18.0.4:9876
#启用自动创建主题autoCreateTopicEnable=true
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。#当前broker监听的IP
brokerIP1 =192.168.56.101
#存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步。
brokerIP2 =192.168.56.101
#Broker 对外服务的监听端口
listenPort =10919#Broker角色#- ASYNC_MASTER 异步复制Master#- SYNC_MASTER 同步双写Master#- SLAVEbrokerRole=SYNC_MASTER
#刷盘方式#- ASYNC_FLUSH 异步刷盘#- SYNC_FLUSH 同步刷盘flushDiskType=ASYNC_FLUSH

5.broker-slave-b配置文件

1.创建 broker-slave-b配置文件

vi /opt/rocketmq-docker/conf/broker-slave-b.conf

2.添加文件内容

brokerClusterName = DefaultCluster
brokerName = broker-b
brokerId =1
deleteWhen = 04
fileReservedTime =48#namesrvAddr 地址 填写docker内网地址即可namesrvAddr=172.18.0.3:9876;172.18.0.4:9876
#启用自动创建主题autoCreateTopicEnable=true
#这个很有讲究 如果是正式环境 这里一定要填写内网地址(安全)#如果是用于测试或者本地这里建议要填外网地址,因为你的本地代码是无法连接到阿里云内网,只能连接外网。#当前broker监听的IP
brokerIP1 =192.168.56.101
#存在broker主从时,在broker主节点上配置了brokerIP2的话,broker从节点会连接主节点配置的brokerIP2来同步。
brokerIP2 =192.168.56.101
#Broker 对外服务的监听端口
listenPort = 10921dock    
#Broker角色#- ASYNC_MASTER 异步复制Master#- SYNC_MASTER 同步双写Master#- SLAVEbrokerRole=SLAVE
#刷盘方式#- ASYNC_FLUSH 异步刷盘#- SYNC_FLUSH 同步刷盘flushDiskType=ASYNC_FLUSH

6.编写Docker-compose文件

1.创建数据挂在目录

mkdir -p  /opt/rocketmq-docker/data/nameserver-a/logs
mkdir -p  /opt/rocketmq-docker/data/nameserver-a/store
mkdir -p  /opt/rocketmq-docker/data/nameserver-b/logs
mkdir -p  /opt/rocketmq-docker/data/nameserver-b/store
mkdir -p  /opt/rocketmq-docker/data/broker-master-a/logs
mkdir -p  /opt/rocketmq-docker/data/broker-master-b/logs
mkdir -p  /opt/rocketmq-docker/data/broker-master-a/store
mkdir -p  /opt/rocketmq-docker/data/broker-master-b/store
mkdir -p  /opt/rocketmq-docker/data/broker-slave-a/logs
mkdir -p  /opt/rocketmq-docker/data/broker-slave-b/logs
mkdir -p  /opt/rocketmq-docker/data/broker-slave-a/store
mkdir -p  /opt/rocketmq-docker/data/broker-slave-b/store
mkdir -p  /opt/rocketmq-docker/data/broker-master-a
mkdir -p  /opt/rocketmq-docker/data/broker-master-b
mkdir -p  /opt/rocketmq-docker/data/broker-slave-a
mkdir -p  /opt/rocketmq-docker/data/broker-slave-b

2.创建docker-compose文件

vi /opt/rocketmq-docker/docker-compose.yml

3.添加文件内容

version: '2'
services:
  nameserver-a:
    image: rocketmqinc/rocketmq
    container_name: nameserver-a
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.3
    environment:
      MAX_POSSIBLE_HEAP: 100000000
    ports:
      - 9876:9876
    volumes:
      - /opt/rocketmq-docker/data/nameserver-a/logs:/root/logs
      - /opt/rocketmq-docker/data/nameserver-a/store:/root/store
    command: sh mqnamesrv
  nameserver-b:
    image: rocketmqinc/rocketmq
    container_name: nameserver-b
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.4
    environment:
      MAX_POSSIBLE_HEAP: 100000000
    ports:
      - 9877:9876
    volumes:
      - /opt/rocketmq-docker/data/nameserver-b/logs:/root/logs
      - /opt/rocketmq-docker/data/nameserver-b/store:/root/store
    command: sh mqnamesrv
  broker-master-a:
    image: rocketmqinc/rocketmq
    container_name: broker-master-a
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.5
    environment:
      MAX_POSSIBLE_HEAP: 200000000
    ports:
      - 10909:10909
      - 10910:10910
    volumes:
      - /opt/rocketmq-docker/data/broker-master-a/logs:/root/logs
      - /opt/rocketmq-docker/data/broker-master-a/store:/root/store
      - /opt/rocketmq-docker/conf/broker-master-a.conf:/opt/rocketmq/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
    depends_on:
      - nameserver-a
      - nameserver-b
  broker-master-b:
    image: rocketmqinc/rocketmq
    container_name: broker-master-b
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.6
    environment:
      MAX_POSSIBLE_HEAP: 200000000
    ports:
      - 10919:10919
      - 10920:10920
    volumes:
      - /opt/rocketmq-docker/data/broker-master-b/logs:/root/logs
      - /opt/rocketmq-docker/data/broker-master-b/store:/root/store
      - /opt/rocketmq-docker/conf/broker-master-b.conf:/opt/rocketmq/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
    depends_on:
      - nameserver-a
      - nameserver-b
  broker-slave-a:
    image: rocketmqinc/rocketmq
    container_name: broker-slave-a
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.7
    environment:
      MAX_POSSIBLE_HEAP: 200000000
    ports:
      - 10911:10911
    volumes:
      - /opt/rocketmq-docker/data/broker-slave-a/logs:/root/logs
      - /opt/rocketmq-docker/data/broker-slave-a/store:/root/store
      - /opt/rocketmq-docker/conf/broker-slave-a.conf:/opt/rocketmq/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
    depends_on:
      - nameserver-a
      - nameserver-b
      - broker-master-a
      - broker-master-b
  broker-slave-b:
    image: rocketmqinc/rocketmq
    container_name: broker-slave-b
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.8
    environment:
      MAX_POSSIBLE_HEAP: 200000000
    ports:
      - 10921:10921
    volumes:
      - /opt/rocketmq-docker/data/broker-slave-b/logs:/root/logs
      - /opt/rocketmq-docker/data/broker-slave-b/store:/root/store
      - /opt/rocketmq-docker/conf/broker-slave-b.conf:/opt/rocketmq/conf/broker.conf
    command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
    depends_on:
      - nameserver-a
      - nameserver-b
      - broker-master-a
      - broker-master-b
  console:
    image: styletang/rocketmq-console-ng
    container_name: rocketmq-console-ng
    networks:
      rocketmq_net:
        ipv4_address: 172.18.0.9
    ports:
      - 8080:8080
    depends_on:
      - nameserver-a
      - nameserver-b
    environment:
      - JAVA_OPTS= -Dlogging.level.root=info -Drocketmq.namesrv.addr=172.18.0.3:9876;172.18.0.4:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
networks:
  rocketmq_net:
    ipam:
      config:
        - subnet: 172.18.0.0/16
          gateway: 172.18.0.1

7.启动docker集群

1.在docker-compose文件所在目录,执行命令启动

docker-compose up -d 

本文转载自: https://blog.csdn.net/weixin_44702984/article/details/131091119
版权归原作者 我就是我352 所有, 如有侵权,请联系我们删除。

“RocketMQ在Linux中的安装教程”的评论:

还没有评论