getstarted.rst 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  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. Plugins
  83. -------
  84. The *EMQ* broker could be extended by Plugins. A plugin is an Erlang application to extend the *EMQ* broker:
  85. +-------------------------+--------------------------------------------+
  86. | `emq_auth_clientid`_ | Authentication with ClientId |
  87. +-------------------------+--------------------------------------------+
  88. | `emq_auth_username`_ | Authentication with Username and Password |
  89. +-------------------------+--------------------------------------------+
  90. | `emq_plugin_template`_ | Plugin template and demo |
  91. +-------------------------+--------------------------------------------+
  92. | `emq_dashboard`_ | Web Dashboard |
  93. +-------------------------+--------------------------------------------+
  94. | `emq_auth_ldap`_ | LDAP Auth Plugin |
  95. +-------------------------+--------------------------------------------+
  96. | `emq_auth_http`_ | Authentication/ACL with HTTP API |
  97. +-------------------------+--------------------------------------------+
  98. | `emq_auth_mysql` _ | Authentication with MySQL |
  99. +-------------------------+--------------------------------------------+
  100. | `emq_auth_pgsql`_ | Authentication with PostgreSQL |
  101. +-------------------------+--------------------------------------------+
  102. | `emq_auth_redis`_ | Authentication with Redis |
  103. +-------------------------+--------------------------------------------+
  104. | `emq_mod_rewrite`_ | Topics rewrite like HTTP rewrite module |
  105. +-------------------------+--------------------------------------------+
  106. | `emq_mod_retainer`_ | Retainer Module |
  107. +-------------------------+--------------------------------------------+
  108. | `emq_mod_presence`_ | Presence Module |
  109. +-------------------------+--------------------------------------------+
  110. | `emq_mod_subscription`_ | Subscription Module |
  111. +-------------------------+--------------------------------------------+
  112. | `emq_mod_mongo`_ | Authentication with MongoDB |
  113. +-------------------------+--------------------------------------------+
  114. | `emq_sn`_ | MQTT-SN Protocol Plugin |
  115. +-------------------------+--------------------------------------------+
  116. | `emq_coap`_ | CoAP Protocol Plugin |
  117. +-------------------------+--------------------------------------------+
  118. | `emq_stomp`_ | STOMP Protocol Plugin |
  119. +-------------------------+--------------------------------------------+
  120. | `emq_sockjs`_ | SockJS(Stomp) Plugin |
  121. +-------------------------+--------------------------------------------+
  122. | `emq_recon`_ | Recon Plugin |
  123. +-------------------------+--------------------------------------------+
  124. | `emq_reloader`_ | Reloader Plugin |
  125. +-------------------------+--------------------------------------------+
  126. A plugin could be enabled by 'bin/emqttd_ctl plugins load' command.
  127. For example, enable 'emq_auth_pgsql' plugin::
  128. ./bin/emqttd_ctl plugins load emq_auth_pgsql
  129. -----------------------
  130. One Million Connections
  131. -----------------------
  132. Latest release of the *EMQ* broker is scaling to 1.3 million MQTT connections on a 12 Core, 32G CentOS server.
  133. .. NOTE::
  134. The emqttd broker only allows 512 concurrent connections by default, for 'ulimit -n' limit is 1024 on most platform.
  135. We need tune the OS Kernel, TCP Stack, Erlang VM and emqttd broker for one million connections benchmark.
  136. Linux Kernel Parameters
  137. -----------------------
  138. .. code-block:: bash
  139. # 2M:
  140. sysctl -w fs.file-max=2097152
  141. sysctl -w fs.nr_open=2097152
  142. echo 2097152 > /proc/sys/fs/nr_open
  143. # 1M:
  144. ulimit -n 1048576
  145. TCP Stack Parameters
  146. --------------------
  147. .. code-block:: bash
  148. # backlog
  149. sysctl -w net.core.somaxconn=65536
  150. Erlang VM
  151. ---------
  152. emqttd/etc/emq.conf:
  153. .. code-block:: properties
  154. ## Erlang Process Limit
  155. node.process_limit = 2097152
  156. ## Sets the maximum number of simultaneously existing ports for this system
  157. node.max_ports = 1048576
  158. Max Allowed Connections
  159. -----------------------
  160. emqttd/etc/emq.conf 'listeners':
  161. .. code-block:: properties
  162. ## Size of acceptor pool
  163. mqtt.listener.tcp.acceptors = 64
  164. ## Maximum number of concurrent clients
  165. mqtt.listener.tcp.max_clients = 1000000
  166. Test Client
  167. -----------
  168. .. code-block:: bash
  169. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  170. echo 1000000 > /proc/sys/fs/nr_open
  171. ulimit -n 100000
  172. ---------------------
  173. MQTT Client Libraries
  174. ---------------------
  175. GitHub: https://github.com/emqtt
  176. +--------------------+----------------------+
  177. | `emqttc`_ | Erlang MQTT Client |
  178. +--------------------+----------------------+
  179. | `emqtt_benchmark`_ | MQTT benchmark Tool |
  180. +--------------------+----------------------+
  181. | `CocoaMQTT`_ | Swift MQTT Client |
  182. +--------------------+----------------------+
  183. | `QMQTT`_ | QT MQTT Client |
  184. +--------------------+----------------------+
  185. Eclipse Paho: https://www.eclipse.org/paho/
  186. MQTT.org: https://github.com/mqtt/mqtt.github.io/wiki/libraries
  187. .. _emqttc: https://github.com/emqtt/emqttc
  188. .. _emqtt_benchmark: https://github.com/emqtt/emqtt_benchmark
  189. .. _CocoaMQTT: https://github.com/emqtt/CocoaMQTT
  190. .. _QMQTT: https://github.com/emqtt/qmqtt
  191. .. _emq_plugin_template: https://github.com/emqtt/emq_plugin_template
  192. .. _emq_dashboard: https://github.com/emqtt/emq_dashboard
  193. .. _emq_mod_rewrite: https://github.com/emqtt/emq_mod_rewrite
  194. .. _emq_auth_clientid: https://github.com/emqtt/emq_auth_clientid
  195. .. _emq_auth_username: https://github.com/emqtt/emq_auth_username
  196. .. _emq_auth_ldap: https://github.com/emqtt/emq_auth_ldap
  197. .. _emq_auth_http: https://github.com/emqtt/emq_auth_http
  198. .. _emq_auth_mysql: https://github.com/emqtt/emq_plugin_mysql
  199. .. _emq_auth_pgsql: https://github.com/emqtt/emq_plugin_pgsql
  200. .. _emq_auth_redis: https://github.com/emqtt/emq_plugin_redis
  201. .. _emq_auth_mongo: https://github.com/emqtt/emq_plugin_mongo
  202. .. _emq_reloader: https://github.com/emqtt/emq_reloader
  203. .. _emq_stomp: https://github.com/emqtt/emq_stomp
  204. .. _emq_sockjs: https://github.com/emqtt/emq_sockjs
  205. .. _emq_recon: https://github.com/emqtt/emq_recon
  206. .. _emq_sn: https://github.com/emqtt/emq_sn
  207. .. _emq_coap: https://github.com/emqtt/emq_coap
  208. .. _emq_mod_retainer: https://github.com/emqtt/emq_mod_retainer
  209. .. _emq_mod_presence: https://github.com/emqtt/emq_mod_presence
  210. .. _emq_mod_subscription: https://github.com/emqtt/emq_mod_subscription