getstarted.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. .. _getstarted:
  2. ===========
  3. Get Started
  4. ===========
  5. --------
  6. Overview
  7. --------
  8. *EMQ* (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 *EMQ* project is aimed to implement a scalable, distributed, extensible open-source MQTT broker for IoT, M2M and Mobile applications that hope to handle millions of concurrent MQTT clients.
  10. Highlights of the *EMQ* 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. * Cluster and Bridge Support
  15. * Easy to extend - Hooks and plugins to customize or extend the broker
  16. * Pluggable Authentication - LDAP, MySQL, PostgreSQL, Redis Authentication Plugins
  17. --------
  18. Features
  19. --------
  20. * Full MQTT V3.1/V3.1.1 protocol specification support
  21. * QoS0, QoS1, QoS2 Publish and Subscribe
  22. * Session Management and Offline Messages
  23. * Retained Message
  24. * Last Will Message
  25. * TCP/SSL Connection
  26. * MQTT Over WebSocket(SSL)
  27. * HTTP Publish API
  28. * STOMP protocol
  29. * MQTT-SN Protocol
  30. * CoAP Protocol
  31. * STOMP over SockJS
  32. * $SYS/# Topics
  33. * ClientID Authentication
  34. * IpAddress Authentication
  35. * Username and Password Authentication
  36. * Access control based on IpAddress, ClientID, Username
  37. * Authentication with LDAP, Redis, MySQL, PostgreSQL and HTTP API
  38. * Cluster brokers on several servers
  39. * Bridge brokers locally or remotely
  40. * mosquitto, RSMB bridge
  41. * Extensible architecture with Hooks, Modules and Plugins
  42. * Passed eclipse paho interoperability tests
  43. * Local subscription
  44. * Shared subscription
  45. -----------
  46. Quick Start
  47. -----------
  48. Download and Install
  49. --------------------
  50. The *EMQ* broker is cross-platform, which could be deployed on Linux, FreeBSD, Mac, Windows and even Raspberry Pi.
  51. Download binary package from: http://emqtt.io/downloads.
  52. Installing on Mac, for example:
  53. .. code-block:: bash
  54. unzip emqttd-macosx-v2.0-rc.2-20161019.zip && cd emqttd
  55. # Start emqttd
  56. ./bin/emqttd start
  57. # Check Status
  58. ./bin/emqttd_ctl status
  59. # Stop emqttd
  60. ./bin/emqttd stop
  61. Installing from Source
  62. ----------------------
  63. .. NOTE:: emqttd broker requires Erlang R18+ to build since 1.1 release.
  64. .. code-block:: bash
  65. git clone https://github.com/emqtt/emqttd.git
  66. cd emqttd && make && make dist
  67. cd rel/emqttd && ./bin/emqttd console
  68. -------------
  69. Web Dashboard
  70. -------------
  71. A Web Dashboard will be loaded when the *EMQ* broker is started successfully.
  72. The Dashboard helps check running status of the broker, monitor statistics and metrics of MQTT packets, query clients, sessions, topics and subscriptions.
  73. +------------------+---------------------------+
  74. | Default Address | http://localhost:18083 |
  75. +------------------+---------------------------+
  76. | Default User | admin |
  77. +------------------+---------------------------+
  78. | Default Password | public |
  79. +------------------+---------------------------+
  80. .. image:: ./_static/images/dashboard.png
  81. -------------------
  82. Modules and Plugins
  83. -------------------
  84. The *EMQ* broker could be extended by Modules ofr Plugins.
  85. Modules
  86. -------
  87. +-------------------------+--------------------------------------------+
  88. | emqttd_mod_retainer | Retained Messages Storage |
  89. +-------------------------+--------------------------------------------+
  90. | emqttd_mod_presence | Publish presence message to $SYS topics |
  91. | | when client connected or disconnected |
  92. +-------------------------+--------------------------------------------+
  93. | emqttd_mod_subscription | Subscribe topics automatically when client |
  94. | | connected |
  95. +-------------------------+--------------------------------------------+
  96. Modules could enabled by configuring 'etc/emq.conf':
  97. .. code-block:: properties
  98. ##-------------------------------------------------------------------
  99. ## MQTT Modules
  100. ##-------------------------------------------------------------------
  101. ## Enable presence module
  102. mqtt.module.presence = on
  103. mqtt.module.presence.qos = 0
  104. ## Enable subscription module
  105. mqtt.module.subscription = on
  106. mqtt.module.subscription.topics = $client/%c=1,$user/%u=1
  107. Plugins
  108. -------
  109. A plugin is an Erlang application to extend the *EMQ* broker.
  110. +----------------------------+--------------------------------------------+
  111. | `emq_auth_clientid`_ | Authentication with ClientId |
  112. +----------------------------+--------------------------------------------+
  113. | `emq_auth_username`_ | Authentication with Username and Password |
  114. +----------------------------+--------------------------------------------+
  115. | `emq_plugin_template`_ | Plugin template and demo |
  116. +----------------------------+--------------------------------------------+
  117. | `emq_dashboard`_ | Web Dashboard |
  118. +----------------------------+--------------------------------------------+
  119. | `emq_auth_ldap`_ | LDAP Auth Plugin |
  120. +----------------------------+--------------------------------------------+
  121. | `emq_auth_http`_ | Authentication/ACL with HTTP API |
  122. +----------------------------+--------------------------------------------+
  123. | `emq_auth_mysql` _ | Authentication with MySQL |
  124. +----------------------------+--------------------------------------------+
  125. | `emq_auth_pgsql`_ | Authentication with PostgreSQL |
  126. +----------------------------+--------------------------------------------+
  127. | `emq_auth_redis`_ | Authentication with Redis |
  128. +----------------------------+--------------------------------------------+
  129. | `emq_mod_rewrite`_ | Topics rewrite like HTTP rewrite module |
  130. +----------------------------+--------------------------------------------+
  131. | `emq_plugin_mongo`_ | Authentication with MongoDB |
  132. +----------------------------+--------------------------------------------+
  133. | `emq_sn`_ | MQTT-SN Protocol Plugin |
  134. +----------------------------+--------------------------------------------+
  135. | `emq_coap`_ | CoAP Protocol Plugin |
  136. +----------------------------+--------------------------------------------+
  137. | `emq_stomp`_ | STOMP Protocol Plugin |
  138. +----------------------------+--------------------------------------------+
  139. | `emq_sockjs`_ | SockJS(Stomp) Plugin |
  140. +----------------------------+--------------------------------------------+
  141. | `emq_recon`_ | Recon Plugin |
  142. +----------------------------+--------------------------------------------+
  143. | `emq_reloader`_ | Reloader Plugin |
  144. +----------------------------+--------------------------------------------+
  145. A plugin could be enabled by 'bin/emqttd_ctl plugins load' command.
  146. For example, enable 'emq_auth_pgsql' plugin::
  147. ./bin/emqttd_ctl plugins load emq_auth_pgsql
  148. -----------------------
  149. One Million Connections
  150. -----------------------
  151. Latest release of the *EMQ* broker is scaling to 1.3 million MQTT connections on a 12 Core, 32G CentOS server.
  152. .. NOTE::
  153. The emqttd broker only allows 512 concurrent connections by default, for 'ulimit -n' limit is 1024 on most platform.
  154. We need tune the OS Kernel, TCP Stack, Erlang VM and emqttd broker for one million connections benchmark.
  155. Linux Kernel Parameters
  156. -----------------------
  157. .. code-block:: bash
  158. # 2M:
  159. sysctl -w fs.file-max=2097152
  160. sysctl -w fs.nr_open=2097152
  161. echo 2097152 > /proc/sys/fs/nr_open
  162. # 1M:
  163. ulimit -n 1048576
  164. TCP Stack Parameters
  165. --------------------
  166. .. code-block:: bash
  167. # backlog
  168. sysctl -w net.core.somaxconn=65536
  169. Erlang VM
  170. ---------
  171. emqttd/etc/emq.conf:
  172. .. code-block:: properties
  173. ## Erlang Process Limit
  174. node.process_limit = 2097152
  175. ## Sets the maximum number of simultaneously existing ports for this system
  176. node.max_ports = 1048576
  177. Max Allowed Connections
  178. -----------------------
  179. emqttd/etc/emq.conf 'listeners':
  180. .. code-block:: properties
  181. ## Size of acceptor pool
  182. mqtt.listener.tcp.acceptors = 64
  183. ## Maximum number of concurrent clients
  184. mqtt.listener.tcp.max_clients = 1000000
  185. Test Client
  186. -----------
  187. .. code-block:: bash
  188. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  189. echo 1000000 > /proc/sys/fs/nr_open
  190. ulimit -n 100000
  191. ---------------------
  192. MQTT Client Libraries
  193. ---------------------
  194. GitHub: https://github.com/emqtt
  195. +--------------------+----------------------+
  196. | `emqttc`_ | Erlang MQTT Client |
  197. +--------------------+----------------------+
  198. | `emqtt_benchmark`_ | MQTT benchmark Tool |
  199. +--------------------+----------------------+
  200. | `CocoaMQTT`_ | Swift MQTT Client |
  201. +--------------------+----------------------+
  202. | `QMQTT`_ | QT MQTT Client |
  203. +--------------------+----------------------+
  204. Eclipse Paho: https://www.eclipse.org/paho/
  205. MQTT.org: https://github.com/mqtt/mqtt.github.io/wiki/libraries
  206. .. _emqttc: https://github.com/emqtt/emqttc
  207. .. _emqtt_benchmark: https://github.com/emqtt/emqtt_benchmark
  208. .. _CocoaMQTT: https://github.com/emqtt/CocoaMQTT
  209. .. _QMQTT: https://github.com/emqtt/qmqtt
  210. .. _emq_plugin_template: https://github.com/emqtt/emq_plugin_template
  211. .. _emq_dashboard: https://github.com/emqtt/emq_dashboard
  212. .. _emq_mod_rewrite: https://github.com/emqtt/emq_mod_rewrite
  213. .. _emq_auth_clientid: https://github.com/emqtt/emq_auth_clientid
  214. .. _emq_auth_username: https://github.com/emqtt/emq_auth_username
  215. .. _emq_auth_ldap: https://github.com/emqtt/emq_auth_ldap
  216. .. _emq_auth_http: https://github.com/emqtt/emq_auth_http
  217. .. _emq_auth_mysql: https://github.com/emqtt/emq_plugin_mysql
  218. .. _emq_auth_pgsql: https://github.com/emqtt/emq_plugin_pgsql
  219. .. _emq_auth_redis: https://github.com/emqtt/emq_plugin_redis
  220. .. _emq_auth_mongo: https://github.com/emqtt/emq_plugin_mongo
  221. .. _emq_reloader: https://github.com/emqtt/emq_reloader
  222. .. _emq_stomp: https://github.com/emqtt/emq_stomp
  223. .. _emq_sockjs: https://github.com/emqtt/emq_sockjs
  224. .. _emq_recon: https://github.com/emqtt/emq_recon
  225. .. _emq_sn: https://github.com/emqtt/emq_sn
  226. .. _emq_coap: https://github.com/emqtt/emq_coap