CentOS7 内网安装mosquitto

目录

说明:

依赖需求:

安装mosquitto

新增用户

设置用户权限


说明:

        mosquitto是一款实现了消息推送协议 MQTT v3.1 的开源消息代理软件,Mosquitto轻量,适用于低功耗单板计算机到完整服务器的所有设备。Mosquitto项目还提供了用于实现MQTT客户端的C库以及非常受欢迎的mosquitto_pub和mosquitto_sub命令行MQTT客户端。

最近有IOT方向开发的需求,MQTT就选用了mosquitto:

下载地址:Download | Eclipse Mosquitto

依赖需求:

1  gcc gcc-c++ libstdc++-devel
2  openssl-devel
3  c-ares-devel
4  uuid-devel
5  libuuid-devel
6  cJSON

 

具体的依赖可以从RPM resource readline-devel 上查找对应的版本然后上传到堡垒机

通过

cat /proc/version 

此命令可以查看正在运行的内核版本信息。,然后根据信息选择对应的版本

因为涉及到make的指令,所以g++也需要安装。

RPM resource上下载的都是rpm包,使用 rpm -i(-ivh) 进行安装,过程中出现循环依赖可参考:CentOS离线安装gcc(循环依赖、冲突解决) - 知乎

安装mosquitto:

下载源码包:

https://mosquitto.org/files/source/mosquitto-2.0.15.tar.gz.asc

解压包:

tar -zxvf mosquitto-2.0.15.tar.gz

进入包中make:

cd mosquitto-2.0.15
make && make install
cd /etc/mosquitto

复制mosquitto的配置文件:

cp mosquitto.conf.example mosquitto.conf

启动测试:

# 测试启动服务
mosquitto -c /etc/mosquitto/mosquitto.conf
#测试pub 
mosquitto_pub --help

新增用户:

修改mosquitto.conf 配置文件

 3 # into mosquitto (it is recommended that TLS support should be included) then
 4 # plain text passwords are used, in which case the file should be a text file
 5 # with lines in the format:
 6 # username:password
 7 # The password (and colon) may be omitted if desired, although this
 8 # offers very little in the way of security.
 9 #
10 # See the TLS client require_certificate and use_identity_as_username options
11 # for alternative authentication options. If an auth_plugin is used as well as
12 # password_file, the auth_plugin check will be made first.
13 #打开password_file
password_file /etc/mosquitto/pwfile  
创建用户密码
1 mosquitto_passwd -c /etc/mosquitto/pwfile testa 
2 
3 mosquitto_passwd -c /etc/mosquitto/pwfile testb 

重启生效。

设置用户权限:

testa只能订阅/req/#主题、发布/res/#主题,testb正好相反

修改mosquitto.conf:

# The form is the same as for the topic keyword, but using pattern as the
# keyword.
# Pattern ACLs apply to all users even if the "user" keyword has previously
# been given.
#
# If using bridges with usernames and ACLs, connection messages can be allowed
# with the following pattern:
# pattern write $SYS/broker/connection/%c/state
#
# pattern [read|write|readwrite] <topic>
#
# Example:
#
# pattern write sensor/%u/data
#
# If an auth_plugin is used as well as acl_file, the auth_plugin check will be
# made first.
acl_file /etc/mosquitto/aclfile

修改aclfile:

cd /etc/mosquitto
cp aclfile.example aclfile
vi aclfile
 1 # This affects access control for clients with no username.
 2 topic read $SYS/#
 3 
 4 # This only affects clients with username "roger".
 5 user roger
 6 topic foo/bar
 7 
 8 
 9 # This affects all clients.
10 pattern write $SYS/broker/connection/%c/state
11 
12 
13 user testa
14 topic write /req/#
15 topic read /res/#
16 
17 user testb
18 topic read /req/#
19 topic write /res/#

重启生效。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

PigeonEssence

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值