Linux安装mosquitto mqtt几种方式

Eclipse Mosquitto是一个开源消息代理,实现了MQTT协议版本3.1和3.1.1。提供轻量级的,支持可发布/可订阅的的消息推送模式,Mosquitto的轻量,适用于低功耗单板计算机到完整服务器的所有设备。Mosquitto项目还提供了用于实现MQTT客户端的C库以及非常受欢迎的mosquitto_pub和mosquitto_sub命令行MQTT客户端。

Linux离线安装mosquitto

官方下载地址: https://mosquitto.org/download/

#下载包
wget http://mosquitto.org/files/source/mosquitto-1.4.5.tar.gz

#解压
tar -zxvf mosquitto-1.4.5.tar.gz

#进入目录,编译
cd mosquitto-1.4.5/
make
sudo make install

#拷贝配置
cp mosquitto.conf /etc/mosquitto/

#查看版本
mosquitto -v

#创建组和用户
groupadd mosquitto
useradd -g mosquitto mosquitto

#查看服务启动
ps -aux | grep mosquitto

#启动服务
mosquitto -c /etc/mosquitto/mosquitto.conf -d -v
 

mosquitto-1.6.10版本的安装

#解压mqtt包
tar -zxvf mosquitto-1.6.10.tar.gz

cd mosquitto-1.6.10/

make

sudo make install

#拷贝配置
cp mosquitto.conf /etc/mosquitto/

#拷贝可执行文件
cp /usr/local/sbin/mosquitto /usr/sbin/

#查看帮助
mosquitto -h

#创建分组和用户
groupadd mosquitto

useradd -g mosquitto mosquitto -s /sbin/nologin

#查看启动情况
ps -aux | grep mosquitto

#mqtt启动文件复制指定目录
cp mosquitto.service /etc/systemd/system/

##添加文件执行权限
chmod +x /etc/systemd/system/mosquitto.service

#重新加载配置文件
systemctl daemon-reload

#设置mqtt开机自启
systemctl enable mosquitto.service

#查看mqtt开机启动状态
systemctl is-enabled mosquitto.service

#启动mqtt
systemctl start mosquitto.service

#查看启动状态
systemctl status mosquitto.service

ps -aux | grep mosquitto

CentOS在线安装mosquitto

yum install -y mosquito

mosquitto MQTT 高版本 2.x以上远程访问设置

mosquitto MQTT 高版本 2.x以上,默认是:只能本机访问, 且不能匿名访问 增加: allow_anonymous true 允许匿名访问 listener 1883 可以远程访问

cat /etc/mosquitto/mosquitto.conf 
# Place your local configuration in /etc/mosquitto/conf.d/
#
# A full description of the configuration file is at
# /usr/share/doc/mosquitto/examples/mosquitto.conf.example

persistence true
persistence_location /var/lib/mosquitto/

log_dest file /var/log/mosquitto/mosquitto.log

include_dir /etc/mosquitto/conf.d

allow_anonymous true
listener 1883

参考链接: https://www.jianshu.com/p/9e3cb7042a2e https://www.jianshu.com/p/a0efd843a39f https://www.shangmayuan.com/a/b088b32fe79d411bb6ac849d.html https://www.icode9.com/content-3-901950.html https://www.pianshen.com/article/70141267956/ https://my.oschina.net/wujinghust/blog/661167