install.rst 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. .. _install:
  2. ============
  3. Installation
  4. ============
  5. The emqttd 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/debian |
  15. +-----------+-----------------------------------+
  16. | Ubuntu | http://emqtt.io/downloads/ubuntu |
  17. +-----------+-----------------------------------+
  18. | CentOS | http://emqtt.io/downloads/centos |
  19. +-----------+-----------------------------------+
  20. | FreeBSD | http://emqtt.io/downloads/freebsd |
  21. +-----------+-----------------------------------+
  22. | Mac OS X | http://emqtt.io/downloads/macosx |
  23. +-----------+-----------------------------------+
  24. | Windows | http://emqtt.io/downloads/windows |
  25. +-----------+-----------------------------------+
  26. The package name consists of platform, version and release time.
  27. For example: emqttd-centos64-0.16.0-beta-20160216.zip
  28. .. _install_on_linux:
  29. -------------------
  30. Installing on Linux
  31. -------------------
  32. Download CentOS Package from: http://emqtt.io/downloads/centos, and then unzip:
  33. .. code-block:: bash
  34. unzip emqttd-centos64-0.16.0-beta-20160216.zip
  35. Start the broker in console mode:
  36. .. code-block:: bash
  37. cd emqttd && ./bin/emqttd console
  38. If the broker is started successfully, console will print:
  39. .. code-block:: bash
  40. starting emqttd on node 'emqttd@127.0.0.1'
  41. emqttd ctl is starting...[done]
  42. emqttd trace is starting...[done]
  43. emqttd pubsub is starting...[done]
  44. emqttd stats is starting...[done]
  45. emqttd metrics is starting...[done]
  46. emqttd retainer is starting...[done]
  47. emqttd pooler is starting...[done]
  48. emqttd client manager is starting...[done]
  49. emqttd session manager is starting...[done]
  50. emqttd session supervisor is starting...[done]
  51. emqttd broker is starting...[done]
  52. emqttd alarm is starting...[done]
  53. emqttd mod supervisor is starting...[done]
  54. emqttd bridge supervisor is starting...[done]
  55. emqttd access control is starting...[done]
  56. emqttd system monitor is starting...[done]
  57. http listen on 0.0.0.0:18083 with 4 acceptors.
  58. mqtt listen on 0.0.0.0:1883 with 16 acceptors.
  59. mqtts listen on 0.0.0.0:8883 with 4 acceptors.
  60. http listen on 0.0.0.0:8083 with 4 acceptors.
  61. Erlang MQTT Broker 0.16.0 is running now
  62. Eshell V6.4 (abort with ^G)
  63. (emqttd@127.0.0.1)1>
  64. CTRL+C to close the console and stop the broker.
  65. Start the broker in daemon mode:
  66. .. code-block:: bash
  67. ./bin/emqttd start
  68. The boot logs in log/emqttd_sasl.log file.
  69. Check the running status of the broker:
  70. .. code-block:: bash
  71. $ ./bin/emqttd_ctl status
  72. Node 'emqttd@127.0.0.1' is started
  73. emqttd 0.16.0 is running
  74. Or check the status by URL::
  75. http://localhost:8083/status
  76. Stop the broker::
  77. ./bin/emqttd stop
  78. .. _install_on_freebsd:
  79. ---------------------
  80. Installing on FreeBSD
  81. ---------------------
  82. Download FreeBSD Package from: http://emqtt.io/downloads/freebsd
  83. The installing process is same to Linux.
  84. .. _install_on_mac:
  85. ----------------------
  86. Installing on Mac OS X
  87. ----------------------
  88. We could install the broker on Mac OS X to develop and debug MQTT applications.
  89. Download Mac Package from: http://emqtt.io/downloads/macosx
  90. Configure 'lager' log level in 'etc/emqttd.config', all MQTT messages recevied/sent will be printed on console:
  91. .. code-block:: erlang
  92. {lager, [
  93. ...
  94. {handlers, [
  95. {lager_console_backend, info},
  96. ...
  97. ]}
  98. ]},
  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/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 emqttd broker requires Erlang/OTP R17+ 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.git
  130. cd emqttd
  131. make && make dist
  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:: erlang
  149. {listeners, [
  150. {mqtt, 1883, [
  151. ...
  152. ]},
  153. {mqtts, 8883, [
  154. ...
  155. ]},
  156. %% HTTP and WebSocket Listener
  157. {http, 8083, [
  158. ...
  159. ]}
  160. ]},
  161. The 18083 port is used by Web Dashboard of the broker. Default login: admin, Password: public
  162. .. _quick_setup:
  163. -----------
  164. Quick Setup
  165. -----------
  166. Two main configuration files of the emqttd broker:
  167. +-------------------+-----------------------------------+
  168. | etc/vm.args | Erlang VM Arguments |
  169. +-------------------+-----------------------------------+
  170. | etc/emqttd.config | emqttd broker Config |
  171. +-------------------+-----------------------------------+
  172. Two important parameters in etc/vm.args:
  173. +-------+---------------------------------------------------------------------------+
  174. | +P | Max number of Erlang proccesses. A MQTT client consumes two proccesses. |
  175. | | The value should be larger than max_clients * 2 |
  176. +-------+---------------------------------------------------------------------------+
  177. | +Q | Max number of Erlang Ports. A MQTT client consumes one port. |
  178. | | The value should be larger than max_clients. |
  179. +-------+---------------------------------------------------------------------------+
  180. .. NOTE::
  181. +Q > maximum number of allowed concurrent clients
  182. +P > maximum number of allowed concurrent clients * 2
  183. The maximum number of allowed MQTT clients:
  184. .. code-block:: erlang
  185. {listeners, [
  186. {mqtt, 1883, [
  187. %% TCP Acceptor Pool
  188. {acceptors, 16},
  189. %% Maximum number of concurrent MQTT clients
  190. {max_clients, 8192},
  191. ...
  192. ]},
  193. .. _init_d_emqttd:
  194. -------------------
  195. /etc/init.d/emqttd
  196. -------------------
  197. .. code-block:: bash
  198. #!/bin/sh
  199. #
  200. # emqttd Startup script for emqttd.
  201. #
  202. # chkconfig: 2345 90 10
  203. # description: emqttd is mqtt broker.
  204. # source function library
  205. . /etc/rc.d/init.d/functions
  206. # export HOME=/root
  207. start() {
  208. echo "starting emqttd..."
  209. cd /opt/emqttd && ./bin/emqttd start
  210. }
  211. stop() {
  212. echo "stopping emqttd..."
  213. cd /opt/emqttd && ./bin/emqttd stop
  214. }
  215. restart() {
  216. stop
  217. start
  218. }
  219. case "$1" in
  220. start)
  221. start
  222. ;;
  223. stop)
  224. stop
  225. ;;
  226. restart)
  227. restart
  228. ;;
  229. *)
  230. echo $"Usage: $0 {start|stop}"
  231. RETVAL=2
  232. esac
  233. chkconfig::
  234. chmod +x /etc/init.d/emqttd
  235. chkconfig --add emqttd
  236. chkconfig --list
  237. boot test::
  238. service emqttd start
  239. .. NOTE::
  240. ## erlexec: HOME must be set
  241. uncomment '# export HOME=/root' if "HOME must be set" error.