zoukankan      html  css  js  c++  java
  • 二、 Mosquitto 使用说明

    一、 继上一篇文章<<Mosquitto 介绍&安装>> 之后、本章介绍 Mosquitto 的 简单使用。

    1> 创建用户

    # groupadd mosquitto
      # useradd -g mosquitto mosquitto

    2> 程序配置

    # mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf

    3> 配置说明

    # 服务进程的PID
    #pid_file /var/run/mosquitto.pid
     
    # 服务进程的系统用户
    #user mosquitto
     
    # 服务绑定的IP地址
    #bind_address
     
    # 服务绑定的端口号
    #port 1883
     
    # 允许的最大连接数,-1表示没有限制
    #max_connections -1
     
    # 允许匿名用户
    #allow_anonymous true

    4> 如果实现websocket 功能 添加如下配置:

    mosquitto.conf 的“Default Listener” 一节添加如下几行: 
    port 1883 
    listener 9001 
    protocol websockets 
    

    将websocket 端口映射到 9001 上 

    后续需要使用libwebsockets的库文件,如果找不到库,执行下面的命令为库做一下符号连接(分64位和32位)

    ln -s /usr/local/lib/libwebsockets.so.10 /usr/lib64/libwebsockets.so.10

    5> 启动 mosquitto

    # mosquitto -c /etc/mosquitto/mosquitto.conf –d

    启动如出现如下错误:

    .mosquitto: error while loading shared libraries: libwebsockets.so.4.0.0: cannot open shared object file: No such file or directory
    

     是libwebsockets 库的问题:

    ln -s /usr/local/lib64/libwebsockets.so.4.0.0 /usr/lib/libwebsockets.so.4.0.0 
    

     还出现上述问题:

    vi /etc/ld.so.conf.d/lib64c.conf 
    
    …and add the following lines:- 
    ==lib64c default configuration 
    /usr/local/lib64 
    …and then:- 
    
     ldconfig
    

     成功启动1883端口监听

    5> 测试:
    5.1>  打开两个shell窗口
    5.2> 订阅一个主题

    # mosquitto_sub -t mqtt

    5.3> 在另一窗口推送消息

    # mosquitto_pub -t mqtt -h localhost -m "new location“

    OK 这时会在订阅窗口看到推送的信息

    new location

  • 相关阅读:
    数据结构之整数划分问题(转)
    各种排序方法的收集
    bloom filter 的Java 版
    常见面试题学习(3)
    优先级队列的Java ,C++ STL,堆实现
    常见面试题学习(2)
    常见面试题学习(5)
    常见面试题学习(4)
    常见面试题学习(1)
    bitmap与桶方式对1000万数据进行排序(转+自己实现理解)
  • 原文地址:https://www.cnblogs.com/yueli/p/7478543.html
Copyright © 2011-2022 走看看