mosquitto-mqtt 安装-配置指南

1.安装外部依赖
1.1 yum 安装依赖
yum install openssl-devel
yum install c-ares-devel
yum install libuuid-devel
yum install gcc*
2.安装mosquitto实例:
2.1 下载tar.gz文件
wget https://mosquitto.org/files/source/mosquitto-1.4.9.tar.gz
2.2 解压
tar -zxvf mosquitto-1.4.9.tar.gz
2.3 进入安装目录
cd mosquitto-1.4.9
2.4 编译
sudo make
sudo make install
2.5 加载.so.1文件
vim /etc/ld.so.conf.d/user.conf
加入内容:
/usr/local/lib
加载以上配置

ldconfig
2.6 更新动态链接库
sudo ldconfig
2.7 增加mosquitto用户
adduser mosquitto
2.8 测试mosquitto安装
启动mosquitto
mosquitto -c mosquitto.conf
3.安装第三方认证插件
3.1 下载tar.gz
wget https://github.com/jpmens/mosquitto-auth-plug/archive/0.1.2.tar.gz
3.2 解压,修改配置
tar -zxvf 0.1.2.tar.gz
cd mosquitto-auth-plug-0.1.2
cp config.mk.in config.mk
3.3 编辑config.mk指定开启redis,mosquitto源码目录
vim config.mk
修改如下配置项:
BACKEND_MYSQL ?= no
BACKEND_REDIS ?= yes
BACKEND_HTTP ?= yes
注:此处需要依赖http 相关的库 需要添加
MOSQUITTO_SRC = /usr/local/mosquitto-env/mosquitto-1.4.9/src

3.4 编译
make
3.5 mosquitto目录下创建plugin目录
mkdir plugin
3.6 将插件中的.so文件复制到plugin目录下
cp auth-plug.so mosquitto/plugin
3.7 修改mosquitto的配置文件
vim mosquitto.conf
修改如下配置项
allow_anonymous false
在这一行下新增
auth_plugin /usr/local/mqtt/mosquitto-1.4.9/plugin/auth-plug.so
#redis 使用这个配置
#auth_opt_backends redis
#auth_opt_redis_host 192.168.120.203
#auth_opt_redis_port 6379
#auth_opt_redis_userquery GET %s

#http 验证使用这个
auth_opt_backends http
auth_opt_http_ip 192.168.120.94
auth_opt_http_port 3015
#auth_opt_http_hostname example.org
auth_opt_http_getuser_uri /awifi/mqtt/auth
auth_opt_http_superuser_uri /awifi/mqtt/superuser
auth_opt_http_aclcheck_uri /awifi/mqtt/acl

三个uri 返回的数据均为
/**
* 用户名
*/
private String username ;

/**
* 密码
*/
private String password ;

/**
* 主题
*/
private String topic;

/**
*1 == SUB, 2 == PUB
*/
private String acc;

/**
*客户端id
**/
private String clientid;

请求方式为POST

URI-Paramusernamepasswordclientidtopicacc
http_getuser_uriYYNNN
http_superuser_uriYNNNN
http_aclcheck_uriYNYYY


详细案例参考


## 相关注意事项

## 功能验证建议
1.根据如下url下载不同操作系统下的mosquitto图形化客户端工具
https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org.eclipse.paho.ui.app/1.1.1/
2. 新建连接
连接地址:tcp://url:port(默认端口为1883)
输入用户名密码 admin admin 该用户名密码在 http服务中校验
连接,连接成功即完成搭建
或者使用mosquitto订阅命令:
mosquitto_sub -h 192.168.212.177 -p 1884 -t test -u admin -P admin
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值