config.rst 19 KB

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