centos6.5 mosquitto (websocket)1.4.8安装

搭建步骤如下:

1、安装依赖包
yum -y install gcc gcc-c++ openssl-devel c-ares-devel libuuid-devel wget cmake

2、安装libwebsockets(mosquitto支持websocket)
命令如下:
cd /mnt/
git clone https://git.oschina.net/woniu201/libwebsockets.git
cd libwebsockets/
tar zxfv libwebsockets-v1.5-stable.tar.gz
cd libwebsockets-v1.5-stable
mkdir build
cd build/
cmake ..
make && make install

3、安装mosquitto
wget http://mosquitto.org/files/source/mosquitto-1.4.8.tar.gz
tar zxfv mosquitto-1.4.8.tar.gz
cd mosquitto-1.4.8
vi 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
cd /etc/mosquitto/
创建mosquitto.conf、pwfile文件
# cp mosquitto.conf.example mosquitto.conf
# cp pwfile.example pwfile
修改 文件mosquitto.conf
这里写图片描述
并在最后添加:
port 1883
listener 9109
protocol websockets

4、启动
mosquitto -d -c /etc/mosquitto/mosquitto.conf

报错:mosquitto: error while loading shared libraries: libwebsockets.so.5: cannot open shared object file: No such file or directory
处理方法:
[root@Docker mosquitto]# cat /etc/ld.so.conf
include ld.so.conf.d/*.conf
[root@Docker mosquitto]# echo “/usr/local/lib”>>/etc/ld.so.conf
[root@Docker mosquitto]# ldconfig

5、测试
开两个窗口
mosquitto_sub -t mqtt (订阅)
mosquitto_pub -h localhost -t mqtt -m “hello world”(发送消息)

# -c是指定一个配置文件 # -d作为守护进程 # -p是指定端口,默认1883
# -v详细日志输出

6、设置密码
a、修改/etc/mosquitto/mosquitto.conf
allow_anonymous false
b、新建用户
mosquitto_passwd -c /etc/mosquitto/pwfile test
c、测试命令
mosquitto_sub -t mqtt -u test -P t123456
mosquitto_pub -h localhost -t mqtt -m “hello world” -u test -P t123456

搭建支持websocket,主要是小程序的开发中需要用到此技术点。此篇文章主要是现实了第一步,下一篇文章会介绍小程序中使用websocket协议连接mqtt服务器。

参考资料:
http://blog.csdn.net/u011033736/article/details/53218394
http://blog.csdn.net/u012377333/article/details/69397124

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值