mosquitto.conf
mosquitto.conf是mosquitto的配置檔案,
# Config file for mosquitto
# =================================================================
# General configuration
# =================================================================
per_listener_settings false
allow_zero_length_clientid false
check_retain_source false
max_inflight_messages 20
max_keepalive 60
persistent_client_expiration 1w
retain_available true
sys_interval 3600
listener 1883 0.0.0.0
# bind_address 127.0.0.1
# =================================================================
# Persistence
# =================================================================
persistence false
# =================================================================
# Security
# =================================================================
allow_anonymous false
password_file /etc/mosquitto/pwfile.example
acl_file /etc/mosquitto/aclfile.example
# =================================================================
# Debug configuration
# =================================================================
# log_dest file /var/log/mosquitto.log
# log_dest none
# log_type error
# log_type warning
# log_type notice
# log_type information
# connection_messages true
# log_timestamp true
# log_timestamp_format %Y-%m-%dT%H:%M:%S
# max_keepalive 5
# sys_interval 10
pwfile.example
設定使用者名稱和密碼,若客戶端登入時,提供的使用者名稱和密碼不匹配,將無法連線mosquitto broker。
安裝mosquitto時,附帶安裝了mosquitto_passwd,使用者建立使用者的可執行檔案。
建立兩個使用者,分別是:admin和mosquitto
建立第一個使用者admin:sudo mosquitto_passwd -c /etc/mosquitto/pwfile.example admin
建立第二個使用者mosquitto:sudo mosquitto_passwd /etc/mosquitto/pwfile.example mosquitto
(注意:建立第二個使用者時,不需要引數-c。若新增了引數-c,那麼第一個使用者會被第二個使用者覆蓋)
aclfile.example
可以限制指定使用者對主題的釋出或訂閱許可權。
例如:使用者admin可以對 device/1001
釋出,對 room/#
訂閱。使用者mosquitto可以對 #
釋出和訂閱。
user admin
topic write device/1001
topic read room/#
user mosquitto
topic readwrite #