config.rst 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549
  1. .. _configuration:
  2. =============
  3. Configuration
  4. =============
  5. The main configuration files of the EMQ broker are under 'etc/' folder:
  6. +----------------------+-----------------------------------+
  7. | File | Description |
  8. +----------------------+-----------------------------------+
  9. | etc/emq.conf | EMQ 2.0 Configuration File |
  10. +----------------------+-----------------------------------+
  11. | etc/acl.conf | The default ACL File |
  12. +----------------------+-----------------------------------+
  13. | etc/plugins/\*.conf | Config Files of Plugins |
  14. +----------------------+-----------------------------------+
  15. ---------------------
  16. EMQ 2.0 Config Syntax
  17. ---------------------
  18. The *EMQ* 2.0-rc.2 release integrated with `cuttlefish` library, and adopt a more user-friendly `k = v` syntax for configuration file:
  19. .. code-block:: properties
  20. ## Node name
  21. node.name = emqttd@127.0.0.1
  22. ...
  23. ## Max ClientId Length Allowed.
  24. mqtt.max_clientid_len = 1024
  25. ...
  26. The configuration files will be preprocessed and translated to Erlang `app.config` before the EMQ broker started::
  27. ---------------------- 2.0/schema/*.schema -------------------
  28. | etc/emq.conf | ----------------- \|/ | data/app.config |
  29. | + | --> mergeconf --> | data/app.conf | --> cuttlefish generate --> | |
  30. | etc/plugins/*.conf | ----------------- | data/vm.args |
  31. ---------------------- -------------------
  32. ------------------------
  33. OS Environment Variables
  34. ------------------------
  35. +-------------------+----------------------------------------+
  36. | EMQ_NODE_NAME | Erlang node name |
  37. +-------------------+----------------------------------------+
  38. | EMQ_NODE_COOKIE | Cookie for distributed erlang node |
  39. +-------------------+----------------------------------------+
  40. | EMQ_MAX_PORTS | Maximum number of opened sockets |
  41. +-------------------+----------------------------------------+
  42. | EMQ_TCP_PORT | MQTT TCP Listener Port, Default: 1883 |
  43. +-------------------+----------------------------------------+
  44. | EMQ_SSL_PORT | MQTT SSL Listener Port, Default: 8883 |
  45. +-------------------+----------------------------------------+
  46. | EMQ_HTTP_PORT | HTTP/WebSocket Port, Default: 8083 |
  47. +-------------------+----------------------------------------+
  48. | EMQ_HTTPS_PORT | HTTPS/WebSocket Port, Default: 8084 |
  49. +-------------------+----------------------------------------+
  50. -------------------
  51. EMQ Node and Cookie
  52. -------------------
  53. The node name and cookie of *EMQ* should be configured when clustering:
  54. .. code-block:: properties
  55. ## Node name
  56. node.name = emqttd@127.0.0.1
  57. ## Cookie for distributed node
  58. node.cookie = emq_dist_cookie
  59. -------------------
  60. Erlang VM Arguments
  61. -------------------
  62. Configure and Optimize Erlang VM:
  63. .. code-block:: properties
  64. ## SMP support: enable, auto, disable
  65. node.smp = auto
  66. ## Enable kernel poll
  67. node.kernel_poll = on
  68. ## async thread pool
  69. node.async_threads = 32
  70. ## Erlang Process Limit
  71. node.process_limit = 256000
  72. ## Sets the maximum number of simultaneously existing ports for this system
  73. node.max_ports = 65536
  74. ## Set the distribution buffer busy limit (dist_buf_busy_limit)
  75. node.dist_buffer_size = 32MB
  76. ## Max ETS Tables.
  77. ## Note that mnesia and SSL will create temporary ets tables.
  78. node.max_ets_tables = 256000
  79. ## Tweak GC to run more often
  80. node.fullsweep_after = 1000
  81. ## Crash dump
  82. node.crash_dump = log/crash.dump
  83. ## Distributed node ticktime
  84. node.dist_net_ticktime = 60
  85. ## Distributed node port range
  86. ## node.dist_listen_min = 6000
  87. ## node.dist_listen_max = 6999
  88. The two most important parameters for Erlang VM:
  89. +--------------------------+---------------------------------------------------------------------------+
  90. | node.process_limit | Max number of Erlang proccesses. A MQTT client consumes two proccesses. |
  91. | | The value should be larger than max_clients * 2 |
  92. +--------------------------+---------------------------------------------------------------------------+
  93. | node.max_ports | Max number of Erlang Ports. A MQTT client consumes one port. |
  94. | | The value should be larger than max_clients. |
  95. +--------------------------+---------------------------------------------------------------------------+
  96. ------------------
  97. Log Level and File
  98. ------------------
  99. Console Log
  100. -----------
  101. .. code-block:: properties
  102. ## Console log. Enum: off, file, console, both
  103. log.console = console
  104. ## Console log level. Enum: debug, info, notice, warning, error, critical, alert, emergency
  105. log.console.level = error
  106. ## Console log file
  107. ## log.console.file = log/console.log
  108. Error Log
  109. ---------
  110. .. code-block:: properties
  111. ## Error log file
  112. log.error.file = log/error.log
  113. Crash Log
  114. ---------
  115. .. code-block:: properties
  116. ## Enable the crash log. Enum: on, off
  117. log.crash = on
  118. log.crash.file = log/crash.log
  119. ------------------------
  120. MQTT Protocol Parameters
  121. ------------------------
  122. Maximum ClientId Length
  123. -----------------------
  124. .. code-block:: properties
  125. ## Max ClientId Length Allowed.
  126. mqtt.max_clientid_len = 1024
  127. Maximum Packet Size
  128. -------------------
  129. .. code-block:: properties
  130. ## Max Packet Size Allowed, 64K by default.
  131. mqtt.max_packet_size = 64KB
  132. MQTT Client Idle Timeout
  133. ------------------------
  134. .. code-block:: properties
  135. ## Client Idle Timeout (Second)
  136. mqtt.client_idle_timeout = 30
  137. ----------------------------
  138. Allow Anonymous and ACL File
  139. ----------------------------
  140. Allow Anonymous
  141. ---------------
  142. .. code-block:: properties
  143. ## Allow Anonymous authentication
  144. mqtt.allow_anonymous = true
  145. Default ACL File
  146. ----------------
  147. Enable the default ACL module:
  148. .. code-block:: properties
  149. ## Default ACL File
  150. mqtt.acl_file = etc/acl.conf
  151. Define ACL rules in etc/acl.conf. The rules by default:
  152. .. code-block:: erlang
  153. %% Allow 'dashboard' to subscribe '$SYS/#'
  154. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
  155. %% Allow clients from localhost to subscribe any topics
  156. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
  157. %% Deny clients to subscribe '$SYS#' and '#'
  158. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
  159. %% Allow all by default
  160. {allow, all}.
  161. An ACL rule is an Erlang tuple. The Access control module of *EMQ* broker matches the rule one by one from top to bottom::
  162. --------- --------- ---------
  163. Client -> | Rule1 | --nomatch--> | Rule2 | --nomatch--> | Rule3 | --> Default
  164. --------- --------- ---------
  165. | | |
  166. match match match
  167. \|/ \|/ \|/
  168. allow | deny allow | deny allow | deny
  169. -----------------------
  170. MQTT Session Parameters
  171. -----------------------
  172. .. code-block:: properties
  173. ## Max number of QoS 1 and 2 messages that can be “inflight” at one time.
  174. ## 0 means no limit
  175. mqtt.session.max_inflight = 100
  176. ## Retry interval for redelivering QoS1/2 messages.
  177. mqtt.session.retry_interval = 60
  178. ## Awaiting PUBREL Timeout
  179. mqtt.session.await_rel_timeout = 20
  180. ## Max Packets that Awaiting PUBREL, 0 means no limit
  181. mqtt.session.max_awaiting_rel = 0
  182. ## Statistics Collection Interval(seconds)
  183. mqtt.session.collect_interval = 0
  184. ## Expired after 1 day:
  185. ## w - week
  186. ## d - day
  187. ## h - hour
  188. ## m - minute
  189. ## s - second
  190. mqtt.session.expired_after = 1d
  191. +------------------------------+----------------------------------------------------------+
  192. | session.max_inflight | Max number of QoS1/2 messages that can be delivered in |
  193. | | the same time |
  194. +------------------------------+----------------------------------------------------------+
  195. | session.retry_interval | Retry interval for unacked QoS1/2 messages. |
  196. +------------------------------+----------------------------------------------------------+
  197. | session.await_rel_timeout | Awaiting PUBREL Timeout |
  198. +------------------------------+----------------------------------------------------------+
  199. | session.max_awaiting_rel | Max number of Packets that Awaiting PUBREL |
  200. +------------------------------+----------------------------------------------------------+
  201. | session.collect_interval | Interval of Statistics Collection |
  202. +------------------------------+----------------------------------------------------------+
  203. | session.expired_after | Expired after (unit: minute) |
  204. +------------------------------+----------------------------------------------------------+
  205. ------------------
  206. MQTT Message Queue
  207. ------------------
  208. The message queue of session stores:
  209. 1. Offline messages for persistent session.
  210. 2. Pending messages for inflight window is full
  211. Queue parameters:
  212. .. code-block:: properties
  213. ## Type: simple | priority
  214. mqtt.queue.type = simple
  215. ## Topic Priority: 0~255, Default is 0
  216. ## mqtt.queue.priority = topic/1=10,topic/2=8
  217. ## Max queue length. Enqueued messages when persistent client disconnected,
  218. ## or inflight window is full.
  219. mqtt.queue.max_length = infinity
  220. ## Low-water mark of queued messages
  221. mqtt.queue.low_watermark = 20%
  222. ## High-water mark of queued messages
  223. mqtt.queue.high_watermark = 60%
  224. ## Queue Qos0 messages?
  225. mqtt.queue.qos0 = true
  226. +----------------------+---------------------------------------------------+
  227. | queue.type | Queue type: simple or priority |
  228. +----------------------+---------------------------------------------------+
  229. | queue.priority | Topic priority |
  230. +----------------------+---------------------------------------------------+
  231. | queue.max_length | Max Queue size, infinity means no limit |
  232. +----------------------+---------------------------------------------------+
  233. | queue.low_watermark | Low watermark |
  234. +----------------------+---------------------------------------------------+
  235. | queue.high_watermark | High watermark |
  236. +----------------------+---------------------------------------------------+
  237. | queue.qos0 | If Qos0 message queued? |
  238. +----------------------+---------------------------------------------------+
  239. ----------------------
  240. Sys Interval of Broker
  241. ----------------------
  242. .. code-block:: properties
  243. ## System Interval of publishing broker $SYS Messages
  244. mqtt.broker.sys_interval = 60
  245. -----------------
  246. PubSub Parameters
  247. -----------------
  248. .. code-block:: properties
  249. ## PubSub Pool Size. Default should be scheduler numbers.
  250. mqtt.pubsub.pool_size = 8
  251. mqtt.pubsub.by_clientid = true
  252. ##TODO: Subscribe Asynchronously
  253. mqtt.pubsub.async = true
  254. ----------------------
  255. MQTT Bridge Parameters
  256. ----------------------
  257. .. code-block:: properties
  258. ## Bridge Queue Size
  259. mqtt.bridge.max_queue_len = 10000
  260. ## Ping Interval of bridge node. Unit: Second
  261. mqtt.bridge.ping_down_interval = 1
  262. -------------------
  263. Plugins' Etc Folder
  264. -------------------
  265. .. code-block:: properties
  266. ## Dir of plugins' config
  267. mqtt.plugins.etc_dir = etc/plugins/
  268. ## File to store loaded plugin names.
  269. mqtt.plugins.loaded_file = data/loaded_plugins
  270. --------------
  271. MQTT Listeners
  272. --------------
  273. Configure the TCP listeners for MQTT, MQTT(SSL), HTTP and HTTPS Protocols.
  274. The most important parameter for MQTT listener is `max_clients`: max concurrent clients allowed.
  275. The TCP Ports occupied by the *EMQ* broker by default:
  276. +-----------+-----------------------------------+
  277. | 1883 | MQTT Port |
  278. +-----------+-----------------------------------+
  279. | 8883 | MQTT(SSL) Port |
  280. +-----------+-----------------------------------+
  281. | 8083 | MQTT(WebSocket), HTTP API Port |
  282. +-----------+-----------------------------------+
  283. Listener Parameters:
  284. +-----------------------------+-------------------------------------------------------+
  285. | mqtt.listener.*.acceptors | TCP Acceptor Pool |
  286. +-----------------------------+-------------------------------------------------------+
  287. | mqtt.listener.*.max_clients | Maximum number of concurrent TCP connections allowed |
  288. +-----------------------------+-------------------------------------------------------+
  289. | mqtt.listener.*.rate_limit | Maximum number of concurrent TCP connections allowed |
  290. +-----------------------------+-------------------------------------------------------+
  291. TCP Listener - 1883
  292. -------------------
  293. .. code-block:: properties
  294. ## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883
  295. mqtt.listener.tcp = 1883
  296. ## Size of acceptor pool
  297. mqtt.listener.tcp.acceptors = 8
  298. ## Maximum number of concurrent clients
  299. mqtt.listener.tcp.max_clients = 1024
  300. ## Rate Limit. Format is 'burst,rate', Unit is KB/Sec
  301. ## mqtt.listener.tcp.rate_limit = 100,10
  302. ## TCP Socket Options
  303. mqtt.listener.tcp.backlog = 1024
  304. ## mqtt.listener.tcp.recbuf = 4096
  305. ## mqtt.listener.tcp.sndbuf = 4096
  306. ## mqtt.listener.tcp.buffer = 4096
  307. ## mqtt.listener.tcp.nodelay = true
  308. SSL Listener - 8883
  309. -------------------
  310. .. code-block:: properties
  311. ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883
  312. mqtt.listener.ssl = 8883
  313. ## Size of acceptor pool
  314. mqtt.listener.ssl.acceptors = 4
  315. ## Maximum number of concurrent clients
  316. mqtt.listener.ssl.max_clients = 512
  317. ## Rate Limit. Format is 'burst,rate', Unit is KB/Sec
  318. ## mqtt.listener.ssl.rate_limit = 100,10
  319. ## SSL Options
  320. mqtt.listener.ssl.handshake_timeout = 15
  321. mqtt.listener.ssl.keyfile = etc/certs/key.pem
  322. mqtt.listener.ssl.certfile = etc/certs/cert.pem
  323. mqtt.listener.ssl.cacertfile = etc/certs/cacert.pem
  324. ## mqtt.listener.ssl.verify = verify_peer
  325. ## mqtt.listener.ssl.fail_if_no_peer_cert = true
  326. HTTP/WS Listener - 8083
  327. -----------------------
  328. .. code-block:: properties
  329. ## HTTP and WebSocket Listener
  330. mqtt.listener.http = 8083
  331. mqtt.listener.http.acceptors = 4
  332. mqtt.listener.http.max_clients = 64
  333. HTTPS/WSS Listener - 8084
  334. -------------------------
  335. .. code-block:: properties
  336. ## HTTP(SSL) Listener
  337. mqtt.listener.https = 8084
  338. mqtt.listener.https.acceptors = 4
  339. mqtt.listener.https.max_clients = 64
  340. mqtt.listener.https.handshake_timeout = 10
  341. mqtt.listener.https.certfile = etc/certs/cert.pem
  342. mqtt.listener.https.keyfile = etc/certs/key.pem
  343. mqtt.listener.https.cacertfile = etc/certs/cacert.pem
  344. ## 开启双向认证
  345. ## mqtt.listener.https.verify = verify_peer
  346. ## mqtt.listener.https.fail_if_no_peer_cert = true
  347. --------------
  348. System Monitor
  349. --------------
  350. .. code-block:: properties
  351. ## Long GC, don't monitor in production mode for:
  352. sysmon.long_gc = false
  353. ## Long Schedule(ms)
  354. sysmon.long_schedule = 240
  355. ## 8M words. 32MB on 32-bit VM, 64MB on 64-bit VM.
  356. sysmon.large_heap = 8MB
  357. ## Busy Port
  358. sysmon.busy_port = false
  359. ## Busy Dist Port
  360. sysmon.busy_dist_port = true
  361. --------------------------
  362. Plugin Configuration Files
  363. --------------------------
  364. +----------------------------------------+-----------------------------------+
  365. | File | Description |
  366. +----------------------------------------+-----------------------------------+
  367. | etc/plugins/emq_auth_username.conf | Username/Password Auth Plugin |
  368. +----------------------------------------+-----------------------------------+
  369. | etc/plugins/emq_auth_clientid.conf | ClientId Auth Plugin |
  370. +----------------------------------------+-----------------------------------+
  371. | etc/plugins/emq_auth_http.conf | HTTP Auth/ACL Plugin Config |
  372. +----------------------------------------+-----------------------------------+
  373. | etc/plugins/emq_auth_mongo.conf | MongoDB Auth/ACL Plugin Config |
  374. +----------------------------------------+-----------------------------------+
  375. | etc/plugins/emq_auth_mysql.conf | MySQL Auth/ACL Plugin Config |
  376. +----------------------------------------+-----------------------------------+
  377. | etc/plugins/emq_auth_pgsql.conf | Postgre Auth/ACL Plugin Config |
  378. +----------------------------------------+-----------------------------------+
  379. | etc/plugins/emq_auth_redis.conf | Redis Auth/ACL Plugin Config |
  380. +----------------------------------------+-----------------------------------+
  381. | etc/plugins/emq_coap.conf | CoAP Protocol Plugin Config |
  382. +----------------------------------------+-----------------------------------+
  383. | etc/plugins/emq_mod_presence.conf | Presence Module Config |
  384. +----------------------------------------+-----------------------------------+
  385. | etc/plugins/emq_mod_retainer.conf | Retainer Module Config |
  386. +----------------------------------------+-----------------------------------+
  387. | etc/plugins/emq_mod_rewrite.config | Rewrite Module Config |
  388. +----------------------------------------+-----------------------------------+
  389. | etc/plugins/emq_mod_subscription.conf | Subscription Module Config |
  390. +----------------------------------------+-----------------------------------+
  391. | etc/plugins/emq_dashboard.conf | Dashboard Plugin Config |
  392. +----------------------------------------+-----------------------------------+
  393. | etc/plugins/emq_plugin_template.conf | Template Plugin Config |
  394. +----------------------------------------+-----------------------------------+
  395. | etc/plugins/emq_recon.conf | Recon Plugin Config |
  396. +----------------------------------------+-----------------------------------+
  397. | etc/plugins/emq_reloader.conf | Reloader Plugin Config |
  398. +----------------------------------------+-----------------------------------+
  399. | etc/plugins/emq_sn.conf | MQTT-SN Protocal Plugin Config |
  400. +----------------------------------------+-----------------------------------+
  401. | etc/plugins/emq_stomp.conf | Stomp Protocl Plugin Config |
  402. +----------------------------------------+-----------------------------------+