基于docker安装rocketmq

    docker search rocketmq

    image.png
    添加文件夹和配置文件

    whereis docker

    查找docker目录,我自己的docker配置文件目录是在/etc/docker下
    1.进入etc/docker目录下创建rocketmq文件夹
    2.进入rocketmq文件夹内创建data文件夹和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. - 18081: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

    3.进入data文件夹创建brokerconf文件夹,并在文件夹中创建文件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=39.103.173.206
    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

    三:启动查看
    启动,安装docker-compose 需要服务器支持python,pip等命令

    docker-compose up -d

    启动需进入etc/docker/rocketmq目录下执行命令
    docker-compose.yml同级目录下执行docker-compose命令
    http://rmqIP:8080 登入控制台
    image.png

    1. docker create -p 10911:10911 -p 10909:10909 --name rmqbroker1 \
    2. -e "JAVA_OPTS=-Duser.home=/opt" \
    3. -e "JAVA_OPT_EXT=-server -Xms128m -Xmx128m -Xmn128m" \
    4. -v /haoke/rmq/rmqbroker/conf/broker.conf:/etc/rocketmq/broker.conf \
    5. -v /haoke/rmq/rmqbroker/logs:/opt/logs \
    6. -v /haoke/rmq/rmqbroker/store:/opt/store \
    7. foxiswho/rocketmq:broker