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命令下载

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

3.项目解压命令

  1. 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

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

6.runbroker.sh

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

7.tools.sh

  1. 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 目录进行操作

  1. nohup sh bin/mqnamesrv &

9.启动 Broker

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

  1. 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.添加集群部署目录

  1. mkdir -p /opt/rocketmq-docker/conf

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

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

3.添加文件内容

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

3.broker-slave-a配置文件

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

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

2.添加文件内容

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

4.broker-master-b配置文件

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

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

2.添加文件内容

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

5.broker-slave-b配置文件

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

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

2.添加文件内容

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

6.编写Docker-compose文件

1.创建数据挂在目录

  1. mkdir -p /opt/rocketmq-docker/data/nameserver-a/logs
  2. mkdir -p /opt/rocketmq-docker/data/nameserver-a/store
  3. mkdir -p /opt/rocketmq-docker/data/nameserver-b/logs
  4. mkdir -p /opt/rocketmq-docker/data/nameserver-b/store
  5. mkdir -p /opt/rocketmq-docker/data/broker-master-a/logs
  6. mkdir -p /opt/rocketmq-docker/data/broker-master-b/logs
  7. mkdir -p /opt/rocketmq-docker/data/broker-master-a/store
  8. mkdir -p /opt/rocketmq-docker/data/broker-master-b/store
  9. mkdir -p /opt/rocketmq-docker/data/broker-slave-a/logs
  10. mkdir -p /opt/rocketmq-docker/data/broker-slave-b/logs
  11. mkdir -p /opt/rocketmq-docker/data/broker-slave-a/store
  12. mkdir -p /opt/rocketmq-docker/data/broker-slave-b/store
  13. mkdir -p /opt/rocketmq-docker/data/broker-master-a
  14. mkdir -p /opt/rocketmq-docker/data/broker-master-b
  15. mkdir -p /opt/rocketmq-docker/data/broker-slave-a
  16. mkdir -p /opt/rocketmq-docker/data/broker-slave-b

2.创建docker-compose文件

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

3.添加文件内容

  1. version: '2'
  2. services:
  3. nameserver-a:
  4. image: rocketmqinc/rocketmq
  5. container_name: nameserver-a
  6. networks:
  7. rocketmq_net:
  8. ipv4_address: 172.18.0.3
  9. environment:
  10. MAX_POSSIBLE_HEAP: 100000000
  11. ports:
  12. - 9876:9876
  13. volumes:
  14. - /opt/rocketmq-docker/data/nameserver-a/logs:/root/logs
  15. - /opt/rocketmq-docker/data/nameserver-a/store:/root/store
  16. command: sh mqnamesrv
  17. nameserver-b:
  18. image: rocketmqinc/rocketmq
  19. container_name: nameserver-b
  20. networks:
  21. rocketmq_net:
  22. ipv4_address: 172.18.0.4
  23. environment:
  24. MAX_POSSIBLE_HEAP: 100000000
  25. ports:
  26. - 9877:9876
  27. volumes:
  28. - /opt/rocketmq-docker/data/nameserver-b/logs:/root/logs
  29. - /opt/rocketmq-docker/data/nameserver-b/store:/root/store
  30. command: sh mqnamesrv
  31. broker-master-a:
  32. image: rocketmqinc/rocketmq
  33. container_name: broker-master-a
  34. networks:
  35. rocketmq_net:
  36. ipv4_address: 172.18.0.5
  37. environment:
  38. MAX_POSSIBLE_HEAP: 200000000
  39. ports:
  40. - 10909:10909
  41. - 10910:10910
  42. volumes:
  43. - /opt/rocketmq-docker/data/broker-master-a/logs:/root/logs
  44. - /opt/rocketmq-docker/data/broker-master-a/store:/root/store
  45. - /opt/rocketmq-docker/conf/broker-master-a.conf:/opt/rocketmq/conf/broker.conf
  46. command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
  47. depends_on:
  48. - nameserver-a
  49. - nameserver-b
  50. broker-master-b:
  51. image: rocketmqinc/rocketmq
  52. container_name: broker-master-b
  53. networks:
  54. rocketmq_net:
  55. ipv4_address: 172.18.0.6
  56. environment:
  57. MAX_POSSIBLE_HEAP: 200000000
  58. ports:
  59. - 10919:10919
  60. - 10920:10920
  61. volumes:
  62. - /opt/rocketmq-docker/data/broker-master-b/logs:/root/logs
  63. - /opt/rocketmq-docker/data/broker-master-b/store:/root/store
  64. - /opt/rocketmq-docker/conf/broker-master-b.conf:/opt/rocketmq/conf/broker.conf
  65. command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
  66. depends_on:
  67. - nameserver-a
  68. - nameserver-b
  69. broker-slave-a:
  70. image: rocketmqinc/rocketmq
  71. container_name: broker-slave-a
  72. networks:
  73. rocketmq_net:
  74. ipv4_address: 172.18.0.7
  75. environment:
  76. MAX_POSSIBLE_HEAP: 200000000
  77. ports:
  78. - 10911:10911
  79. volumes:
  80. - /opt/rocketmq-docker/data/broker-slave-a/logs:/root/logs
  81. - /opt/rocketmq-docker/data/broker-slave-a/store:/root/store
  82. - /opt/rocketmq-docker/conf/broker-slave-a.conf:/opt/rocketmq/conf/broker.conf
  83. command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
  84. depends_on:
  85. - nameserver-a
  86. - nameserver-b
  87. - broker-master-a
  88. - broker-master-b
  89. broker-slave-b:
  90. image: rocketmqinc/rocketmq
  91. container_name: broker-slave-b
  92. networks:
  93. rocketmq_net:
  94. ipv4_address: 172.18.0.8
  95. environment:
  96. MAX_POSSIBLE_HEAP: 200000000
  97. ports:
  98. - 10921:10921
  99. volumes:
  100. - /opt/rocketmq-docker/data/broker-slave-b/logs:/root/logs
  101. - /opt/rocketmq-docker/data/broker-slave-b/store:/root/store
  102. - /opt/rocketmq-docker/conf/broker-slave-b.conf:/opt/rocketmq/conf/broker.conf
  103. command: sh mqbroker -c /opt/rocketmq/conf/broker.conf
  104. depends_on:
  105. - nameserver-a
  106. - nameserver-b
  107. - broker-master-a
  108. - broker-master-b
  109. console:
  110. image: styletang/rocketmq-console-ng
  111. container_name: rocketmq-console-ng
  112. networks:
  113. rocketmq_net:
  114. ipv4_address: 172.18.0.9
  115. ports:
  116. - 8080:8080
  117. depends_on:
  118. - nameserver-a
  119. - nameserver-b
  120. environment:
  121. - JAVA_OPTS= -Dlogging.level.root=info -Drocketmq.namesrv.addr=172.18.0.3:9876;172.18.0.4:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false
  122. networks:
  123. rocketmq_net:
  124. ipam:
  125. config:
  126. - subnet: 172.18.0.0/16
  127. gateway: 172.18.0.1

7.启动docker集群

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

  1. docker-compose up -d

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

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

还没有评论