首页 技术 正文
技术 2022年11月16日
0 收藏 903 点赞 2,801 浏览 1370 个字

OS环境:CentOS6.5

1、安装依赖

yum -y install gcc gcc-c++ openssl-devel c-ares-devel libuuid-devel wget cmake

2、为mosquitto增加websocket支持,安装文本socket库文件 ,解压缩

# tar zxfv libwebsockets-v1.6-stable.tar.gz

  

3、运行 websocket

# cd libwebsockets-v1.6-stable# mkdir bulid# cd bulid# cmake ..# make && make install

  

4、安装mosquitto

下载mqtt--- mosquitto-1.4.8.tar.gz, 解压缩

# tar zxfv mosquitto-1.4.8.tar.gz

  

5、修改config.mk文件以使后面编译的mosquitto文件支持websocket

# cd /mosquitto-1.4.8

  

mosquitto-1.4.8目录下的config.mk文件,把config.mk 文件中的 WITH_WEBSOCKETS:=no 改为yes

保存后,执行

# make && make install# ln -s /usr/local/lib/libwebsockets.so.6 /usr/lib64/libwebsockets.so.6# groupadd mosquitto# useradd -g mosquitto mosquitto

6、创建mosquitto.conf、pwfile文件

# cd /etc/mosquitto/

如果该目录下没有mosquitto.conf 和 pwfile 
执行

# cp mosquitto.conf.example mosquitto.conf# cp pwfile.example pwfile

  

然后修改 文件mosquitto.conf ,

511 allow_anonoymous true
.
.
.
537 password_file /etc/mosquitto/pwfile

  

并在文件最后加入

port 1883
listener 8080
protocol websockets

  

7、启动mqtt

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

  

8、测试 
另外打开两个终端 
终端一: 
 这里其实就是订阅一个主题为”mqtt”的消息。”mqtt”为主题名,假如有客户端发布了主题为”mqtt”的消息,这个终端将会收到消息的内容。

mosquitto_sub -t mqtt

  

终端二: 
 这里就是发布一个主题为”mqtt”,内容为”hello mqtt”的消息。

mosquitto_pub -h localhost -t mqtt -m "hello mqtt"

  

这时终端一会收到:hello mqtt

9、错误解决

在安装过程中,或测试过程中可能会遇到错误:

mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

解决方法:

# cat /etc/ld.so.conf# echo "/usr/local/lib">>/etc/ld.so.conf# ldconfig

  

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,989
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,503
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,348
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,131
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,765
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,842