Mosquitto 安装、部署

mosquitto 官网

2.0.15版本为例

1.下载

cd /usr/local
wget https://mosquitto.org/files/source/mosquitto-2.0.15.tar.gz

2.解压

tar -zxvf mosquitto-2.0.15.tar.gz

3.安装依赖

apt-get install libssl-dev

安装cjson依赖

git clone https://github.com/DaveGamble/cJSON.git
cd cJSON
make && make install

4.编译安装

cd /usr/local/mosquitto-2.0.15
make && make install

5.配置文件

cp /etc/mosquitto/mosquitto.conf.example /etc/mosquitto/mosquitto.conf 

编辑

vi /etc/mosquitto/mosquitto.conf

6.配置

关闭匿名登录
找到allow_anonymous,取消#号,改为false

allow_anonymous false

配置pwfile文件位置
找到password_file,取消#号,改为pwfile.example(这个文件默认就有)

password_file /etc/mosquitto/pwfile.example

7.创建用户名密码

创建admin用户名、密码

mosquitto_passwd -c /etc/mosquitto/pwfile.example admin

会提示输入两次。

创建mosquitto用户

mosquitto_passwd /etc/mosquitto/pwfile.example mosquitto

会提示输入两次。


8.停止服务器

service mosquitto stop

因为安装完成后会自动启动

9.systemctl管理脚本

vi /usr/lib/systemd/system/Mosquitto.service
[Unit]
Description=Mosquitto
After=network.target
Wants=network.target
 
[Service]
ExecStart=/usr/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
User=root
LimitNOFILE=65535
[Install]
WantedBy=multi-user.target
systemctl start Mosquitto && systemctl enable Mosquitto

10.测试

使用命令行订阅主题

mosquitto_sub -t 'test/topic' -v

推送消息

mosquitto_pub -t 'test/topic' -m 'hello world'

11.windows下客户端

可以下载安装:
mqttx官网

猜你喜欢

转载自blog.csdn.net/ziqibit/article/details/131025805