Linux上MQTT搭建
linux系统为Ubuntu16.04 server
1、安装软件
输入以下指令,逐个安装
apt-get install gcc apt-get install cmake apt-get install openssl apt-get install openssl-dev
新建software文件夹,下载mosquitto,下载并解压:
mkdir software cd software wget http://mosquitto.org/files/source/mosquitto-1.6.8.tar.gz tar -xzvf mosquitto-1.6.8.tar.gz
2、可选择下列软件安装
安装c-areas(支持异步DNS查找的库)
wget http://c-ares.haxx.se/download/c-ares-1.14.0.tar.gz tar xvf c-ares-1.14.0.tar.gz cd c-ares-1.14.0 ./configure make sudo make install
安装lib-uuid(支持为每个连接用户端生成唯一uuid)
apt-get install libuuid-dev
(此步骤没经过测试)
安装libwebsockets(支持需使用websocket的应用):
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
(此步骤没经过测试)
上面安装不成功不影响下列的操作
编译安装mosquitto
make sudo make install
注意:如果在后续使用过程中找不到libmosquitto.so.1的话,在software下输入以下指令修改一下libmosquitto.so的位置:
sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1 sudo ldconfig
3、启动测试
创建用户
sudo groupadd mosquitto sudo useradd -g mosquitto mosquitto
程序配置
mv /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf
启动程序
mosquitto -c /etc/mosquitto/mosquitto.conf -d
默认端口为1883
最后再另外打开一个terminal,在一个窗口(订阅)输入:
mosquitto_sub -t hello
另一个窗口(发布)输入:
mosquitto_pub -t hello -h localhost -m "hello world!"
相关推荐
lonesomer 2020-09-17
farwang 2020-11-25
星愿心愿 2020-11-24
tianhuak 2020-11-24
zhjn0 2020-11-24
昭君出塞 2020-11-23
bluecarrot 2020-11-23
linuxwcj 2020-10-21
以梦为马不负韶华 2020-10-20
彼岸随笔 2020-10-20
yutou0 2020-10-17
applecarelte 2020-10-16
ourtimes 2020-10-16
waterhorse 2020-09-19
MRFENGG 2020-11-11
rainandtear 2020-10-30
kyssfanhui 2020-10-20