1、官網下載安裝包,並上傳到服務器
下載地址:http://mosquitto.org/download/
上傳服務器,並解壓:
進入/etc/mosquitto/下:
cd /etc/mosquitto/
使用rz命令上傳,並使用tar進行解壓
rz
tar -zxvf mosquitto-1.5.4.tar.gz
2、進入解壓完的目錄:
3、安裝依賴庫
命令:yum install -y c-ares-devel e2fsprogs-devel uuid-devel libuuid-devel
4、進行編譯安裝
命令:make && make install
5、配置mosquitto
回到mosquitto目錄, 拷貝mosquitto.conf.example 爲 mosquitto.conf
cp mosquitto.conf.example mosquitto.conf
6、啓動:
mosquitto -c /etc/mosquitto/mosquitto.conf -d
7、測試
訂閱格式:mosquitto_sub -t 主題,假設主題名稱爲topic:
mosquitto_sub -t topic
發佈:另開一個窗口輸入內容
mosquitto_pub -h localhost -t topic -m "hello wosquitto"
與此同時,接收端收到發送的信息