CentOS 安装Mosquitto及测试
系统信息,阿里云服务器
安装工具
yum install gcc gcc-c++
yum install openssl-devel
yum install c-ares-devel
yum install libuuid-devel
yum install wget
yum install cmake
yum install build-essential python quilt devscripts python-setuptools python3
yum install libssl-dev libc-ares-dev uuid-dev daemon openssl-devel
下载并编译安装libwebsockets
wget https://libwebsockets.org/git/libwebsockets/snapshot/libwebsockets-2.0.2.tar.gz
tar zxvf libwebsockets-2.0.2.tar.gz
cd libwebsockets-2.0.2
mkdir build
cd build
cmake .. -DLIB_SUFFIX=64
make install
ldconfig
修正链接库
vim /etc/ld.so.conf.d/liblocal.conf
/usr/local/lib64
/usr/local/lib
ldconfig
下载并编译安装mosquitto
wget http://mosquitto.org/files/source/mosquitto-1.4.9.tar.gz
tar -xzvf mosquitto-1.4.9.tar.gz
cd mosquitto-1.4.9
更改configure.mk中
WITH_WEBSOCKETS:=no
为
WITH_WEBSOCKETS:=yes
make
make install
cp mosquitto.conf /etc/mosquitto
修改mosquitto.conf文件
在/etc/mosquitto/mosquitto.conf的Default Listener一节添加如下几行:
运行mosquitto
mosquitto -c /etc/mosquitto/mosquitto.conf
mosquitto -c /etc/mosquitto/mosquitto.conf -v
或mosquitto -c /etc/mosquitto/mosquitto.conf -d
本机测试mosquitto
在服务器上新建两个shell,A和B
A 订阅主题:
mosquitto_sub -t topicA
B 推送消息:
mosquitto_pub -t topicA -h localhost -m "topicA test"
远程测试
下载安装MQTT.fx,下图设置服务器地址
下图设置订阅的topic
下图是服务器发布,MQTT.fx和本机订阅收到的信息
下图是MQTT.fx发布,服务器上订阅收到的信息
至此已经将MQTT服务器初步搭建成功。感谢网络上的一些文字的帮助
http://www.cnblogs.com/littleatp/p/4835879.html
http://blog.csdn.net/qhdcsj/article/details/45042515
./mosquitto_sub: error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory
执行命令:
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
和
ldconfig
即可
posted on 2017-02-16 11:21 cn三少<script></script> 阅读(4194) 评论(0) 编辑 收藏 举报