Ubuntu14 搭建mosquitto

前置条件:

  • 环境: VMWare 12.x + Ubuntu14 64bits
  • 所需软件:VIM

搭建mosquitto:

  1. 添加仓库,更新软件包

    sudo apt-add-repository ppa:mosquitto-dev/mosquitto-ppa
    sudo apt-get update

    这部分我更新软件包时,公钥报错: 解决方案:

    >sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys xxxxxxxxxxxxxxxx
    #此处xxxxxxxx为错误提示的key
    
  2. 安装mosquitto组件

    sudo apt-get install mosquitto
    sudo apt-get install mosquitto-clients

  3. 修改配置文件mosquitto.conf

    路径: /etc/mosquito/

    mosquitto.conf

  4. 创建pwfile

    touch /etc/mosquito/pwfile
    mosquitto_passwd /etc/mosquito/pwfile [username]

    pwfile

  5. 编辑aclfile文件

    vi /etc/mosquitto/aclfile

    aclfile

  6. 以配置文件启动

    mosquito –c /etc/mosquitto/mosquitto.conf –d

测试mosquitto:

  • Subscribe:

    mosquitto_sub –h localhost –t “test/#” –u beelinker2 –P 123456 –i “client1”

  • Publish:

    mosquitto_pub –h localhost –t “test/abc” –u beelinker1 –P 123456 –i “client3” –m “contextxxxxxxxx”

    test

其他操作

  1. 查看进程

    ps aux|grep mosquitto

  2. 结束进程

    kill -9 进程码

其他问题

  1. 启用mosquitto.conf,出现 “address already in use” 的问题时,

    查看当前mosquitto 进程 ,并删除。
    如果无法正常结束进程,删除路径下mosquitto.conf 文件,然后执行删除操作。下次启用时重新配置。

  2. Connection Refused

    用户名密码不匹配。关注pwfile、aclfile文件,及mosquitto.conf文件中allow_anoymous参数值。

  3. 客户端1 订阅主题后,客户端2 发布同主题信息,没有反应。

    几个问题:
    1、在aclfile中不能追求整齐随意使用制表符,定义参数之间用 “ ” 代替。
    2、在配置好 mosquitto.conf 后,不通过mosquitto -c mosquitto.conf -d的方式启动,就不会出现服务stop/waiting的问题,使用service mosquitto start启动

拓展

  • 外网访问本地mqtt服务器
  1. 下载安装配置花生壳内网穿透服务

    dpkg-i phddns_3.0_x86_64.deb #安装
    phddns status #查看phddns状态
    在这里插入图片描述

  2. 登录花生壳管理平台, 使用SN码登录,绑定激活申请好的域名,建立端口映射。
    在这里插入图片描述

参考资料:

  1. https://mosquitto.org/download/
  2. https://blog.csdn.net/loovejava/article/details/21837935
  3. https://www.jianshu.com/p/9e3cb7042a2e
  4. https://www.cnblogs.com/minseo/p/10826110.html
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值