Files
chakcy 9dc2dde59f
tests / ubuntu-latest / py3.13 (push) Has been cancelled
tests / windows-latest / py3.13 (push) Has been cancelled
tests / ubuntu-latest / py3.13 (pull_request) Has been cancelled
tests / windows-latest / py3.13 (pull_request) Has been cancelled
modify: 消息模块
2026-09-17 11:23:34 +08:00

63 lines
3.4 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# svfs 消息模块用的 mosquitto 配置(挂到容器的 /mosquitto/config/mosquitto.conf)。
#
# 默认这份是「内网匿名」:能立刻跑起来,但任何能连到 1883 的人都能收发消息,
# 只适合内网/开发。下面另有「认证 + ACL」与「TLS」两个注释段,要用时解开,
# 完整说明(含客户端怎么配)见 docs/mqtt-guide.md 的「二、Docker 部署 broker」。
# ---- 监听与放行 ------------------------------------------------------
#
# mosquitto 2.x 的规矩:一旦定义了 listener,allow_anonymous 的默认值就是
# false——不显式写这一行,客户端会被直接拒连("能连上端口却连不上 broker"
# 的典型来源)。同理,不定义 listener 时只接受 loopback 连接。
listener 1883
allow_anonymous true
# ---- 数据与日志 ------------------------------------------------------
#
# 本模块实际用的是 QoS 0 + clean session(见 docs/mqtt-guide.md),持久化本身
# 帮不上什么忙;留着它只是为了以后调 QoS、用 retained 消息时不用回头改配置。
persistence true
persistence_location /mosquitto/data/
# 同时往 stdout 和文件写:compose logs 看实时,./log 留档。
log_dest stdout
log_dest file /mosquitto/log/mosquitto.log
log_type all
# ---- 认证 + ACL(可选,生产该开) ------------------------------------
#
# 要开认证,按顺序做三件事:
# 1) 造密码文件(用户名就用 svfs 的登录名,客户端默认拿它当 broker 用户名):
# docker compose exec mqtt mosquitto_passwd -c -b /mosquitto/config/passwd alice 密码
# docker compose exec mqtt mosquitto_passwd -b /mosquitto/config/passwd svfs-server 服务端密码
# (-c 会覆盖已有文件,之后加用户不要再带 -c;Linux 上宿主的 config/ 目录
# 属主不是 uid 1883 时会写不进去,先 sudo chown -R 1883:1883 config)
# 2) 客户端侧准备 broker 密码:它的默认值是**登录 token**,和这里的静态密码
# 对不上,连接会被拒(CONNACK code=4/5)。两条路:
# * 在客户端 settings.json 里写 mqtt_password(见 docs/mqtt-guide.md 三);
# * 或由服务端在登录响应里下发 mqtt.password(推荐,用户端零配置)。
# 3) 解开下面三行,重启容器。
#
# allow_anonymous false
# password_file /mosquitto/config/passwd
# acl_file /mosquitto/config/acl
#
# 注意:开了认证之后示例服务端(examples/plugin_server.py)也会连不上——
# 它的 _mqtt_publish 不带 broker 账号,得给它加 SVFS_MQTT_USER/SVFS_MQTT_PASS
# 的几行补丁,或让它用独立的发布账号(docs/mqtt-guide.md 有现成代码)。
# ---- TLS(可选) -----------------------------------------------------
#
# 解开这段起 8883,同时把 compose 里的 8883 端口映射打开。
# 证书放进 config/certs/(.gitignore 已挡住),容器内路径就是 /mosquitto/config/certs/…。
#
# 重要:客户端只做「系统信任库 + CERT_REQUIRED」校验,没有单独的 CA 配置项
# (设置里的 ca_bundle 只作用于 HTTP)。所以自签证书必须把 CA 装进**每台
# 客户端的系统信任库**,否则握手一定失败——内网先用明文 1883 往往更省事。
#
# listener 8883
# allow_anonymous false
# cafile /mosquitto/config/certs/ca.crt
# certfile /mosquitto/config/certs/server.crt
# keyfile /mosquitto/config/certs/server.key