一. 传统安装

  1. 下载RocketMQ到Linux服务器里

rocketmq-all-4.7.1-bin-release.zip

  1. 解压

    1. unzip rocketmq-all-4.7.1-bin-release.zip
  2. 启动NameServer

    1. cd rocketmq-all-4.7.1-bin-release
    2. nohup ./bin/mqnamesrv &

    PS: 若你的服务器内存太小会直接报错!
    image.png

查看nohup.out可知问题,分配的内存不够
image.png

  1. 修改JVM参数
    1. vim bin/runserver.sh
    2. vim bin/runbroker.sh
    这里我更改的比较小,根据实际情况变更哦
    image.png

启动namesrv服务:nohup sh bin/mqnamesrv &
启动broker服务:nohup sh bin/mqbroker &

关闭namesrv服务:sh bin/mqshutdown namesrv
关闭broker服务 :sh bin/mqshutdown broker

查看日志:tailf ~/logs/rocketmqlogs/namesrv.log
查看日志:tailf ~/logs/rocketmqlogs/broker.log
[

](https://blog.csdn.net/www_wangzheguilai/article/details/76483705)

二. 使用dokcer部署(推荐)

1. 使用docker服务部署搭配docker-compose一键快速部署

  1. cd /usr/local/docker/rocketmq #若没有对应目录自行创建
  2. vim docker-compose.yml

docker-compose.yml

  1. version: '3.5'
  2. services:
  3. rmqnamesrv:
  4. image: foxiswho/rocketmq:server
  5. container_name: rmqnamesrv
  6. ports:
  7. - 9876:9876
  8. volumes:
  9. - ./data/logs:/opt/logs
  10. - ./data/store:/opt/store
  11. networks:
  12. rmq:
  13. aliases:
  14. - rmqnamesrv
  15. rmqbroker:
  16. image: foxiswho/rocketmq:broker
  17. container_name: rmqbroker
  18. ports:
  19. - 10909:10909
  20. - 10911:10911
  21. volumes:
  22. - ./data/logs:/opt/logs
  23. - ./data/store:/opt/store
  24. - ./data/brokerconf/broker.conf:/etc/rocketmq/broker.conf
  25. environment:
  26. NAMESRV_ADDR: "rmqnamesrv:9876"
  27. JAVA_OPTS: " -Duser.home=/opt"
  28. JAVA_OPT_EXT: "-server -Xms128m -Xmx128m -Xmn128m"
  29. command: mqbroker -c /etc/rocketmq/broker.conf
  30. depends_on:
  31. - rmqnamesrv
  32. networks:
  33. rmq:
  34. aliases:
  35. - rmqbroker
  36. rmqconsole:
  37. image: styletang/rocketmq-console-ng
  38. container_name: rmqconsole
  39. ports:
  40. - 8080:8080
  41. environment:
  42. JAVA_OPTS: "-Drocketmq.namesrv.addr=rmqnamesrv:9876 -Dcom.rocketmq.sendMessageWithVIPChannel=false"
  43. depends_on:
  44. - rmqnamesrv
  45. networks:
  46. rmq:
  47. aliases:
  48. - rmqconsole
  49. networks:
  50. rmq:
  51. name: rmq
  52. driver: bridge

保存退出,接着

  1. mkdir data
  2. cd data/
  3. mkdir brokerconf
  4. cd brokerconf/
  5. vim broker.conf

broker.conf

  1. # Licensed to the Apache Software Foundation (ASF) under one or more
  2. # contributor license agreements. See the NOTICE file distributed with
  3. # this work for additional information regarding copyright ownership.
  4. # The ASF licenses this file to You under the Apache License, Version 2.0
  5. # (the "License"); you may not use this file except in compliance with
  6. # the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. # 所属集群名字
  16. brokerClusterName=DefaultCluster
  17. # broker 名字,注意此处不同的配置文件填写的不一样,如果在 broker-a.properties 使用: broker-a,
  18. # 在 broker-b.properties 使用: broker-b
  19. brokerName=broker-a
  20. # 0 表示 Master,> 0 表示 Slave
  21. brokerId=0
  22. # nameServer地址,分号分割
  23. # namesrvAddr=rocketmq-nameserver1:9876;rocketmq-nameserver2:9876
  24. # 启动IP,如果 docker 报 com.alibaba.rocketmq.remoting.exception.RemotingConnectException: connect to <192.168.0.120:10909> failed
  25. # 解决方式1 加上一句 producer.setVipChannelEnabled(false);,解决方式2 brokerIP1 设置宿主机IP,不要使用docker 内部IP
  26. brokerIP1=192.168.0.253(你自己宿主机的IP,请参考自己)
  27. # 在发送消息时,自动创建服务器不存在的topic,默认创建的队列数
  28. defaultTopicQueueNums=4
  29. # 是否允许 Broker 自动创建 Topic,建议线下开启,线上关闭 !!!这里仔细看是 false,false,false
  30. autoCreateTopicEnable=true
  31. # 是否允许 Broker 自动创建订阅组,建议线下开启,线上关闭
  32. autoCreateSubscriptionGroup=true
  33. # Broker 对外服务的监听端口
  34. listenPort=10911
  35. # 删除文件时间点,默认凌晨4点
  36. deleteWhen=04
  37. # 文件保留时间,默认48小时
  38. fileReservedTime=120
  39. # commitLog 每个文件的大小默认1G
  40. mapedFileSizeCommitLog=1073741824
  41. # ConsumeQueue 每个文件默认存 30W 条,根据业务情况调整
  42. mapedFileSizeConsumeQueue=300000
  43. # destroyMapedFileIntervalForcibly=120000
  44. # redeleteHangedFileInterval=120000
  45. # 检测物理文件磁盘空间
  46. diskMaxUsedSpaceRatio=88
  47. # 存储路径
  48. # storePathRootDir=/home/ztztdata/rocketmq-all-4.1.0-incubating/store
  49. # commitLog 存储路径
  50. # storePathCommitLog=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/commitlog
  51. # 消费队列存储
  52. # storePathConsumeQueue=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/consumequeue
  53. # 消息索引存储路径
  54. # storePathIndex=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/index
  55. # checkpoint 文件存储路径
  56. # storeCheckpoint=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/checkpoint
  57. # abort 文件存储路径
  58. # abortFile=/home/ztztdata/rocketmq-all-4.1.0-incubating/store/abort
  59. # 限制的消息大小
  60. maxMessageSize=65536
  61. # flushCommitLogLeastPages=4
  62. # flushConsumeQueueLeastPages=2
  63. # flushCommitLogThoroughInterval=10000
  64. # flushConsumeQueueThoroughInterval=60000
  65. # Broker 的角色
  66. # - ASYNC_MASTER 异步复制Master
  67. # - SYNC_MASTER 同步双写Master
  68. # - SLAVE
  69. brokerRole=ASYNC_MASTER
  70. # 刷盘方式
  71. # - ASYNC_FLUSH 异步刷盘
  72. # - SYNC_FLUSH 同步刷盘
  73. flushDiskType=ASYNC_FLUSH
  74. # 发消息线程池数量
  75. # sendMessageThreadPoolNums=128
  76. # 拉消息线程池数量
  77. # pullMessageThreadPoolNums=128

注意:brokerIP1要改成自己的IP,并且对外放出所有端口

回到docker-compose.yml路径下,运行启动docker-compose

  1. cd ../../
  2. docker-compose up -d
  3. docker ps #查看是否运行

成功如下
image.png
在portain中可以查看到容器状态image.png

2. 查看RocketMQ控制台

访问 http://RocketMQIP:8080 登入控制台
image.png


这样环境就搭建好了,结合springboot测试demo请看RocketMQ在Springbot上测试