install.rst 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 Package
  11. ----------------
  12. Download binary package from: http://emqtt.io/downloads
  13. +-----------+-----------------------------------+
  14. | Ubuntu | http://emqtt.io/downloads/ubuntu |
  15. +-----------+-----------------------------------+
  16. | CentOS | http://emqtt.io/downloads/centos |
  17. +-----------+-----------------------------------+
  18. | FreeBSD | http://emqtt.io/downloads/freebsd |
  19. +-----------+-----------------------------------+
  20. | Mac OS X | http://emqtt.io/downloads/macosx |
  21. +-----------+-----------------------------------+
  22. | Windows | http://emqtt.io/downloads/windows |
  23. +-----------+-----------------------------------+
  24. The package name consists of platform, version and release time.
  25. For example: emqttd-centos64-0.16.0-beta-20160216.zip
  26. .. _install_on_linux:
  27. --------------------
  28. Installing on Linux
  29. --------------------
  30. Download CentOS Package from: http://emqtt.io/downloads/centos, and then unzip:
  31. .. code:: console
  32. unzip emqttd-centos64-0.16.0-beta-20160216.zip
  33. Start the broker in console mode::
  34. .. code:: console
  35. cd emqttd && ./bin/emqttd console
  36. If the broker is started successfully, console will print:
  37. .. code:: console
  38. starting emqttd on node 'emqttd@127.0.0.1'
  39. emqttd ctl is starting...[done]
  40. emqttd trace is starting...[done]
  41. emqttd pubsub is starting...[done]
  42. emqttd stats is starting...[done]
  43. emqttd metrics is starting...[done]
  44. emqttd retainer is starting...[done]
  45. emqttd pooler is starting...[done]
  46. emqttd client manager is starting...[done]
  47. emqttd session manager is starting...[done]
  48. emqttd session supervisor is starting...[done]
  49. emqttd broker is starting...[done]
  50. emqttd alarm is starting...[done]
  51. emqttd mod supervisor is starting...[done]
  52. emqttd bridge supervisor is starting...[done]
  53. emqttd access control is starting...[done]
  54. emqttd system monitor is starting...[done]
  55. http listen on 0.0.0.0:18083 with 4 acceptors.
  56. mqtt listen on 0.0.0.0:1883 with 16 acceptors.
  57. mqtts listen on 0.0.0.0:8883 with 4 acceptors.
  58. http listen on 0.0.0.0:8083 with 4 acceptors.
  59. Erlang MQTT Broker 0.16.0 is running now
  60. Eshell V6.4 (abort with ^G)
  61. (emqttd@127.0.0.1)1>
  62. CTRL+C to close the console and stop the broker.
  63. Start the broker in daemon mode:
  64. .. code:: console
  65. ./bin/emqttd start
  66. The boot logs in log/emqttd_sasl.log file.
  67. Check the running status of the broker:
  68. .. code:: console
  69. $ ./bin/emqttd_ctl status
  70. Node 'emqttd@127.0.0.1' is started
  71. emqttd 0.16.0 is running
  72. Or check the status by URL::
  73. http://localhost:8083/status
  74. Stop the broker::
  75. ./bin/emqttd stop
  76. .. _install_on_freebsd:
  77. ---------------------
  78. Installing on FreeBSD
  79. ---------------------
  80. Download FreeBSD Package from: http://emqtt.io/downloads/freebsd
  81. The installing process is same to Linux.
  82. .. _install_on_mac:
  83. ----------------------
  84. Installing on Mac OS X
  85. ----------------------
  86. We could install the broker on Mac OS X to develop and debug MQTT applications.
  87. Download Mac Package from: http://emqtt.io/downloads/macosx
  88. Configure 'lager' log level in 'etc/emqttd.config', all MQTT messages recevied/sent will be printed on console:
  89. .. code:: erlang
  90. {lager, [
  91. ...
  92. {handlers, [
  93. {lager_console_backend, info},
  94. ...
  95. ]}
  96. ]},
  97. The install and boot process on Mac are same to Linux.
  98. .. _install_on_windows:
  99. ---------------------
  100. Installing on Windows
  101. ---------------------
  102. Download Package from: http://emqtt.io/downloads/windows.
  103. Unzip the package to install folder. Open the command line window and 'cd' to the folder.
  104. Start the broker in console mode::
  105. .\bin\emqttd console
  106. If the broker started successfully, a Erlang console window will popup.
  107. Close the console window and stop the emqttd broker. Prepare to register emqttd as window service.
  108. Install emqttd serivce::
  109. .\bin\emqttd install
  110. Start emqttd serivce::
  111. .\bin\emqttd start
  112. Stop emqttd serivce::
  113. .\bin\emqttd stop
  114. Uninstall emqttd service::
  115. .\bin\emqttd uninstall
  116. .. WARNING:: './bin/emqttd_ctl' command line cannot work on Windows.
  117. .. _build_from_source:
  118. ----------------------
  119. Installing From Source
  120. ----------------------
  121. The emqttd broker requires Erlang/OTP R17+ and git client to build:
  122. Install Erlang: http://www.erlang.org/
  123. Install Git Client: http://www.git-scm.com/
  124. Could use apt-get on Ubuntu, yum on CentOS/RedHat and brew on Mac to install Erlang and Git.
  125. When all dependencies are ready, clone the emqttd project from github.com and build:
  126. .. code:: console
  127. git clone https://github.com/emqtt/emqttd.git
  128. cd emqttd
  129. make && make dist
  130. The binary package output in folder::
  131. rel/emqttd
  132. .. _tcp_ports:
  133. ------------------
  134. TCP Ports Occupied
  135. ------------------
  136. +-----------+-----------------------------------+
  137. | 1883 | MQTT Port |
  138. +-----------+-----------------------------------+
  139. | 8883 | MQTT Over SSL Port |
  140. +-----------+-----------------------------------+
  141. | 8083 | MQTT(WebSocket), HTTP API Port |
  142. +-----------+-----------------------------------+
  143. | 18083 | Dashboard Port |
  144. +-----------+-----------------------------------+
  145. The TCP ports could be configured in etc/emqttd.config:
  146. .. code:: erlang
  147. {listeners, [
  148. {mqtt, 1883, [
  149. ...
  150. ]},
  151. {mqtts, 8883, [
  152. ...
  153. ]},
  154. %% HTTP and WebSocket Listener
  155. {http, 8083, [
  156. ...
  157. ]}
  158. ]},
  159. The 18083 port is used by Web Dashboard of the broker. Default login: admin, Password: public
  160. .. _quick_setup:
  161. -----------
  162. Quick Setup
  163. -----------
  164. emqttd消息服务器主要配置文件:
  165. +-------------------+-----------------------------------+
  166. | etc/vm.args | Erlang VM的启动参数设置 |
  167. +-------------------+-----------------------------------+
  168. | etc/emqttd.config | emqttd消息服务器参数设置 |
  169. +-------------------+-----------------------------------+
  170. etc/vm.args中两个重要的启动参数:
  171. +-------+------------------------------------------------------------------+
  172. | +P | Erlang虚拟机允许的最大进程数,emqttd一个连接会消耗2个Erlang进程 |
  173. +-------+------------------------------------------------------------------+
  174. | +Q | Erlang虚拟机允许的最大Port数量,emqttd一个连接消耗1个Port |
  175. +-------+------------------------------------------------------------------+
  176. +P 参数值 > 最大允许连接数 * 2
  177. +Q 参数值 > 最大允许连接数
  178. .. WARNING:: 实际连接数量超过Erlang虚拟机参数设置,会引起emqttd消息服务器宕机!
  179. etc/emqttd.config文件listeners段落设置最大允许连接数:
  180. .. code:: erlang
  181. {listeners, [
  182. {mqtt, 1883, [
  183. %% TCP Acceptor池设置
  184. {acceptors, 16},
  185. %% 最大允许连接数设置
  186. {max_clients, 8192},
  187. ...
  188. ]},
  189. emqttd消息服务器详细设置,请参见文档: :ref:`config`
  190. .. _init_d_emqttd:
  191. -------------------
  192. /etc/init.d/emqttd
  193. -------------------
  194. .. code:: shell
  195. #!/bin/sh
  196. #
  197. # emqttd Startup script for emqttd.
  198. #
  199. # chkconfig: 2345 90 10
  200. # description: emqttd is mqtt broker.
  201. # source function library
  202. . /etc/rc.d/init.d/functions
  203. # export HOME=/root
  204. start() {
  205. echo "starting emqttd..."
  206. cd /opt/emqttd && ./bin/emqttd start
  207. }
  208. stop() {
  209. echo "stopping emqttd..."
  210. cd /opt/emqttd && ./bin/emqttd stop
  211. }
  212. restart() {
  213. stop
  214. start
  215. }
  216. case "$1" in
  217. start)
  218. start
  219. ;;
  220. stop)
  221. stop
  222. ;;
  223. restart)
  224. restart
  225. ;;
  226. *)
  227. echo $"Usage: $0 {start|stop}"
  228. RETVAL=2
  229. esac
  230. chkconfig::
  231. chmod +x /etc/init.d/emqttd
  232. chkconfig --add emqttd
  233. chkconfig --list
  234. boot test::
  235. service emqttd start
  236. .. NOTE::
  237. ## erlexec: HOME must be set
  238. uncomment '# export HOME=/root' if "HOME must be set" error.