官网: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 目录下,点击相应的脚本执行文件,就会自动启动,如果要想退出的话,需要到活动监视器里面强制退出,如果只是关闭終端窗口,程序并没有真正的退出。

posted on 2018-03-22 15:31  夏沫忆香  阅读(2517)  评论(0编辑  收藏  举报