getstarted.rst 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. .. _getstarted:
  2. ===========
  3. Get Started
  4. ===========
  5. --------
  6. Overview
  7. --------
  8. emqttd(Erlang MQTT Broker) is an open source MQTT broker written in Erlang/OTP. Erlang/OTP is a concurrent, fault-tolerant, soft-realtime and distributed programming platform. MQTT is anextremely lightweight publish/subscribe messaging protocol powering IoT, M2M applications.
  9. The emqttd project is aimed to implement a scalable, distributed, extensible open-source MQTT broker for IoT, M2M and Mobile applications that hope to handle ten millions of concurrent MQTT clients.
  10. The emqttd broker is:
  11. * Full MQTT V3.1/3.1.1 Protocol Specifications Support
  12. * Easy to Install - Quick Install on Linux, FreeBSD, Mac and Windows
  13. * Massively scalable - Scaling to 1 million connections on a single server
  14. * Easy to extend - Hooks and plugins to customize or extend the broker
  15. * Pluggable Authentication - LDAP, MySQL, PostgreSQL, Redis Authentication Plugins
  16. --------
  17. Features
  18. --------
  19. * Full MQTT V3.1/V3.1.1 protocol specification support
  20. * QoS0, QoS1, QoS2 Publish and Subscribe
  21. * Session Management and Offline Messages
  22. * Retained Message
  23. * Last Will Message
  24. * TCP/SSL Connection
  25. * MQTT Over Websocket(SSL)
  26. * HTTP Publish API
  27. * STOMP protocol
  28. * STOMP over SockJS
  29. * $SYS/# Topics
  30. * Client Authentication with clientId, ipaddress
  31. * Client Authentication with username, password
  32. * Client ACL control with ipaddress, clientid, username
  33. * LDAP, Redis, MySQL, PostgreSQL authentication
  34. * Cluster brokers on several servers.
  35. * Bridge brokers locally or remotely
  36. * mosquitto, RSMB bridge
  37. * Extensible architecture with Hooks, Modules and Plugins
  38. * Passed eclipse paho interoperability tests
  39. -----------
  40. Quick Start
  41. -----------
  42. Download and Install
  43. --------------------
  44. Download binary package for Linux, Mac, FreeBSD and Windows platform from http://emqtt.io/downloads.
  45. .. code:: console
  46. unzip emqttd-macosx-0.16.0-beta-20160216.zip && cd emqttd
  47. # Start emqttd
  48. ./bin/emqttd start
  49. # Check Status
  50. ./bin/emqttd_ctl status
  51. # Stop emqttd
  52. ./bin/emqttd stop
  53. Installing from Source
  54. -----------------------
  55. .. NOTE:: emqttd requires Erlang R17+ to build.
  56. .. code:: console
  57. git clone https://github.com/emqtt/emqttd.git
  58. cd emqttd && make && make dist
  59. -------------
  60. Web Dashboard
  61. -------------
  62. .. image:: ./_static/images/dashboard.png
  63. -------------------
  64. Modules and Plugins
  65. -------------------
  66. The emqttd broker could be extended by modules and plugins.
  67. Modules
  68. -------
  69. +-------------------------+-----------------------------------+
  70. | emqttd_auth_clientid | ClientId认证 |
  71. +-------------------------+-----------------------------------+
  72. | emqttd_auth_username | 用户名密码认证 |
  73. +-------------------------+-----------------------------------+
  74. | emqttd_auth_ldap | LDAP认证 |
  75. +-------------------------+-----------------------------------+
  76. | emqttd_mod_presence | 客户端上下线状态消息发布 |
  77. +-------------------------+-----------------------------------+
  78. | emqttd_mod_subscription | 客户端上线自动主题订阅 |
  79. +-------------------------+-----------------------------------+
  80. | emqttd_mod_rewrite | 重写客户端订阅主题(Topic) |
  81. +-------------------------+-----------------------------------+
  82. 扩展模块通过'etc/emqttd.config'配置文件的auth, modules段落启用。
  83. 例如启用用户名密码认证::
  84. {access, [
  85. %% Authetication. Anonymous Default
  86. {auth, [
  87. %% Authentication with username, password
  88. {username, []},
  89. ...
  90. 启用客户端状态发布模块::
  91. {modules, [
  92. %% Client presence management module.
  93. %% Publish messages when client connected or disconnected
  94. {presence, [{qos, 0}]}
  95. Plugins
  96. --------
  97. +-------------------------+-----------------------------------+
  98. | emqttd_plugin_template | 插件模版与演示代码 |
  99. +-------------------------+-----------------------------------+
  100. | emqttd_dashboard | Web管理控制台,默认加载 |
  101. +-------------------------+-----------------------------------+
  102. | emqttd_plugin_mysql | MySQL认证插件 |
  103. +-------------------------+-----------------------------------+
  104. | emqttd_plugin_pgsql | PostgreSQL认证插件 |
  105. +-------------------------+-----------------------------------+
  106. | emqttd_plugin_redis | Redis认证插件 |
  107. +-------------------------+-----------------------------------+
  108. | emqttd_plugin_mongo | MongoDB认证插件 |
  109. +-------------------------+-----------------------------------+
  110. | emqttd_stomp | Stomp协议插件 |
  111. +-------------------------+-----------------------------------+
  112. | emqttd_sockjs | SockJS插件 |
  113. +-------------------------+-----------------------------------+
  114. | emqttd_recon | Recon优化调测插件 |
  115. +-------------------------+-----------------------------------+
  116. 扩展插件通过'bin/emqttd_ctl'管理命令行,加载启动运行。
  117. 例如启用PostgreSQL认证插件::
  118. ./bin/emqttd_ctl plugins load emqttd_plugin_pgsql
  119. ----------------------------------
  120. One million Connections
  121. ----------------------------------
  122. .. NOTE::
  123. emqttd消息服务器默认设置,允许最大客户端连接是512,因为大部分操作系统'ulimit -n'限制为1024。
  124. emqttd消息服务器当前版本,连接压力测试到130万线,8核心/32G内存的CentOS云服务器。
  125. 操作系统内核参数、TCP协议栈参数、Erlang虚拟机参数、emqttd最大允许连接数设置简述如下:
  126. Linux Kernel Parameters
  127. -----------------------
  128. # 2M - 系统所有进程可打开的文件数量::
  129. .. code::
  130. sysctl -w fs.file-max=2097152
  131. sysctl -w fs.nr_open=2097152
  132. # 1M - 系统允许当前进程打开的文件数量::
  133. ulimit -n 1048576
  134. TCP Stack Parameters
  135. -----------------------
  136. # backlog - Socket监听队列长度::
  137. .. code::
  138. sysctl -w net.core.somaxconn=65536
  139. Erlang VM
  140. -----------------
  141. emqttd/etc/vm.args::
  142. ## max process numbers
  143. +P 2097152
  144. ## Sets the maximum number of simultaneously existing ports for this system
  145. +Q 1048576
  146. ## Increase number of concurrent ports/sockets
  147. -env ERL_MAX_PORTS 1048576
  148. -env ERTS_MAX_PORTS 1048576
  149. emqttd.config
  150. -----------------
  151. emqttd/etc/emqttd.config::
  152. {mqtt, 1883, [
  153. %% Size of acceptor pool
  154. {acceptors, 64},
  155. %% Maximum number of concurrent clients
  156. {max_clients, 1000000},
  157. %% Socket Access Control
  158. {access, [{allow, all}]},
  159. %% Connection Options
  160. {connopts, [
  161. %% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
  162. %% {rate_limit, "100,10"} %% 100K burst, 10K rate
  163. ]},
  164. ...
  165. Test Client
  166. -----------
  167. .. code::
  168. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  169. echo 1000000 > /proc/sys/fs/nr_open
  170. ---------------------
  171. MQTT Client Libraries
  172. ---------------------
  173. GitHub: https://github.com/emqtt
  174. +--------------------+----------------------+
  175. | `emqttc`_ | Erlang MQTT Client |
  176. +--------------------+----------------------+
  177. | `emqtt_benchmark`_ | MQTT benchmark Tool |
  178. +--------------------+----------------------+
  179. | `CocoaMQTT`_ | Swift MQTT Client |
  180. +--------------------+----------------------+
  181. | `QMQTT`_ | QT MQTT Client |
  182. +--------------------+----------------------+
  183. .. _emqttc: https://github.com/emqtt/emqttc
  184. .. _emqtt_benchmark: https://github.com/emqtt/emqtt_benchmark
  185. .. _CocoaMQTT: https://github.com/emqtt/CocoaMQTT
  186. .. _QMQTT: https://github.com/emqtt/qmqtt