c4rt1y

mosquitto安装与使用

0x01 mosquitto介绍

一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,提供轻量级的,支持可发布/可订阅的的消息推送模式,使设备对设备之间的短消息通信变得简单,比如现在应用广泛的低功耗传感器,手机、嵌入式计算机、微型控制器等移动设备。一个典型的应用案例就是 Andy Stanford-ClarkMosquitto(MQTT协议创始人之一)在家中实现的远程监控和自动化。并在 OggCamp 的演讲上,对MQTT协议进行详细阐述。

0x02 环境介绍

#一共2台服务器
master.com 10.10.10.20
node01.com 10.10.10.30

#关闭防火墙
systemctl stop firewalld.service
systemctl disable firewalld.service

#两种方法设置host(每台对应每台的host地址)
echo "master.com" > /etc/hostname
hostname master.com

#下载第三方依赖环境包
yum -y install epel-release

#设置host
cat >>/etc/hosts <<EOF 
10.10.10.20 master.com 
10.10.10.30 node01.com
EOF 

#关闭selinux,需要重启
sed -i 's:SELINUX=enforcing:SELINUX=disabled:g' /etc/selinux/config

#临时关闭seLinux
setenforce 0

#重启
reboot

0x03 安装mosquitto

##在node01和master上

#安装源
wget http://download.opensuse.org/repositories/home:/oojah:/mqtt/CentOS_CentOS-7/home:oojah:mqtt.repo -O /etc/yum.repos.d/mqtt.repo
#安装服务器端
yum install mosquitto.x86_64
#安装客户端
yum install mosquitto-clients.x86_64

0x04 mosquitto使用

##master和node01上
#启动mosquitto
mosquitto -d

##测试一:本机订阅推送,任意一台服务器,启动两个终端

#启动订阅客户端(监听msg组信息,默认监听本机)
mosquitto_sub -t msg 
#推送信息到客户端
mosquitto_pub -t msg -m "this is testing"

#会在mosquitto_sub的终端发现this is testing


##测试二:
##node01上
mosquitto_pub -h 10.10.10.20 -t msg 
##master上
mosquitto_pub -t msg -m "this is testing by 10.10.10.20"

0x05 资料来源

https://baike.baidu.com/item/mosquitto/3172080?fr=aladdin   mosquitto
GoTop