Mac 下 Mosquitto 安裝和配置 (Mosquitto為開源的mqtt服務器)


官網:http://mosquitto.org/download/

官網的介紹簡單明了

Mac 下一個命令“brew install mosquitto” 安裝成功了,還學會了brew偷笑

安裝目錄:/usr/local/Cellar/mosquitto/1.3.5 安裝自動完成了。
接下來就是配置,把 shagoo大師的成果直接搬過來了

 

找到 /usr/local/Cellar/mosquitto/1.3.5 /etc/mosquitto/mosquitto.conf ,打開這個文件,就可以對服務器進行相關配置

 

[objc]  view plain  copy
 
  1. # =================================================================    
  2. # General configuration    
  3. # =================================================================    
  4.     
  5. # 客戶端心跳的間隔時間    
  6. #retry_interval 20    
  7.     
  8. # 系統狀態的刷新時間    
  9. #sys_interval 10    
  10.     
  11. # 系統資源的回收時間,0表示盡快處理    
  12. #store_clean_interval 10    
  13.     
  14. # 服務進程的PID    
  15. #pid_file /var/run/mosquitto.pid    
  16.     
  17. # 服務進程的系統用戶    
  18. #user mosquitto    
  19.     
  20. # 客戶端心跳消息的最大並發數    
  21. #max_inflight_messages 10    
  22.     
  23. # 客戶端心跳消息緩存隊列    
  24. #max_queued_messages 100    
  25.     
  26. # 用於設置客戶端長連接的過期時間,默認永不過期    
  27. #persistent_client_expiration    
  28.     
  29. # =================================================================    
  30. # Default listener    
  31. # =================================================================    
  32.     
  33. # 服務綁定的IP地址    
  34. #bind_address    
  35.     
  36. # 服務綁定的端口號    
  37. #port 1883    
  38.     
  39. # 允許的最大連接數,-1表示沒有限制    
  40. #max_connections -1    
  41.     
  42. # cafile:CA證書文件    
  43. # capath:CA證書目錄    
  44. # certfile:PEM證書文件    
  45. # keyfile:PEM密鑰文件    
  46. #cafile    
  47. #capath    
  48. #certfile    
  49. #keyfile    
  50.     
  51. # 必須提供證書以保證數據安全性    
  52. #require_certificate false    
  53.     
  54. # 若require_certificate值為true,use_identity_as_username也必須為true    
  55. #use_identity_as_username false    
  56.     
  57. # 啟用PSK(Pre-shared-key)支持    
  58. #psk_hint    
  59.     
  60. # SSL/TSL加密算法,可以使用“openssl ciphers”命令獲取    
  61. # as the output of that command.    
  62. #ciphers    
  63.     
  64. # =================================================================    
  65. # Persistence    
  66. # =================================================================    
  67.     
  68. # 消息自動保存的間隔時間    
  69. #autosave_interval 1800    
  70.     
  71. # 消息自動保存功能的開關    
  72. #autosave_on_changes false    
  73.     
  74. # 持久化功能的開關    
  75. persistence true    
  76.     
  77. # 持久化DB文件    
  78. #persistence_file mosquitto.db    
  79.     
  80. # 持久化DB文件目錄    
  81. #persistence_location /var/lib/mosquitto/    
  82.     
  83. # =================================================================    
  84. # Logging    
  85. # =================================================================    
  86.     
  87. # 4種日志模式:stdout、stderr、syslog、topic    
  88. # none 則表示不記日志,此配置可以提升些許性能    
  89. log_dest none    
  90.     
  91. # 選擇日志的級別(可設置多項)    
  92. #log_type error    
  93. #log_type warning    
  94. #log_type notice    
  95. #log_type information    
  96.     
  97. # 是否記錄客戶端連接信息    
  98. #connection_messages true    
  99.     
  100. # 是否記錄日志時間    
  101. #log_timestamp true    
  102.     
  103. # =================================================================    
  104. # Security    
  105. # =================================================================    
  106.     
  107. # 客戶端ID的前綴限制,可用於保證安全性    
  108. #clientid_prefixes    
  109.     
  110. # 允許匿名用戶    
  111. #allow_anonymous true    
  112.     
  113. # 用戶/密碼文件,默認格式:username:password    
  114. #password_file    
  115.     
  116. # PSK格式密碼文件,默認格式:identity:key    
  117. #psk_file    
  118.     
  119. # pattern write sensor/%u/data    
  120. # ACL權限配置,常用語法如下:    
  121. # 用戶限制:user <username>    
  122. # 話題限制:topic [read|write] <topic>    
  123. # 正則限制:pattern write sensor/%u/data    
  124. #acl_file    
  125.     
  126. # =================================================================    
  127. # Bridges    
  128. # =================================================================    
  129.     
  130. # 允許服務之間使用“橋接”模式(可用於分布式部署)    
  131. #connection <name>    
  132. #address <host>[:<port>]    
  133. #topic <topic> [[[out | in | both] qos-level] local-prefix remote-prefix]    
  134.     
  135. # 設置橋接的客戶端ID    
  136. #clientid    
  137.     
  138. # 橋接斷開時,是否清除遠程服務器中的消息    
  139. #cleansession false    
  140.     
  141. # 是否發布橋接的狀態信息    
  142. #notifications true    
  143.     
  144. # 設置橋接模式下,消息將會發布到的話題地址    
  145. # $SYS/broker/connection/<clientid>/state    
  146. #notification_topic    
  147.     
  148. # 設置橋接的keepalive數值    
  149. #keepalive_interval 60    
  150.     
  151. # 橋接模式,目前有三種:automatic、lazy、once    
  152. #start_type automatic    
  153.     
  154. # 橋接模式automatic的超時時間    
  155. #restart_timeout 30    
  156.     
  157. # 橋接模式lazy的超時時間    
  158. #idle_timeout 60    
  159.     
  160. # 橋接客戶端的用戶名    
  161. #username    
  162.     
  163. # 橋接客戶端的密碼    
  164. #password    
  165.     
  166. # bridge_cafile:橋接客戶端的CA證書文件    
  167. # bridge_capath:橋接客戶端的CA證書目錄    
  168. # bridge_certfile:橋接客戶端的PEM證書文件    
  169. # bridge_keyfile:橋接客戶端的PEM密鑰文件    
  170. #bridge_cafile    
  171. #bridge_capath    
  172. #bridge_certfile    
  173. #bridge_keyfile    

最后,啟動Mosquitto服務很簡單,直接運行命令行“mosquitto -c /usr/local/Cellar/mosquitto/1.3.5/etc/mosquitto/mosquitto.conf -d”即可開啟服務

如果沒有將命令添加到環境變量就需要到sbin目錄下執行以上命令。
我當前的版本是:/usr/local/Cellar/mosquitto/1.3.5/sbin

命令為:./mosquitto -c /usr/local/Cellar/mosquitto/1.3.5/etc/mosquitto/mosquitto.conf -d

 

如果不想用命令啟動的話,也可以直接進入/usr/local/Cellar/mosquitto/1.3.5/sbin 目錄下,點擊相應的腳本執行文件,就會自動啟動,如果要想退出的話,需要到活動監視器里面強制退出,如果只是關閉終端窗口,程序並沒有真正的退出。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM