install.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386
  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. .. _install_via_docker_image:
  120. ------------------------
  121. Install via Docker Image
  122. ------------------------
  123. Download *EMQ* 2.0 Docker Image:
  124. http://emqtt.com/downloads/latest/docker
  125. unzip emqttd-docker image::
  126. unzip emqttd-docker-v2.0.zip
  127. Load Docker Image::
  128. docker load < emqttd-docker-v2.0
  129. Run the Container::
  130. docker run -itd --net='host' --name emq20 emqttd-docker-v2.0
  131. Stop the broker::
  132. docker stop emq20
  133. Start the broker::
  134. docker start emq20
  135. Enter the running container::
  136. docker exec -it emq20 /bin/bash
  137. .. _build_from_source:
  138. ----------------------
  139. Installing From Source
  140. ----------------------
  141. The *EMQ* broker requires Erlang/OTP R18+ and git client to build:
  142. Install Erlang: http://www.erlang.org/
  143. Install Git Client: http://www.git-scm.com/
  144. Could use apt-get on Ubuntu, yum on CentOS/RedHat and brew on Mac to install Erlang and Git.
  145. When all dependencies are ready, clone the emqttd project from github.com and build:
  146. .. code-block:: bash
  147. git clone https://github.com/emqtt/emqttd-relx.git
  148. cd emqttd-relx && make
  149. cd _rel/emqttd && ./bin/emqttd console
  150. The binary package output in folder::
  151. _rel/emqttd
  152. .. _tcp_ports:
  153. --------------
  154. TCP Ports Used
  155. --------------
  156. +-----------+-----------------------------------+
  157. | 1883 | MQTT Port |
  158. +-----------+-----------------------------------+
  159. | 8883 | MQTT/SSL Port |
  160. +-----------+-----------------------------------+
  161. | 8083 | MQTT(WebSocket), HTTP API Port |
  162. +-----------+-----------------------------------+
  163. | 8084 | MQTT(WebSocket/SSL), HTTP API Port|
  164. +-----------+-----------------------------------+
  165. | 18083 | Web Dashboard Port |
  166. +-----------+-----------------------------------+
  167. The TCP ports used can be configured in etc/emqttd.config:
  168. .. code-block:: properties
  169. ## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883
  170. mqtt.listener.tcp = 1883
  171. ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883
  172. mqtt.listener.ssl = 8883
  173. ## HTTP and WebSocket Listener
  174. mqtt.listener.http = 8083
  175. The 18083 port is used by Web Dashboard of the broker. Default login: admin, Password: public
  176. .. _quick_setup:
  177. -----------
  178. Quick Setup
  179. -----------
  180. Two main configuration files of the *EMQ* broker:
  181. +-----------------------+-----------------------------------+
  182. | etc/emq.conf | EMQ Broker Config |
  183. +-----------------------+-----------------------------------+
  184. | etc/plugins/\*.conf | EMQ Plugins' Config |
  185. +-----------------------+-----------------------------------+
  186. Two important parameters in etc/emq.conf:
  187. +--------------------+-------------------------------------------------------------------------+
  188. | node.process_limit | Max number of Erlang proccesses. A MQTT client consumes two proccesses. |
  189. | | The value should be larger than max_clients * 2 |
  190. +--------------------+-------------------------------------------------------------------------+
  191. | node.max_ports | Max number of Erlang Ports. A MQTT client consumes one port. |
  192. | | The value should be larger than max_clients. |
  193. +--------------------+-------------------------------------------------------------------------+
  194. .. NOTE::
  195. node.process_limit > maximum number of allowed concurrent clients * 2
  196. node.max_ports > maximum number of allowed concurrent clients
  197. The maximum number of allowed MQTT clients:
  198. .. code-block:: properties
  199. mqtt.listener.tcp = 1883
  200. mqtt.listener.tcp.acceptors = 8
  201. mqtt.listener.tcp.max_clients = 1024
  202. .. _init_d_emqttd:
  203. -------------------
  204. /etc/init.d/emqttd
  205. -------------------
  206. .. code-block:: bash
  207. #!/bin/sh
  208. #
  209. # emqttd Startup script for emqttd.
  210. #
  211. # chkconfig: 2345 90 10
  212. # description: emqttd is mqtt broker.
  213. # source function library
  214. . /etc/rc.d/init.d/functions
  215. # export HOME=/root
  216. start() {
  217. echo "starting emqttd..."
  218. cd /opt/emqttd && ./bin/emqttd start
  219. }
  220. stop() {
  221. echo "stopping emqttd..."
  222. cd /opt/emqttd && ./bin/emqttd stop
  223. }
  224. restart() {
  225. stop
  226. start
  227. }
  228. case "$1" in
  229. start)
  230. start
  231. ;;
  232. stop)
  233. stop
  234. ;;
  235. restart)
  236. restart
  237. ;;
  238. *)
  239. echo $"Usage: $0 {start|stop}"
  240. RETVAL=2
  241. esac
  242. chkconfig::
  243. chmod +x /etc/init.d/emqttd
  244. chkconfig --add emqttd
  245. chkconfig --list
  246. boot test::
  247. service emqttd start
  248. .. NOTE::
  249. ## erlexec: HOME must be set
  250. uncomment '# export HOME=/root' if "HOME must be set" error.
  251. .. _emq_dashboard: https://github.com/emqtt/emqttd_dashboard