一、安装

1、下载mosquitto安装包

地址:http://mosquitto.org/files/source/

2、安装依赖包

yum install gcc gcc-c++ libstdc++-devel 

yum install openssl-devel -y

yum install c-ares-devel -y

yum install uuid-devel -y

yum install libuuid-devel -y

yum install c-ares-devel

3、编译并安装

解压下载的安装包:tar zxvf mosquitto-2.0.10.tar.gz

进入解压后的文件夹:cd mosquitto-2.0.10

执行命令:make && make install

4、安装后进入 /etc/mosquitto中,复制配置文件

cp mosquitto.conf.example mosquitto.conf

5、启动

mosquitto -c /etc/mosquitto/mosquitto.conf

//后台启动
mosquitto -c /etc/mosquitto/mosquitto.conf -d

6、关闭,kill进程

ps -aux | grep mosquitto
kill -9 2438

至此安装mosquitto完毕!

二、设置用户密码

1、打开配置文件为/etc/mosquitto/mosquitto.conf

配置如下 :

listener 1883  //配置允许外部访问的端口设置
allow_anonymous false //配置不允许匿名访问,需输入账号密码才可订阅或者发布
password_file /etc/mosquitto/pwfile.example //配置账号密码存放的路径

2、设置用户密码

命令如下:

mosquitto_passwd /etc/mosquitto/pwfile.example 用户名

回车后,按照提示输入两次密码即可!

3、用户测试验证

启动 mosquitto:

mosquitto -c /etc/mosquitto/mosquitto.conf

(订阅端)客户端启动:

mosquitto_sub -h 地址 -t 主题 -u 用户名 -P 密码

(发布者)客户端启动:

mosquitto_pub -h 地址 -t 主题 -u 用户名 -P 密码 -m 发布内容

三、补充问题

编译问题

1、fatal error: cjson/cJSON.h: No such file or directory



解决:需要安装cJSON(这里cJSON的安装,yum和apt不一定能找到,可以直接从github上下载源码压缩包,然后解压,进入目录,并make,make install)

启动订阅客户端问题

1、error while loading shared libraries: libmosquitto.so.1: cannot open shared object file: No such file or directory

解决:执行以下命令:

sudo ln -s /usr/local/lib/libmosquitto.so.1 /usr/lib/libmosquitto.so.1
ldconfig

2、error while loading shared libraries: libcjson.so.1: cannot open shared object file: No such file or directory



解决:

方法1:

编辑/etc/ld.so.conf文件,在新的一行中加入库文件所在目录(/usr/local/lib);

运行ldconfig,以更新/etc/ld.so.cache文件;

方法2:

在/etc/ld.so.conf.d/目录下新建任何以.conf为后缀的文件(touch mqtt.conf),在该文件中加入库文件所在的目录;

运行ldconfig,以更新/etc/ld.so.cache文件;

3、Warning: Unable to drop privileges to 'mosquitto' because this user does not exist. Trying 'nobody' instead.

解决:

在allow_anonymous 前面加一个 user root

user root
allow_anonymous false

或者创建mosquitto用户和组

groupadd mosquitto
useradd -g mosquitto mosquitto
chown -R mosquitto:mosquitto /etc/mosquitto/

四、参考以下文章

https://www.cnblogs.com/chen1-kerr/p/7258487.html

https://www.cnblogs.com/IC1101/p/14749722.html

https://blog.csdn.net/u012377333/article/details/69397124

https://www.cnblogs.com/x_wukong/p/4722903.html

https://blog.csdn.net/houjixin/article/details/46711547

MQTT服务器搭建——Liunx安装mosquitto,并设置用户密码的更多相关文章

  1. 常见MQTT服务器搭建与试用

    常见MQTT服务器搭建与试用   简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠 ...

  2. 个人智能家居系统 - MQTT服务器搭建(centOS7.3)

    个人智能家居系统 - MQTT服务器搭建(centOS7.3) 0x00 参考 在CentOS7 上安装mosquitto1.4.1服务器,实现MQTT信息推送功能并增加websocket功能 mos ...

  3. Mqtt服务器搭建

    .bg { background: #99CC99 } Mqtt服务器搭建 测试环境:CentOS64位 1.安装基础软件 yum install gcc-c++ yum install cmake ...

  4. 服务器搭建--Linux安装rabbitmq

    安装rabbitmq需要先安装erlang:安装erlang参考https://blog.csdn.net/ztx114/article/details/79912570 1.下载rabbitmq-s ...

  5. 服务器搭建--Linux安装erlang

    1.安装依赖环境: 1)安装GCC GCC-C++ Openssl等模块,安装过就不需要安装了 yum -y install make gcc gcc-c++ kernel-devel m4 ncur ...

  6. MariaDB数据库设置用户密码

    SET PASSWORD [FOR user] = { PASSWORD('some password') | OLD_PASSWORD('some password') | 'encrypted p ...

  7. MQTT服务器搭建--Mosquitto用户名密码配置

    Mosquitto用户认证配置 前言:基于Mosquitto服务器已经搭建成功,大部分都是采用默认的是允许匿名用户登录模式,正式上线的系统需要进行用户认证. 1.用户参数说明 Mosquitto服务器 ...

  8. 常见MQTT服务器搭建[转载]

    简介 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输)是IBM开发的一个即时通讯协议,它比较适合于在低带宽.不可靠的网络的进行远程传感器和控制设备通 ...

  9. Apollo mqtt 服务器搭建

    html { overflow-x: initial !important } :root { --bg-color: #ffffff; --text-color: #333333; --select ...

  10. MQTT服务器搭建-mosquitto1.4.4安装指南

    Mosquitto mosquitto是一款实现了 MQTT v3.1 协议的开源的消息代理服务软件. 其提供了非常轻量级的消息数据传输协议,采用发布/订阅模式进行工作,可用于物联设备.中间件.APP ...

随机推荐

  1. pj_0001_compare_col_csv

    #!/usr/bin/python# -*- coding: UTF-8 -*- import pathlibimport pandas as pd print("please input ...

  2. cgroup和Linux Namespace基础操作

    一.开头 接触过docker的同学多多少少听过这样一句话"docker容器通过linux namespace.cgroup特性实现资源的隔离与限制".今天我们来尝试学习一下这两个东 ...

  3. linux中用命令导出、导入mysql数据库表

    一.导出数据 1.使用场景:在没有数据库可视化工具的情况下备份导出数据库. 命令如下: mysqldump -u用户名 -p 数据库名 > 数据库名.sql mysqldump -u root ...

  4. java位运算分析

    java位运算 java位运算在平常的编码过程中十分场景,通常框架都替我们封装好了,我对于细节方面反而一知半解,下面就重新梳理一下. 优秀的框架使得我们轻松,也使得我们距离真相越来越远. 位运算种类 ...

  5. 《ImageNet Classification with Deep Convolutional Neural Networks (AlexNet)2012》

    Abstract 作者训练了一个大型的深度卷积神经网络,用于在 ImageNet LSVRC-2010 比赛中对120万张高分辨率图像分为1000个不同的类别.在测试数据上,作者们达到了 top-1 ...

  6. Jupyter 快捷键1

    Jupyter Notebook 有两种键盘输入模式.编辑模式,允许你往单元中键入代码或文本:这时的单元框线是绿色的.命令模式,键盘输入运行程序命令:这时的单元框线是灰色. 命令模式 (按键 Esc ...

  7. 面试官:来说说 https 和 http 区别?

    http 和 https的区别? 一.传输信息安全性不同 1.http协议:是超文本传输协议,信息是明文传输.如果攻击者截取了Web浏览器和网站服务器之间的传输报文,就可以直接读懂其中的信息. 2.h ...

  8. vue element-ui form验证中自定义验证方式通过不返回true问题

    项目中使用了element-ui的form验证,自定义了手机号的验证规则,验证不通过的时候定义了callback()扔出错误.但是忘了写通过的callback().导致form验证通过拿不到返回的va ...

  9. 如何把高德地图搜索结果导出成excel里?

    前段时间,根据朋友的要求,开发了百度地图里的商家采集工具. 最近,又开发了腾讯地图里的商家采集工具. 来了兴致,干脆把高德地图的采集工具也一并搞定!:) 原理应该差不多,我就查阅了下高德地图的采集规则 ...

  10. Java-面向对象进阶 方法继承、重写

    1.继承 子类继承父类后自动拥有父类非私有的属性和方法 Java中,一个父类可以被多个子类继承,一个子类只能继承一个父类 除了继承父类的属性和方法外,子类还拥有自己特有的属性和方法 如果子类的方法与父 ...