首页 > 其他分享 >Ubutu Mosquitto部署和相关的配置(支持websocket)

Ubutu Mosquitto部署和相关的配置(支持websocket)

时间:2022-12-02 23:03:23浏览次数:63  
标签:websocket conf Ubutu Mosquitto install libwebsockets mosquitto root


最近公司使用MQTT对公司现有的物联网设备进行重组,有幸能研究关于MQTT的一个服务端Mosquitto,虽然支持Socket的方式很好部署,但是在WebSoket的部署上还是走了很多弯路,网上查询了很多资料,现在将部署过程中遇到的问题做个总结,方便后续回顾查看:
首先下载Mosquitto安装文件
下载地址:​​​http://mosquitto.org/files/source/​​​
我用的是1.4.8 最新版本进行的部署! 参考部署地址:​​
该博客没有对websocket的支持,下面这篇博客是针对Websocket部署的时候,需要做以下操作:
下载最新的libwebsockets并放在服务器上去编译,下载地址:
​​​https://github.com/warmcat/libwebsockets​​​
下载完成以后 进入libwebsockets目录

mkdir build
cd build
cmake .. -DOPENSSL_ROOT_DIR=/usr/bin/openssl
make
sudo make install

当你安装mosquitto1.4最新版本的时候或多或少会遇到问题。
我是用的centos系统,系统默许很多没有安装
假设你是ubuntu系统请使用 apt-get 代替yum
首先是安装各种工具
yum install gcc gcc-c++ libstdc++-devel
编译进程中问题:
1. ssh.h找不到
yum install openssl-devel
2.ares.h找不到
yum install c-ares-devel
3.如果你添加了websocket
借助git工具 yum install git
wget ​http://git.warmcat.com/cgi-bin/cgit/libwebsockets/snapshot/libwebsockets​⑴.3-chrome37-firefox30.tar.gz
tar -zxvf libwebsockets⑴.3-chrome37-firefox30.tar.gz
cd libwebsockets⑴.3-chrome37-firefox30
mkdir build
cd build
cmake .. -DOPENSSL_ROOT_DIR=/usr/bin/openssl
make
sudo make install
4.uuid.h找不到
yum install libuuid-devel
5.mosquitto: error while loading shared libraries: libwebsockets.so.4.0.0: cannot open shared object file: No such file or directory
库的问题

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


还不行的话:

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

新的Mosquitto版本1.4.2已经支持WebSocket,这就为我们HTML5客户端使用MQTT提供了方法,但是MQTT连接默认不支持WebSocket连接,所以我们要首先设置让Mosquitto支持WebSocket:
(如果遇见有的步骤不能执行或者除错,请使用管理员权限sudo执行)废话不讲,开始:

第一步:安装前准备用到的依赖包:
sudoapt−getupdate sudo apt-get install build-essential python quilt devscripts python-setuptools python3
sudoapt−getinstalllibssl−dev sudo apt-get install cmake
sudoapt−getinstalllibc−ares−dev sudo apt-get install uuid-dev
sudoapt−getinstalldaemon

第二步:下载并编译安装libwebsockets wget ​​​http://git.libwebsockets.org/cgi​​​ … 3-firefox-36.tar.gz
tarzxvflibwebsockets−1.4−chrome43−firefox−36.tar.gz cd libwebsockets-1.4-chrome43-firefox-36
mkdirbuild cd build
cmake.. make install
ldconfig

第三步:下载并编译安装最新版 mosquitto 1.4.2

$ wget ​​http://mosquitto.org/files/source/mosquitto-1.4.2.tar.gz​​​
tarzxvfmosquitto−1.4.2.tar.gz cd mosquitto-1.4.2
更改configure.mk中
WITH_WEBSOCKETS:=no
变成(这一步是做WebSocket支持)

WITH_WEBSOCKETS:=yes
make make install
$ cp mosquitto.conf /etc/mosquitto
第四步:配置Mosquitto能够使用WebSocket

请在/etc/mosquitto/mosquitto.conf 的“Default Listener” 一节添加如下几行:
port 1883
listener 9001
protocol websockets
你添加过后此文件像这样的:

port 1883
listener 9001
protocol websockets
第五步:添加Mosquitto用户:

addusermosquitto reboot
第六步:运行Mosquitto:

$ mosquitto -c /etc/mosquitto/mosquitto.conf
现在你可以试试使用Websocket客户端来连接你的MQTT服务器的9001端口!!!!!!!


常用问题解答

This tutorial explains basic steps of installing mosquitto server on openwrt platform. Mosquitto exists in openwrt barrier breaker repository but I decided to crosscompile it. At host computer in openwrt directory call :

uros-petrevski-2:bin uros$ ./scripts/feeds install mosquitto-nossl
This will install version that don’t support ssl layer because we don’t need it. We need server that is fast. Run make menuconfig and under Network select mosquitto nossl as M package.

uros-petrevski-2:bin uros$ make J=4
Then copy mosquitto package to weio. Mosquitto don’t have any dependencies.

uros-petrevski-2:packages uros$ scp /Volumes/openwrt/carambola/bin/ramips/packages/mosquitto-nossl_1.0.3-1_ramips.ipk [email protected]:/tmp
Now it’s time to install mosquitto

root@Weio:/tmp# opkg install mosquitto-nossl_1.0.3-1_ramips.ipk -d root
If you run mosquitto now it will break :

root@Weio:/tmp# mosquitto

11145: Error: Invalid user ‘mosquitto’.
The reason is simple, user is not configured. As user is root we have to declare root user un mosquitto configuration. So edit /etc/mosquitto/mosquitto.conf file and add at user section

user root
If you want to run manually mosquitto (you can see what is happening with clients on the console) you have to do :

root@Weio:/# mosquitto -c /etc/mosquitto/mosquitto.conf
Parameter -c specify path to conf file. However if you want to run automaticaly on startup mosquitto server do following

root@Weio:/# /etc/init.d/mosquitto enable
Once system rebooted you can see mosquitto server running by :

root@Weio:/# ps | grep mosquitto
2570 root 932 S /usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
2574 root 1488 S grep mosquitto


完成以后测试WebSoket是否成功

下载这个进行测试即可

感谢提供参考资料: ​​
​http://www.tuicool.com/articles/ba6Vja​
​http://www.wfuyu.com/Internet/22690.html


标签:websocket,conf,Ubutu,Mosquitto,install,libwebsockets,mosquitto,root
From: https://blog.51cto.com/u_11295556/5907694

相关文章

  • Ubutu+Apache+Mono 实现.net开发的网站跨平台移植
    最近公司转型,需要将现有使用的.net技术开发的平台系统在linux系统上跑起来,一方面是为了节省成本(Linux免费),另一方面,现在是大数据的填写,所有的技术要向java平台移植,起到一个......
  • nginx反向代理websocket,ws转wss
    记录一下nginx规则location^~/echargenet-admin#本地代理目录{proxy_passhttp://127.0.0.1:8080/xxx;#websocket地址proxy_set_headerHost$host;#......
  • webSocket基本使用
    //创建ws实例,建立连接(ws://121.40.165.18.8800有广告)    varws=newWebSocket('wss://javascript.info/article/websocket/demo/hello')    //......
  • springboot 加入websocket后,ServerEndpointExporter配置不识别-解决
    1.背景springboot加入websocket,需要配置ServerEndpointExporter的bean,发现没法识别2.原因springboot内置了tomcat,内置的tomcat与websocket不兼容,因此需要将-start-w......
  • UT026010 Buffer pool was not set on WebSocketDeploymentInfo...
    UT026010:BufferpoolwasnotsetonWebSocketDeploymentInfo,thedefaultpoolwillbeused一、解决方案:在引入undertow包时剔除undertow-websockets-js包,启动无警......
  • fastapi系列之-在多进程使用websocket一些问题细节的小结
    由于之前一直未深入去了解过关于fastapi中websocket多进程问题,由于之前的测试有可能都是但进程的方式进行启动测试,即便有时候是多进程的方式启动,但是巧合的是估计刚好用户......
  • nginx反向代理websocket wss或ws端口
    1.直接上nginx配置文件注意:后端端口使用wss:proxy_passhttps://wss_8;后端端口使用ws:proxy_passhttp://wss_8;upstreamwss_8{server127.0.0.1:8004;}#......
  • websocket 测试
    npminstall-gwscatwscat-l8888wscat-cws://127.0.0.1:8888  constWebSocket=require('ws');constws=newWebSocket.Server({port:8777});ws.on('connection......
  • JFinal整合spring的websocket
    在使用JFinal整合spring使用spring的websocket的时候,遇到了很多问题,下面介绍整合的全过程和要注意的点。(整个项目使用maven进行搭建,服务器用的是eclipse自带的jetty)1.整个po......
  • spring配置websocket并实现群发/单独发送消息
    spring框架中自带了websocket的jar包,利用它可以实现与H5中WebSocket的对接,甚至websocket还可以通过依赖注入与http请求一同工作,详细配置实现过程如下文件目录结构如下,主要是......