一、引入mosquitto軟件資源庫。安裝的操做系統是centos,其它操做系統的安裝見官方文檔
在/etc/yum.repos.d/新建一個文件,好比mosquitto.repo,編輯該文件
對Centos 6,文件內容
[home_oojah_mqtt]
name=mqtt (CentOS_CentOS-6)
type=rpm-md
baseurl=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-6//repodata/repomd.xml.key
enabled=1
對centos 7,文件內容
[home_oojah_mqtt]
name=mqtt (CentOS_CentOS-7)
type=rpm-md
baseurl=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7/
gpgcheck=1
gpgkey=http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7//repodata/repomd.xml.key
enabled=1數據庫
二、安裝軟件
安裝mosquitto服務端
yum install mosquitto
安裝mosquitto命令行客戶端
yum install mosquitto-clients
三、mosquitto目錄說明
Mosquitto相關的命令文件路徑
/usr/sbin/mosquito # mosquitto啓動服務命令
/usr/bin/mosquito_pub # mosquitto發佈主題命令
/usr/bin/mosquito_sub # mosquitto訂閱主題命令
/usr/bin/mosquito_passwd # mosquitto加密密碼的工具
配置目錄
/etc/mosquito/
保存消息的數據庫路徑:可經過配置自定義路徑
/var/lib/mosquito/mosquitto.db
日誌路徑:須要建立:可經過配置自定義路徑
/var/log/mosquito/mosquitto.log
四、mosquitto啓動
mosquito -c /etc/mosquito/mosquito.conf
五、訂閱消息。
mosquitto_sub -t a/b/c
六、發佈消息。就能夠在命令行發佈多條消息,在第5步中的訂閱客戶端,就能接收到消息。
mosquitto_pub -t a/b/c -l
centos