版本说明:

Mosquitto版本:v2.0.10

    libwebsockets版本:v3.0.1(用于支持websockets)

    mosquitto-go-auth(Mosquitto plugin):v1.50(提供权限认证)

1.编译前准备

因为我们准备本机编译源码包,所以要提前安装gcc

yum -y install gcc-c++ cmake 

还有一些三方依赖

yum install openssl-devel
yum install libuuid-devel
yum install c-ares-devel
yum install uuid-devel
yum install libwebsockets-devel.x86_64
yum install libwebsockets.x86_64

2.下载Mosquitto源码

官网下载Mosquitto源码压缩包, 或者从github上下载也是可以的, 我这里使用的版本2.0.10

3.解压并安装Mosquitto

Mosquitto默认是不支持websockets的,要在编译前修改config.mk,WITH_WEBSOCKETS:=yes,把no改为yes

    执行makemake install

如果遇到fatal error: cjson/cJSON.h: No such file or directory报错,那么要提前安装cJSON(这里cJSON的安装,yum和apt不一定能找到,可以直接从github上下载源码压缩包,然后解压,进入目录,并makemake install), 这是当前版本的bug,后期应该会修复吧;

安装完成之后,添加名称为mosquitto的用户,并将相关文件夹授权给mosquitto用户

sudo groupadd mosquitto
sudo useradd -s /sbin/nologin mosquitto -g mosquitto -d /var/lib/mosquitto
sudo mkdir -p /var/log/mosquitto/ /var/lib/mosquitto/
sudo chown -R mosquitto:mosquitto /var/log/mosquitto/
sudo chown -R mosquitto:mosquitto /var/lib/mosquitto/

创建/etc/systemd/system/mosquitto.service文件

[Unit]
Description=Mosquitto MQTT v3.1/v3.1.1 server
Wants=network.target
Documentation=http://mosquitto.org/documentation/ [Service]
Type=simple
User=mosquitto
Group=mosquitto
ExecStart=/usr/local/sbin/mosquitto -c /etc/mosquitto/mosquitto.conf
Restart=on-failure
SyslogIdentifier=Mosquitto [Install]
WantedBy=multi-user.target

设置开机启动

sudo systemctl enable mosquitto

4.解压并安装Mosquitto auth插件

我安装的是mosquitto-go-auth插件,因为是go语言写的插件,所以要提前安装golang,建议同时设置go的代理go env -w GOPROXY=https://mirrors.aliyun.com/goproxy,编译后得到go-auth.so插件

5.配置mosquitto

修改/etc/mosquitto/mosquitto.conf

per_listener_settings true

include_dir /etc/mosquitto/conf

persistence true

persistence_location /var/lib/mosquitto/

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

#password_file /etc/mosquitto/pwfile

#acl_file /etc/mosquitto/aclfile

log_timestamp true

log_timestamp_format %Y-%m-%dT%H:%M:%S

log_type all

创建/etc/mosquitto/conf文件夹,并将go-auth.so插件移入,创建go-auth-mqtt.conf配置文件,go-auth-websockets.conf配置文件,分别对应mqtt协议,websockets协议



go-auth-mqtt.conf配置

listener 18883

protocol mqtt

connection_messages true

socket_domain ipv4

allow_anonymous false

auth_plugin /etc/mosquitto/conf/go-auth.so

auth_opt_backends mysql

auth_opt_cache true
auth_opt_cache_type redis
auth_opt_cache_reset true
auth_opt_cache_refresh true auth_opt_auth_cache_seconds 30
auth_opt_acl_cache_seconds 30
auth_opt_auth_jitter_seconds 3
auth_opt_acl_jitter_seconds 3 auth_opt_cache_host XX.X.X.XXX
auth_opt_cache_port 6379
auth_opt_cache_password yourpassword
auth_opt_cache_db 3 auth_opt_hasher pbkdf2 auth_opt_hasher_salt_size 16 # salt bytes length
auth_opt_hasher_iterations 100000 # number of iterations
auth_opt_hasher_keylen 64 # key length
auth_opt_hasher_algorithm sha512 # hashing algorithm, either sha512 (default) or sha256
auth_opt_hasher_salt_encoding base64 # salt encoding, either base64 (default) or utf-8 auth_opt_log_level debug auth_opt_log_dest file
auth_opt_log_file /var/log/mosquitto/mosquitto_auth.log auth_opt_retry_count 2 #根据名称前缀匹配验证方式
auth_opt_check_prefix false auth_opt_disable_superuser false auth_opt_mysql_allow_native_passwords true
auth_opt_mysql_host mysqlhostaddress
auth_opt_mysql_port 3306
auth_opt_mysql_user mqtt
auth_opt_mysql_password mysqlpassword
auth_opt_mysql_dbname mqtt
auth_opt_mysql_userquery SELECT password_hash FROM mqtt_user WHERE username = ? limit 1
auth_opt_mysql_superquery SELECT COUNT(*) FROM mqtt_user WHERE username = ? AND is_admin = 1
auth_opt_mysql_aclquery SELECT topic FROM mqtt_acl WHERE (username = ?) AND (rw = ? OR rw = 3)

go-auth-websockets.conf配置

listener 18884

protocol websockets

connection_messages true

socket_domain ipv4

allow_anonymous false

auth_plugin /etc/mosquitto/conf/go-auth.so

auth_opt_backends jwt

auth_opt_jwt_mode remote
auth_opt_jwt_parse_token false
auth_opt_jwt_userfield username auth_opt_jwt_host jwtauthserverhost
auth_opt_jwt_port 80
auth_opt_jwt_getuser_uri /op/unauthorized
auth_opt_jwt_superuser_uri /op/unauthorized
auth_opt_jwt_aclcheck_uri /op/unauthorized
auth_opt_jwt_response_mode status
auth_opt_jwt_params_mode json
auth_opt_jwt_with_tls false
auth_opt_jwt_verify_peer false auth_opt_cache true
auth_opt_cache_type redis
auth_opt_cache_reset true
auth_opt_cache_refresh true auth_opt_auth_cache_seconds 30
auth_opt_acl_cache_seconds 30
auth_opt_auth_jitter_seconds 3
auth_opt_acl_jitter_seconds 3 auth_opt_cache_host redishostaddress
auth_opt_cache_port 6379
auth_opt_cache_password redispassword
auth_opt_cache_db 3 auth_opt_log_level debug auth_opt_log_dest file
auth_opt_log_file /var/log/mosquitto/mosquitto_auth.log auth_opt_retry_count 2 #根据名称前缀匹配验证方式
auth_opt_check_prefix false auth_opt_disable_superuser false

Mosquitto安装与部署的更多相关文章

  1. MQTT入门1 -- mosquitto 安装

    原文链接:https://www.cnblogs.com/NickQ/p/9247638.html MQTT入门1 -- mosquitto 安装 简介: MQTT(Message Queuing T ...

  2. MQTT的学习之Mosquitto安装&使用(1)

    Mosquitto是一个实现了MQTT3.1协议的代理服务器,由MQTT协议创始人之一的Andy Stanford-Clark开发,它为我们提供了非常棒的轻量级数据交换的解决方案.本文的主旨在于记录M ...

  3. Mac 下 Mosquitto 安装和配置 (Mosquitto为开源的mqtt服务器)

    官网:http://mosquitto.org/download/ 官网的介绍简单明了 Mac 下一个命令“brew install mosquitto” 安装成功了,还学会了brew 安装目录:/u ...

  4. MQTT的学习之Mosquitto安装和使用

    Mosquitto是一个实现了MQTT3.1协议的代理服务器,由MQTT协议创始人之一的Andy Stanford-Clark开发,它为我们提供了非常棒的轻量级数据交换的解决方案.本文的主旨在于记录M ...

  5. Windows Server 2012 虚拟化实战:SCVMM的安装和部署

    本篇大概介绍一下在Windows Server 2012 R2上安装和部署SCVMM的过程及其注意事项.下图是我们数据中心SCVMM的基本架构,其中 SCVMM Database 是用于存储了所有配置 ...

  6. Linux下Redis的安装和部署

    一.Redis介绍 Redis是当前比较热门的NOSQL系统之一,它是一个key-value存储系统.和Memcache类似,但很大程度补偿了Memcache的不足,它支持存储的value类型相对更多 ...

  7. 他山之石——vs2013 安装与部署及程序打包

    C#打包需要这个:InstallShield 2013 Limited Edition for Visual Studio  .下载地址: InstallShield 2013 Limited Edi ...

  8. 阿里云服务器Linux CentOS安装配置(六)resin多端口配置、安装、部署

    阿里云服务器Linux CentOS安装配置(六)resin多端口配置.安装.部署 1.下载resin包 http://125.39.66.162/files/2183000003E08525/cau ...

  9. Kafka的安装和部署及测试

    1.简介 大数据分析处理平台包括数据的接入,数据的存储,数据的处理,以及后面的展示或者应用.今天我们连说一下数据的接入,数据的接入目前比较普遍的是采用kafka将前面的数据通过消息的方式,以数据流的形 ...

  10. Redis的安装与部署

    为了解决公司产品数据增长过快,初始化太耗费时间的问题,决定使用redis作为缓存服务器. Windows下的安装与部署: 可以直接参考这个文章,我也是实验了一遍:http://www.runoob.c ...

随机推荐

  1. zookeeper要点总结

    简述:zookeeper分布式协调服务,节点数据存储在内存,高吞吐,低延时,zkserver cluster组建zookeeper service保证自身高可用 zookeeper数据模型为类文件目录 ...

  2. DataTransfer.setDragImage()自定义拖拽图像遇到的坑

    发生拖动时,从拖动目标(dragstart事件触发的元素)生成半透明图像,并在拖动过程中跟随鼠标指针.这个图片是自动创建的,你不需要自己去创建它.然而,如果想要设置为自定义图像,那么 DataTran ...

  3. win10bug可导致系统崩溃

    1.使用浏览器访问访问路径:\\.\globalroot\device\condrv\kernelconnect会立刻导致系统崩溃.会影响Windows10 1709及以上版本 2.使用以下代码保存成 ...

  4. Python: 取消numpy科学计数法

    Numpy中默认是使用科学计数法来显示数据的,但是这种做法往往不利于我们观测数据,比如坐标数据等.那么如何取消numpy科学计数法呢,请往下看. np.set_printoptions() impor ...

  5. 监控平台prometheus+grafana+snmp_explorer+blackbox_exporter+alertmanager

    一.背景介绍 公司需要监控交换机和IP设备,能够放在展示屏幕,及时发出告警信息.网上有很多监控软件,prometheus系列已经能够满足我们需求.prometheus功能强大,本次只用到一部功能.咱们 ...

  6. 深度学习PyTorch入门(1):3060 Pytorch+pycharm环境搭建

    WIN10, NVIDIA GeForce RTX 3060 python 3.7, CUDAv11.1.1, PyTorch 1.9, PyCharm 1.安装anacodah和PyCharm:   ...

  7. 西湖论剑2023-mp3[wp]

    一 题目描述 二 解题步骤 1.分析文件 (1)放入Audacity中查看频谱信息无果 (2)010editor中查看文件结构 文件尾部存在PNG文件尾,搜索png文件头 将该png文件复制提取出来, ...

  8. leecode70. 爬楼梯

    70. 爬楼梯 假设你正在爬楼梯.需要 n 阶你才能到达楼顶. 每次你可以爬 1 或 2 个台阶.你有多少种不同的方法可以爬到楼顶呢? 示例 1: 输入:n = 2 输出:2 解释:有两种方法可以爬到 ...

  9. ElementUI Select下拉框定位问题!

    今天遇到了下拉不跟随文本框滚动的问题 参考官方手册添加参数: popper-append-to-body="false" 无效[内心很无语]继续检查向上推,查看html样式,发现了 ...

  10. 移动自动化-swipe、scroll、drag、高级手势等

    swipe 滑动事件 使用方法:driver.swipe(strat_x,start_y,end_x,end_y) swipe通过driver使用 传入起始的位置x和y,和结束的位置x和y 时间参数, ...