Mosquitto的配置文件存放在/etc/mosquitto/mosquitto.conf
配置文件具體的配置內容為:
# ================================================================= # General configuration # ================================================================= # 客戶端心跳的間隔時間,當QoS為1或2的消息已經被發送后,mosquitto在一段時間內仍未接收到客戶端的反饋消息,將重新發送消息。 默認為20秒 #retry_interval 20 # 系統狀態的刷新時間,每隔一段時間將更新$SYS層級話題的狀態,其中包含着broker的狀態信息。 默認為10秒,
#設置為0以禁用$ SYS樹的發布。
#sys_interval 10 # 系統資源的回收時間,0表示盡快處理,表示間隔多長時間將不再被使用的消息銷毀掉。該值越小,使用的內存就會越小但會需要更多的處理時間。 如果設置為0,表示不被
#使用的消息將會及時銷毀。 默認為10秒 #store_clean_interval 10 # 服務進程的PID, 默認為/var/run/mosquitto.pid #pid_file /var/run/mosquitto.pid # 服務進程的系統用戶,設置mosquitto啟動用戶 #user mosquitto
#queue_qos0_messages 是否將QoS為0的消息計算到max_queued_messages參數中
# 客戶端心跳消息的最大並發數,表示允許多大數量的QoS為1或2消息被同時進行傳輸處理。這些消息包括正在進行握手的消息和進行重新發送的消息。默認為20個,
#如果設置為0,表示不設限制;如果為1,則會確保消息被順序處理。 #max_inflight_messages 10 # 客戶端心跳消息緩存隊列,表示允許多大數量的QoS為1或2消息在隊列中進行排隊。 默認為100個 #max_queued_messages 100 # 用於設置客戶端長連接的過期時間,默認永不過期,持久訂閱的過期設置。 對於將clean session設置為false的持久訂閱客戶端,如果在一定的時間段里面沒有重新連接mosquitto將會被移除。
#這並不是一個標准的配置項,因為對於MQTT協議來說所有的持久訂閱應該是永遠有效的。
#如: persistent_client_expiration 2m persistent_client_expiration 14d persistent_client_expiration 1y
#h:小時 d:天 m:月 y:年 #persistent_client_expiration # ================================================================= # Default listener # ================================================================= # 服務綁定的IP地址 #bind_address # 服務綁定的端口號 #port 1883 # 允許的最大連接數,-1表示沒有限制 #max_connections -1
#如果一個客戶端訂閱了多個topic時,設置是否允許接收重復的消息。比如訂閱了foo/# 和 foo/+/baz。
#allow_duplicate_messages
# cafile:CA證書文件 # capath:CA證書目錄 # certfile:PEM證書文件 # keyfile:PEM密鑰文件 #cafile #capath #certfile #keyfile # 必須提供證書以保證數據安全性 #require_certificate false # 若require_certificate值為true,use_identity_as_username也必須為true #use_identity_as_username false # 啟用PSK(Pre-shared-key)支持 #psk_hint # SSL/TSL加密算法,可以使用“openssl ciphers”命令獲取 # as the output of that command. #ciphers # ================================================================= # Persistence # ================================================================= # 消息自動保存的間隔時間,表示當開啟持久化設置時,間隔多少時間mosquitto會把內存中的消息保存到磁盤中。默認為30分鍾,當設置為0時,只有mosquitto
#關閉的時候才會寫的磁盤中。 #autosave_interval 1800 # 消息自動保存功能的開關,
#If true, mosquitto will count the number of subscription changes, retained messages received and queued messages and if the total exceeds autosave_interval then the in-memory database
# will be saved to disk. If false, mosquitto will save the in-memory database to disk by treating autosave_interval as a time in seconds #autosave_on_changes false # 持久化功能的開關,設置為true時,所有的連接,訂閱和消息數據都會被保存到磁盤的mosquitto.db文件中。當mosquitto重啟的時候,它會從mosquitto.db文件中
#重新加載數據。 persistence true # 持久化DB文件 #persistence_file mosquitto.db # 持久化DB文件目錄,默認為/var/lib/mosquitto/ #persistence_location /var/lib/mosquitto/ # ================================================================= # Logging # ================================================================= # 4種日志模式:stdout、stderr、syslog、topic # none 則表示不記日志,此配置可以提升些許性能,設置日志的輸出目的地 如果輸出到某個文件的話可以這樣設置log_dest file /var/log/mosquitto.log 要賦予對mosquitto.log文件的讀寫權限。 log_dest none # 選擇日志的級別(可設置多項),日志類型:debug, error, warning, notice, information, subscribe, unsubscribe, websockets, none, all #log_type error #log_type warning #log_type notice #log_type information # 是否記錄客戶端連接信息 #connection_messages true # 是否記錄日志時間, 是否記錄日志時間 #log_timestamp true # ================================================================= # Security # ================================================================= # 客戶端ID的前綴限制,可用於保證安全性,設置只有clientId以某個前綴開始的客戶端才允許連接到mosquitto broker. #clientid_prefixes # 允許匿名用戶 #allow_anonymous true # 用戶/密碼文件,默認格式:username:password #password_file # PSK格式密碼文件,默認格式:identity:key #psk_file # pattern write sensor/%u/data # ACL權限配置,常用語法如下: # 用戶限制:user <username> # 話題限制:topic [read|write] <topic> # 正則限制:pattern write sensor/%u/data #acl_file # ================================================================= # Bridges # ================================================================= # 允許服務之間使用“橋接”模式(可用於分布式部署) #connection <name> #address <host>[:<port>] #topic <topic> [[[out | in | both] qos-level] local-prefix remote-prefix] # 設置橋接的客戶端ID #clientid # 橋接斷開時,是否清除遠程服務器中的消息 #cleansession false # 是否發布橋接的狀態信息 #notifications true # 設置橋接模式下,消息將會發布到的話題地址 # $SYS/broker/connection/<clientid>/state #notification_topic # 設置橋接的keepalive數值 #keepalive_interval 60 # 橋接模式,目前有三種:automatic、lazy、once #start_type automatic # 橋接模式automatic的超時時間 #restart_timeout 30 # 橋接模式lazy的超時時間 #idle_timeout 60 # 橋接客戶端的用戶名 #username # 橋接客戶端的密碼 #password # bridge_cafile:橋接客戶端的CA證書文件 # bridge_capath:橋接客戶端的CA證書目錄 # bridge_certfile:橋接客戶端的PEM證書文件 # bridge_keyfile:橋接客戶端的PEM密鑰文件 #bridge_cafile #bridge_capath #bridge_certfile #bridge_keyfile # 自己的配置可以放到以下目錄中 include_dir /etc/mosquitto/conf.d