configuration.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. Configuration
  2. =============
  3. TODO:...
  4. Configuration files include:
  5. +-------------------+-----------------------------------+
  6. | File | Description |
  7. +-------------------+-----------------------------------+
  8. | etc/vm.args | Erlang VM Arguments |
  9. +-------------------+-----------------------------------+
  10. | etc/app.config | emqttd Broker Configuration |
  11. +-------------------+-----------------------------------+
  12. | etc/acl.config | ACL Rules Config |
  13. +-------------------+-----------------------------------+
  14. | etc/clients.config| Authentication with clientId |
  15. +-------------------+-----------------------------------+
  16. | etc/ssl/* | SSL certificate and key files |
  17. +-------------------+-----------------------------------+
  18. etc/vm.args
  19. -----------
  20. Configure/Optimize the Erlang VM::
  21. ##-------------------------------------------------------------------------
  22. ## Name of the node
  23. ##-------------------------------------------------------------------------
  24. -name emqttd@127.0.0.1
  25. ## Cookie for distributed erlang
  26. -setcookie emqttdsecretcookie
  27. ##-------------------------------------------------------------------------
  28. ## Flags
  29. ##-------------------------------------------------------------------------
  30. ## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive
  31. ## (Disabled by default..use with caution!)
  32. ##-heart
  33. -smp true
  34. ## Enable kernel poll and a few async threads
  35. +K true
  36. ## 12 threads/core.
  37. +A 48
  38. ## max process numbers
  39. +P 8192
  40. ## Sets the maximum number of simultaneously existing ports for this system
  41. +Q 8192
  42. ## max atom number
  43. ## +t
  44. ## Set the distribution buffer busy limit (dist_buf_busy_limit) in kilobytes.
  45. ## Valid range is 1-2097151. Default is 1024.
  46. ## +zdbbl 8192
  47. ## CPU Schedulers
  48. ## +sbt db
  49. ##-------------------------------------------------------------------------
  50. ## Env
  51. ##-------------------------------------------------------------------------
  52. ## Increase number of concurrent ports/sockets, deprecated in R17
  53. -env ERL_MAX_PORTS 8192
  54. -env ERTS_MAX_PORTS 8192
  55. -env ERL_MAX_ETS_TABLES 1024
  56. ## Tweak GC to run more often
  57. -env ERL_FULLSWEEP_AFTER 1000
  58. .. NOTE:: +P Number > 2 * Max Connections
  59. etc/app.config
  60. --------------
  61. TODO: The main configuration file for emqttd broker. Configure authentication, ACL, mqtt protocol parameters and listeners of the broker.
  62. TODO: The file is erlang format.
  63. Authentication and ACL::
  64. %% Authentication and Authorization
  65. {access, [
  66. %% Authetication. Anonymous Default
  67. {auth, [
  68. %% Authentication with username, password
  69. %{username, []},
  70. %% Authentication with clientid
  71. %{clientid, [{password, no}, {file, "etc/clients.config"}]},
  72. %% Authentication with LDAP
  73. % {ldap, [
  74. % {servers, ["localhost"]},
  75. % {port, 389},
  76. % {timeout, 30},
  77. % {user_dn, "uid=$u,ou=People,dc=example,dc=com"},
  78. % {ssl, fasle},
  79. % {sslopts, [
  80. % {"certfile", "ssl.crt"},
  81. % {"keyfile", "ssl.key"}]}
  82. % ]},
  83. %% Allow all
  84. {anonymous, []}
  85. ]},
  86. %% ACL config
  87. {acl, [
  88. %% Internal ACL module
  89. {internal, [{file, "etc/acl.config"}, {nomatch, allow}]}
  90. ]}
  91. ]},
  92. MQTT Packet, Client, Session, MQueue::
  93. {mqtt, [
  94. %% Packet
  95. {packet, [
  96. %% Max ClientId Length Allowed
  97. {max_clientid_len, 1024},
  98. %% Max Packet Size Allowed, 64K default
  99. {max_packet_size, 65536}
  100. ]},
  101. %% Client
  102. {client, [
  103. %% Socket is connected, but no 'CONNECT' packet received
  104. {idle_timeout, 20} %% seconds
  105. %TODO: Network ingoing limit
  106. %{ingoing_rate_limit, '64KB/s'}
  107. %TODO: Reconnet control
  108. ]},
  109. %% Session
  110. {session, [
  111. %% Max number of QoS 1 and 2 messages that can be “in flight” at one time.
  112. %% 0 means no limit
  113. {max_inflight, 100},
  114. %% Retry interval for redelivering QoS1/2 messages.
  115. {unack_retry_interval, 60},
  116. %% Awaiting PUBREL Timeout
  117. {await_rel_timeout, 20},
  118. %% Max Packets that Awaiting PUBREL, 0 means no limit
  119. {max_awaiting_rel, 0},
  120. %% Statistics Collection Interval(seconds)
  121. {collect_interval, 0},
  122. %% Expired after 2 days
  123. {expired_after, 48}
  124. ]},
  125. %% Session
  126. {queue, [
  127. %% Max queue length. enqueued messages when persistent client disconnected,
  128. %% or inflight window is full.
  129. {max_length, 100},
  130. %% Low-water mark of queued messages
  131. {low_watermark, 0.2},
  132. %% High-water mark of queued messages
  133. {high_watermark, 0.6},
  134. %% Queue Qos0 messages?
  135. {queue_qos0, true}
  136. ]}
  137. ]},
  138. Broker Options::
  139. {broker, [
  140. %% System interval of publishing broker $SYS messages
  141. {sys_interval, 60},
  142. %% Retained messages
  143. {retained, [
  144. %% Expired after seconds, never expired if 0
  145. {expired_after, 0},
  146. %% Max number of retained messages
  147. {max_message_num, 100000},
  148. %% Max Payload Size of retained message
  149. {max_playload_size, 65536}
  150. ]},
  151. %% PubSub and Router
  152. {pubsub, [
  153. %% Default should be scheduler numbers
  154. %% {pool_size, 8},
  155. %% Subscription: disc | ram | false
  156. {subscription, ram},
  157. %% Route shard
  158. {route_shard, false},
  159. %% Route delay, false | integer
  160. {route_delay, false},
  161. %% Route aging time(seconds)
  162. {route_aging, 5}
  163. ]},
  164. %% Bridge
  165. {bridge, [
  166. %%TODO: bridge queue size
  167. {max_queue_len, 10000},
  168. %% Ping Interval of bridge node
  169. {ping_down_interval, 1} %seconds
  170. ]}
  171. ]},
  172. Extended Modules::
  173. {modules, [
  174. %% Client presence management module.
  175. %% Publish messages when client connected or disconnected
  176. {presence, [{qos, 0}]}
  177. %% Subscribe topics automatically when client connected
  178. %% {subscription, [
  179. %% %% Subscription from stored table
  180. %% stored,
  181. %%
  182. %% %% $u will be replaced with username
  183. %% {"$Q/username/$u", 1},
  184. %%
  185. %% %% $c will be replaced with clientid
  186. %% {"$Q/client/$c", 1}
  187. %% ]}
  188. %% Rewrite rules
  189. %% {rewrite, [{file, "etc/rewrite.config"}]}
  190. ]},
  191. Listeners::
  192. {listeners, [
  193. {mqtt, 1883, [
  194. %% Size of acceptor pool
  195. {acceptors, 16},
  196. %% Maximum number of concurrent clients
  197. {max_clients, 8192},
  198. %% Socket Access Control
  199. {access, [{allow, all}]},
  200. %% Connection Options
  201. {connopts, [
  202. %% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
  203. %% {rate_limit, "100,10"} %% 100K burst, 10K rate
  204. ]},
  205. %% Socket Options
  206. {sockopts, [
  207. %Set buffer if hight thoughtput
  208. %{recbuf, 4096},
  209. %{sndbuf, 4096},
  210. %{buffer, 4096},
  211. %{nodelay, true},
  212. {backlog, 1024}
  213. ]}
  214. ]},
  215. {mqtts, 8883, [
  216. %% Size of acceptor pool
  217. {acceptors, 4},
  218. %% Maximum number of concurrent clients
  219. {max_clients, 512},
  220. %% Socket Access Control
  221. {access, [{allow, all}]},
  222. %% SSL certificate and key files
  223. {ssl, [{certfile, "etc/ssl/ssl.crt"},
  224. {keyfile, "etc/ssl/ssl.key"}]},
  225. %% Socket Options
  226. {sockopts, [
  227. {backlog, 1024}
  228. %{buffer, 4096},
  229. ]}
  230. ]},
  231. %% WebSocket over HTTPS Listener
  232. %% {https, 8083, [
  233. %% %% Size of acceptor pool
  234. %% {acceptors, 4},
  235. %% %% Maximum number of concurrent clients
  236. %% {max_clients, 512},
  237. %% %% Socket Access Control
  238. %% {access, [{allow, all}]},
  239. %% %% SSL certificate and key files
  240. %% {ssl, [{certfile, "etc/ssl/ssl.crt"},
  241. %% {keyfile, "etc/ssl/ssl.key"}]},
  242. %% %% Socket Options
  243. %% {sockopts, [
  244. %% %{buffer, 4096},
  245. %% {backlog, 1024}
  246. %% ]}
  247. %%]},
  248. %% HTTP and WebSocket Listener
  249. {http, 8083, [
  250. %% Size of acceptor pool
  251. {acceptors, 4},
  252. %% Maximum number of concurrent clients
  253. {max_clients, 64},
  254. %% Socket Access Control
  255. {access, [{allow, all}]},
  256. %% Socket Options
  257. {sockopts, [
  258. {backlog, 1024}
  259. %{buffer, 4096},
  260. ]}
  261. ]}
  262. ]},
  263. etc/acl.config
  264. --------------
  265. Configuration file for ACL::
  266. %%%-----------------------------------------------------------------------------
  267. %%%
  268. %%% -type who() :: all | binary() |
  269. %%% {ipaddr, esockd_access:cidr()} |
  270. %%% {client, binary()} |
  271. %%% {user, binary()}.
  272. %%%
  273. %%% -type access() :: subscribe | publish | pubsub.
  274. %%%
  275. %%% -type topic() :: binary().
  276. %%%
  277. %%% -type rule() :: {allow, all} |
  278. %%% {allow, who(), access(), list(topic())} |
  279. %%% {deny, all} |
  280. %%% {deny, who(), access(), list(topic())}.
  281. %%%
  282. %%%-----------------------------------------------------------------------------
  283. {allow, {user, "dashboard"}, subscribe, ["$SYS/#"]}.
  284. {allow, {ipaddr, "127.0.0.1"}, pubsub, ["$SYS/#", "#"]}.
  285. {deny, all, subscribe, ["$SYS/#", {eq, "#"}]}.
  286. {allow, all}.
  287. .. NOTE:: Allow 'localhost' to pubsub '$SYS/#' and '#' by default.
  288. etc/clients.config
  289. ------------------
  290. TODO:
  291. testclientid0
  292. testclientid1 127.0.0.1
  293. testclientid2 192.168.0.1/24