install.rst 8.0 KB

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