install.rst 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350
  1. .. _install:
  2. ============
  3. Installation
  4. ============
  5. The *EMQ* broker is cross-platform, which could be deployed on Linux, FreeBSD, Mac, Windows and even Raspberry Pi.
  6. .. NOTE::
  7. Linux, FreeBSD Recommended.
  8. .. _install_download:
  9. -----------------
  10. Download Packages
  11. -----------------
  12. Download binary packages from: http://emqtt.io/downloads
  13. +-----------+------------------------------------------+
  14. | Debian | http://emqtt.io/downloads/latest/debian |
  15. +-----------+------------------------------------------+
  16. | Ubuntu | http://emqtt.io/downloads/latest/ubuntu |
  17. +-----------+------------------------------------------+
  18. | CentOS | http://emqtt.io/downloads/latest/centos |
  19. +-----------+------------------------------------------+
  20. | FreeBSD | http://emqtt.io/downloads/latest/freebsd |
  21. +-----------+------------------------------------------+
  22. | Mac OS X | http://emqtt.io/downloads/latest/macosx |
  23. +-----------+------------------------------------------+
  24. | Windows | http://emqtt.io/downloads/latest/windows |
  25. +-----------+------------------------------------------+
  26. | Docker | http://emqtt.com/downloads/latest/docker |
  27. +-----------+------------------------------------------+
  28. The package name consists of platform, version and release time.
  29. For example: emqttd-centos64-v2.0-rc.2-20161019.zip
  30. .. _install_on_linux:
  31. -------------------
  32. Installing on Linux
  33. -------------------
  34. Download CentOS Package from: http://emqtt.io/downloads/latest/centos, and then unzip:
  35. .. code-block:: bash
  36. unzip emqttd-centos64-v2.0-rc.2-20161019.zip
  37. Start the broker in console mode:
  38. .. code-block:: bash
  39. cd emqttd && ./bin/emqttd console
  40. If the broker is started successfully, console will print:
  41. .. code-block:: bash
  42. starting emqttd on node 'emqttd@127.0.0.1'
  43. emqttd ctl is starting...[done]
  44. emqttd trace is starting...[done]
  45. emqttd pubsub is starting...[done]
  46. emqttd stats is starting...[done]
  47. emqttd metrics is starting...[done]
  48. emqttd retainer is starting...[done]
  49. emqttd pooler is starting...[done]
  50. emqttd client manager is starting...[done]
  51. emqttd session manager is starting...[done]
  52. emqttd session supervisor is starting...[done]
  53. emqttd broker is starting...[done]
  54. emqttd alarm is starting...[done]
  55. emqttd mod supervisor is starting...[done]
  56. emqttd bridge supervisor is starting...[done]
  57. emqttd access control is starting...[done]
  58. emqttd system monitor is starting...[done]
  59. http listen on 0.0.0.0:18083 with 4 acceptors.
  60. mqtt listen on 0.0.0.0:1883 with 16 acceptors.
  61. mqtts listen on 0.0.0.0:8883 with 4 acceptors.
  62. http listen on 0.0.0.0:8083 with 4 acceptors.
  63. Erlang MQTT Broker 2.0 is running now
  64. Eshell V6.4 (abort with ^G)
  65. (emqttd@127.0.0.1)1>
  66. CTRL+C to close the console and stop the broker.
  67. Start the broker in daemon mode:
  68. .. code-block:: bash
  69. ./bin/emqttd start
  70. Check the running status of the broker:
  71. .. code-block:: bash
  72. $ ./bin/emqttd_ctl status
  73. Node 'emqttd@127.0.0.1' is started
  74. emqttd 2.0 is running
  75. Or check the status by URL::
  76. http://localhost:8083/status
  77. Stop the broker::
  78. ./bin/emqttd stop
  79. .. _install_on_freebsd:
  80. ---------------------
  81. Installing on FreeBSD
  82. ---------------------
  83. Download FreeBSD Package from: http://emqtt.io/downloads/latest/freebsd
  84. The installing process is same to Linux.
  85. .. _install_on_mac:
  86. ----------------------
  87. Installing on Mac OS X
  88. ----------------------
  89. We could install the broker on Mac OS X to develop and debug MQTT applications.
  90. Download Mac Package from: http://emqtt.io/downloads/latest/macosx
  91. Configure log level in `etc/emq.conf`, all MQTT messages recevied/sent will be printed on console:
  92. .. code-block::
  93. ## Console log. Enum: off, file, console, both
  94. log.console = both
  95. ## Console log level. Enum: debug, info, notice, warning, error, critical, alert, emergency
  96. log.console.level = debug
  97. ## Console log file
  98. log.console.file = log/console.log
  99. The install and boot process on Mac are same to Linux.
  100. .. _install_on_windows:
  101. ---------------------
  102. Installing on Windows
  103. ---------------------
  104. Download Package from: http://emqtt.io/downloads/latest/windows.
  105. Unzip the package to install folder. Open the command line window and 'cd' to the folder.
  106. Start the broker in console mode::
  107. .\bin\emqttd console
  108. If the broker started successfully, a Erlang console window will popup.
  109. Close the console window and stop the emqttd broker. Prepare to register emqttd as window service.
  110. Install emqttd serivce::
  111. .\bin\emqttd install
  112. Start emqttd serivce::
  113. .\bin\emqttd start
  114. Stop emqttd serivce::
  115. .\bin\emqttd stop
  116. Uninstall emqttd service::
  117. .\bin\emqttd uninstall
  118. .. WARNING:: './bin/emqttd_ctl' command line cannot work on Windows.
  119. .. _build_from_source:
  120. ----------------------
  121. Installing From Source
  122. ----------------------
  123. The *EMQ* broker requires Erlang/OTP R18+ and git client to build:
  124. Install Erlang: http://www.erlang.org/
  125. Install Git Client: http://www.git-scm.com/
  126. Could use apt-get on Ubuntu, yum on CentOS/RedHat and brew on Mac to install Erlang and Git.
  127. When all dependencies are ready, clone the emqttd project from github.com and build:
  128. .. code-block:: bash
  129. git clone https://github.com/emqtt/emqttd-relx.git
  130. cd emqttd-relx && make
  131. cd _rel/emqttd && ./bin/emqttd console
  132. The binary package output in folder::
  133. _rel/emqttd
  134. .. _tcp_ports:
  135. --------------
  136. TCP Ports Used
  137. --------------
  138. +-----------+-----------------------------------+
  139. | 1883 | MQTT Port |
  140. +-----------+-----------------------------------+
  141. | 8883 | MQTT Over SSL Port |
  142. +-----------+-----------------------------------+
  143. | 8083 | MQTT(WebSocket), HTTP API Port |
  144. +-----------+-----------------------------------+
  145. | 18083 | Dashboard Port |
  146. +-----------+-----------------------------------+
  147. The TCP ports used can be configured in etc/emqttd.config:
  148. .. code-block:: properties
  149. ## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883
  150. mqtt.listener.tcp = 1883
  151. ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883
  152. mqtt.listener.ssl = 8883
  153. ## HTTP and WebSocket Listener
  154. mqtt.listener.http = 8083
  155. The 18083 port is used by Web Dashboard of the broker. Default login: admin, Password: public
  156. .. _quick_setup:
  157. -----------
  158. Quick Setup
  159. -----------
  160. Two main configuration files of the *EMQ* broker:
  161. +-----------------------+-----------------------------------+
  162. | etc/emq.conf | EMQ Broker Config |
  163. +-----------------------+-----------------------------------+
  164. | etc/plugins/\*.conf | EMQ Plugins' Config |
  165. +-----------------------+-----------------------------------+
  166. Two important parameters in etc/emq.conf:
  167. +--------------------+-------------------------------------------------------------------------+
  168. | node.process_limit | Max number of Erlang proccesses. A MQTT client consumes two proccesses. |
  169. | | The value should be larger than max_clients * 2 |
  170. +--------------------+-------------------------------------------------------------------------+
  171. | node.max_ports | Max number of Erlang Ports. A MQTT client consumes one port. |
  172. | | The value should be larger than max_clients. |
  173. +--------------------+-------------------------------------------------------------------------+
  174. .. NOTE::
  175. node.process_limit > maximum number of allowed concurrent clients * 2
  176. node.max_ports > maximum number of allowed concurrent clients
  177. The maximum number of allowed MQTT clients:
  178. .. code-block:: properties
  179. mqtt.listener.tcp = 1883
  180. mqtt.listener.tcp.acceptors = 8
  181. mqtt.listener.tcp.max_clients = 1024
  182. .. _init_d_emqttd:
  183. -------------------
  184. /etc/init.d/emqttd
  185. -------------------
  186. .. code-block:: bash
  187. #!/bin/sh
  188. #
  189. # emqttd Startup script for emqttd.
  190. #
  191. # chkconfig: 2345 90 10
  192. # description: emqttd is mqtt broker.
  193. # source function library
  194. . /etc/rc.d/init.d/functions
  195. # export HOME=/root
  196. start() {
  197. echo "starting emqttd..."
  198. cd /opt/emqttd && ./bin/emqttd start
  199. }
  200. stop() {
  201. echo "stopping emqttd..."
  202. cd /opt/emqttd && ./bin/emqttd stop
  203. }
  204. restart() {
  205. stop
  206. start
  207. }
  208. case "$1" in
  209. start)
  210. start
  211. ;;
  212. stop)
  213. stop
  214. ;;
  215. restart)
  216. restart
  217. ;;
  218. *)
  219. echo $"Usage: $0 {start|stop}"
  220. RETVAL=2
  221. esac
  222. chkconfig::
  223. chmod +x /etc/init.d/emqttd
  224. chkconfig --add emqttd
  225. chkconfig --list
  226. boot test::
  227. service emqttd start
  228. .. NOTE::
  229. ## erlexec: HOME must be set
  230. uncomment '# export HOME=/root' if "HOME must be set" error.
  231. .. _emq_dashboard: https://github.com/emqtt/emqttd_dashboard