MQTT 学习二 CentOS下安装 mosquitto

前端之家收集整理的这篇文章主要介绍了MQTT 学习二 CentOS下安装 mosquitto前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

安装

#yum install gcc gcc-c++
#yum install openssl-devel
#yum install c-ares-devel
#yum install libuuid-devel
wget http://mosquitto.org/files/source/mosquitto-1.4.5.tar.gz
@H_502_28@#tar -zxvf mosquitto-1.4.5.tar.gz
@H_502_28@#cd mosquitto-1.4.5
@H_502_28@#make
@H_502_28@#make install

修改配置文件

在/etc/mosquitto/mosquitto.conf

autosave_interval 1800
persistence true
persistence_file mosquitto.db
persistence_location /var/mosquitto/
persisitent_client_expiration 1d
port 1883

配置的一些说明:

@H_502_28@# 服务进程的PID
@H_502_28@#pid_file /var/run/mosquitto.pid

@H_502_28@# 服务进程的系统用户
@H_502_28@#user mosquitto

@H_502_28@# 服务绑定的IP地址
@H_502_28@#bind_address

@H_502_28@# 服务绑定的端口号
@H_502_28@#port 1883

@H_502_28@# 允许的最大连接数,-1表示没有限制
@H_502_28@#max_connections -1

@H_502_28@# 允许匿名用户
@H_502_28@#allow_anonymous true

启动

groupadd mosquitto
useradd -g mosuqitto mosquiotto

cd /usr/local/sbin
./mosquitto -v

指定配置文件位置

mosquitto -c /etc/mosquitto/mosquitto.conf -d

设置客户端

vim /etc/ld@H_502_28@.so@H_502_28@.conf@H_502_28@.d/liblocal@H_502_28@.conf
/usr/local/lib64
/usr/local/lib

//刷新
ldconfig

测试

新建两个shell端口A/B

订阅主题

mosquitto_sub -t location

推送消息:

mosquitto_pub -t location -h localhost -m “new location”

可以在A窗口看到由B推送的消息,此外服务端窗口也可以看到客户端连接和端口的日志

程序安装位置

路径 程序文件
/usr/local/sbin mosquiotto server
/etc/mosquitto configuration
/usr/local/bin utility command

猜你在找的CentOS相关文章