moquitto部署验证发布订阅模式

1.基础准备

安装基础软件

yum install gcc-c++
yum install cmake
yum install openssl-devel //mosquitto默认支持openssl

2.下载程序

wget http://mosquitto.org/files/source/mosquitto-1.4.4.tar.gz
tar -xzvf mosquitto-1.4.4.tar.gz
cd mosquitto-1.4.4
3.编译安装

vim config.mk

参考如下:

4.安装c-areas

wget http://c-ares.haxx.se/download/c-ares-1.10.0.tar.gz
tar xvf c-ares-1.10.0.tar.gz
cd c-ares-1.10.0
./configure
make
sudo make install

5.安装lib-uuid

yum install libuuid-devel

6.安装libwebsockets

wget https://github.com/warmcat/libwebsockets/archive/v1.3-chrome37-firefox30.tar.gz
tar zxvf v1.3-chrome37-firefox30.tar.gz
cd libwebsockets-1.3-chrome37-firefox30
mkdir build; cd build;
cmake .. -DLIB_SUFFIX=64
make install


7.开始安装mosquitto

注意需要在解压目录下进行安装

make
make install
8.程序配置

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

配置项增加程序启动路径,其他部分未动,//关于详细配置可参考
http://mosquitto.org/man/mosquitto-conf-5.html

#pid_file /var/run/mosquitto.pid
 

9.启动程序

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

启动时出现如下错误:

解决方法:需要添加mosquitto用户,adduser -g mosquitto mosquitto

10.客户端测试

开两个shell窗口

cd /usr/local/bin

订阅者:mosquitto_sub -t location

发布者:mosquitto_pub -t location -h localhost -m "new location"

测试时出现错误:error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

解决方法:修正链接库路径

//添加路径

vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
  •  

//刷新
ldconfig

正常后可以在A窗口看到由B推送的消息,此外服务端窗口也可以看到客户端连接和端口的日志

参考1:https://blog.csdn.net/black_little_/article/details/88555822

参考2:https://www.cnblogs.com/Free-Thinker/p/5559816.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值