• docker-compose安装mqtt


    docke和docker-compose环境自己解决

    一、新建文件夹mqtt和文件内部文件

    1、编写docker-compose.yml文件 

    1. version: "3"
    2. services:
    3. mqtt:
    4. image: eclipse-mosquitto:2
    5. container_name: mqtt
    6. privileged: true
    7. ports:
    8. - 1883:1883
    9. - 9001:9001
    10. volumes:
    11. - ./config:/mosquitto/config
    12. - ./data:/mosquitto/data
    13. - ./log:/mosquitto/log

    2、config文件新建mosquitto.conf

    1. persistence true
    2. listener 1883
    3. persistence_location /mosquitto/data
    4. log_dest file /mosquitto/log/mosquitto.log
    5. # 关闭匿名模式
    6. #allow_anonymous true
    7. # 指定密码文件
    8. #password_file /mosquitto/config/pwfile.conf

    二、启动

    1. [mqtt]$ docker-compose up -d
    2. Creating network "mqtt_default" with the default driver
    3. Pulling mqtt (eclipse-mosquitto:2)...
    4. 2: Pulling from library/eclipse-mosquitto
    5. 213ec9aee27d: Pull complete
    6. c38859dc10af: Pull complete
    7. 20f8f1ac2856: Pull complete
    8. Digest: sha256:dbb267884bada100906702758cc2cbf334047f2837a52ae57ff272ea1ef6a99e
    9. Status: Downloaded newer image for eclipse-mosquitto:2
    10. Creating mqtt ... done

    三、设置密码

    进入容器内部
     docker exec -it mqtt sh
     
     生成文件 创建密码
    touch /mosquitto/config/pwfile.conf
    chmod -R 755 /mosquitto/config/pwfile.conf
    # 使用mosquitto_passwd命令创建用户,admin是用户名,admin123是密码
    mosquitto_passwd -b /mosquitto/config/pwfile.conf admin admin_23
    退出 
    exit 或者 Ctrl + D

    1. [mqtt]$ docker exec -it mqtt bash
    2. OCI runtime exec failed: exec failed: container_linux.go:367: starting container process caused: exec: "bash": executable file not found in $PATH: unknown
    3. [tly@sdmkdev1 mqtt]$ docker exec -it mqtt sh
    4. / # touch /mosquitto/config/pwfile.conf
    5. / # chmod -R 755 /mosquitto/config/pwfile.conf
    6. / # mosquitto_passwd -b /mosquitto/config/pwfile.conf admin admin123
    7. / # exit

    四、重启

    1. [mqtt]$ docker-compose restart
    2. Restarting mqtt ... done

    五、MQTTX客户端连接

    免费下载、试用 EMQ 产品

     

     

     

  • 相关阅读:
    实现切换图片透明度轮播效果
    MySQL数据库——17.正则表达式
    go-zero 是如何做路由管理的?
    RabbitMQ消费失败重试策略、及重试策略应用场景详解
    @Binds methods must be abstract 报错指南
    视频是不能 P 的系列:使用 Dlib 实现人脸识别
    简单介绍动态链接过程
    [CVPR2022] A Dual Weighting Label Assignment Scheme for Object Detection
    3、Pod资源管理
    动态规划算法
  • 原文地址:https://blog.csdn.net/xiaohanshasha/article/details/127666240