getstarted.rst 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 an extremely lightweight publish/subscribe messaging protocol powering IoT, M2M and Mobile 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. Highlights of the emqttd broker:
  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. * ClientID Authentication
  31. * IpAddress Authentication
  32. * Username and Password Authentication
  33. * Access control based on IpAddress, ClientID, Username
  34. * Authentication with LDAP, Redis, MySQL, PostgreSQL
  35. * Cluster brokers on several servers
  36. * Bridge brokers locally or remotely
  37. * mosquitto, RSMB bridge
  38. * Extensible architecture with Hooks, Modules and Plugins
  39. * Passed eclipse paho interoperability tests
  40. -----------
  41. Quick Start
  42. -----------
  43. Download and Install
  44. --------------------
  45. The emqttd broker is cross-platform, could be deployed on Linux, Mac, FreeBSD, Windows and Raspberry Pi.
  46. Download binary package from: http://emqtt.io/downloads.
  47. Installing on Mac, For example:
  48. .. code:: console
  49. unzip emqttd-macosx-0.16.0-beta-20160216.zip && cd emqttd
  50. # Start emqttd
  51. ./bin/emqttd start
  52. # Check Status
  53. ./bin/emqttd_ctl status
  54. # Stop emqttd
  55. ./bin/emqttd stop
  56. Installing from Source
  57. ----------------------
  58. .. NOTE:: emqttd requires Erlang R17+ to build.
  59. .. code:: console
  60. git clone https://github.com/emqtt/emqttd.git
  61. cd emqttd && make && make dist
  62. cd rel/emqttd && ./bin/emqttd console
  63. -------------
  64. Web Dashboard
  65. -------------
  66. A Web Dashboard will be loaded automatically when the emqttd broker is started successfully.
  67. The Dashboard helps to check running status of the broker, monitor statistics and metrics of MQTT packets,
  68. query clients, sessions, topics and subscriptions.
  69. +------------------+---------------------------+
  70. | Default Address | http://localhost:18083 |
  71. +------------------+---------------------------+
  72. | Default User | admin |
  73. +------------------+---------------------------+
  74. | Default Password | public |
  75. +------------------+---------------------------+
  76. .. image:: ./_static/images/dashboard.png
  77. -------------------
  78. Modules and Plugins
  79. -------------------
  80. The emqttd broker could be extended by Modules and Plugins.
  81. The authentication and ACL mechanism is usually implemented by a module or plugin.
  82. Modules
  83. -------
  84. +-------------------------+--------------------------------------------+
  85. | emqttd_auth_clientid | Authentication with ClientId |
  86. +-------------------------+--------------------------------------------+
  87. | emqttd_auth_username | Authentication with Username and Password |
  88. +-------------------------+--------------------------------------------+
  89. | emqttd_auth_ldap | Authentication with LDAP |
  90. +-------------------------+--------------------------------------------+
  91. | emqttd_mod_presence | Publish presence message to $SYS topics |
  92. | | when client connected or disconnected |
  93. +-------------------------+--------------------------------------------+
  94. | emqttd_mod_subscription | Subscribe topics automatically when client |
  95. | | connected |
  96. +-------------------------+--------------------------------------------+
  97. | emqttd_mod_rewrite | Topics rewrite like HTTP rewrite module |
  98. +-------------------------+--------------------------------------------+
  99. Configure the 'auth', 'module' paragraph in 'etc/emqttd.config' to enable a module.
  100. Enable 'emqttd_auth_username' module::
  101. {access, [
  102. %% Authetication. Anonymous Default
  103. {auth, [
  104. %% Authentication with username, password
  105. {username, []},
  106. ...
  107. Enable 'emqttd_mod_presence' module::
  108. {modules, [
  109. %% Client presence management module.
  110. %% Publish messages when client connected or disconnected
  111. {presence, [{qos, 0}]}
  112. Plugins
  113. -------
  114. A plugin is an Erlang application to extend the emqttd broker.
  115. +----------------------------+-----------------------------------+
  116. | `emqttd_plugin_template`_ | Plugin template and demo |
  117. +----------------------------+-----------------------------------+
  118. | `emqttd_dashboard`_ | Web Dashboard |
  119. +----------------------------+-----------------------------------+
  120. | `emqttd_plugin_mysql`_ | Authentication with MySQL |
  121. +----------------------------+-----------------------------------+
  122. | `emqttd_plugin_pgsql`_ | Authentication with PostgreSQL |
  123. +----------------------------+-----------------------------------+
  124. | `emqttd_plugin_redis`_ | Authentication with Redis |
  125. +----------------------------+-----------------------------------+
  126. | `emqttd_plugin_mongo`_ | Authentication with MongoDB |
  127. +----------------------------+-----------------------------------+
  128. | `emqttd_stomp`_ | STOMP Protocol Plugin |
  129. +----------------------------+-----------------------------------+
  130. | `emqttd_sockjs`_ | SockJS(Stomp) Plugin |
  131. +----------------------------+-----------------------------------+
  132. | `emqttd_recon`_ | Recon Plugin |
  133. +----------------------------+-----------------------------------+
  134. A plugin could be enabled by 'bin/emqttd_ctl plugins load' command.
  135. For example, enable 'emqttd_plugin_pgsql' plugin::
  136. ./bin/emqttd_ctl plugins load emqttd_plugin_pgsql
  137. -----------------------
  138. One million Connections
  139. -----------------------
  140. Latest release of the emqttd broker is scaling to 1.3 million MQTT connections on a 12 Core, 32G CentOS server.
  141. .. NOTE::
  142. The emqttd broker only allows 512 concurrent connections by default, for 'ulimit -n' limit is 1024 on most platform.
  143. We need tune the OS Kernel, TCP Stack, Erlang VM and emqttd broker for one million connections benchmark.
  144. Linux Kernel Parameters
  145. -----------------------
  146. .. code::
  147. # 2M:
  148. sysctl -w fs.file-max=2097152
  149. sysctl -w fs.nr_open=2097152
  150. # 1M:
  151. ulimit -n 1048576
  152. TCP Stack Parameters
  153. --------------------
  154. .. code::
  155. # backlog
  156. sysctl -w net.core.somaxconn=65536
  157. Erlang VM
  158. ---------
  159. emqttd/etc/vm.args::
  160. ## max process numbers
  161. +P 2097152
  162. ## Sets the maximum number of simultaneously existing ports for this system
  163. +Q 1048576
  164. ## Increase number of concurrent ports/sockets
  165. -env ERL_MAX_PORTS 1048576
  166. -env ERTS_MAX_PORTS 1048576
  167. emqttd broker
  168. -------------
  169. emqttd/etc/emqttd.config::
  170. {mqtt, 1883, [
  171. %% Size of acceptor pool
  172. {acceptors, 64},
  173. %% Maximum number of concurrent clients
  174. {max_clients, 1000000},
  175. %% Socket Access Control
  176. {access, [{allow, all}]},
  177. %% Connection Options
  178. {connopts, [
  179. %% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
  180. %% {rate_limit, "100,10"} %% 100K burst, 10K rate
  181. ]},
  182. ...
  183. Test Client
  184. -----------
  185. .. code::
  186. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  187. echo 1000000 > /proc/sys/fs/nr_open
  188. ulimit -n 100000
  189. ----------------------
  190. emqtt Client Libraries
  191. ----------------------
  192. GitHub: https://github.com/emqtt
  193. +--------------------+----------------------+
  194. | `emqttc`_ | Erlang MQTT Client |
  195. +--------------------+----------------------+
  196. | `emqtt_benchmark`_ | MQTT benchmark Tool |
  197. +--------------------+----------------------+
  198. | `CocoaMQTT`_ | Swift MQTT Client |
  199. +--------------------+----------------------+
  200. | `QMQTT`_ | QT MQTT Client |
  201. +--------------------+----------------------+
  202. .. _emqttc: https://github.com/emqtt/emqttc
  203. .. _emqtt_benchmark: https://github.com/emqtt/emqtt_benchmark
  204. .. _CocoaMQTT: https://github.com/emqtt/CocoaMQTT
  205. .. _QMQTT: https://github.com/emqtt/qmqtt
  206. .. _emqttd_plugin_template: https://github.com/emqtt/emqttd_plugin_template
  207. .. _emqttd_dashboard: https://github.com/emqtt/emqttd_dashboard
  208. .. _emqttd_plugin_mysql: https://github.com/emqtt/emqttd_plugin_mysql
  209. .. _emqttd_plugin_pgsql: https://github.com/emqtt/emqttd_plugin_pgsql
  210. .. _emqttd_plugin_redis: https://github.com/emqtt/emqttd_plugin_redis
  211. .. _emqttd_plugin_mongo: https://github.com/emqtt/emqttd_plugin_mongo
  212. .. _emqttd_stomp: https://github.com/emqtt/emqttd_stomp
  213. .. _emqttd_sockjs: https://github.com/emqtt/emqttd_sockjs
  214. .. _emqttd_recon: https://github.com/emqtt/emqttd_recon