From 9f391f15425c092308069dea89dcf888825c730c Mon Sep 17 00:00:00 2001 From: Feng Lee Date: Fri, 14 Oct 2016 10:49:40 +0800 Subject: [PATCH] Improve listener config --- etc/emq.conf | 28 ++++++------------- priv/emq.schema | 74 +++++++++++++++++++++++++------------------------ 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/etc/emq.conf b/etc/emq.conf index 52e0db7dc..a266ba003 100644 --- a/etc/emq.conf +++ b/etc/emq.conf @@ -2,7 +2,7 @@ ## Node Args ##-------------------------------------------------------------------- -## Node Name +## Node name node.name = emqttd@127.0.0.1 ## Cookie for distributed node @@ -100,13 +100,13 @@ mqtt.session.max_awaiting_rel = 0 ## Statistics Collection Interval(seconds) mqtt.session.collect_interval = 0 -## Expired after 2 day: +## Expired after 1 day: ## w - week ## d - day ## h - hour ## m - minute ## s - second -mqtt.session.expired_after = 2d +mqtt.session.expired_after = 1d ##-------------------------------------------------------------------- ## MQTT Queue @@ -167,7 +167,7 @@ mqtt.plugins.etc_dir = etc/plugins/ mqtt.plugins.loaded_file = data/loaded_plugins ##-------------------------------------------------------------------- -## TCP Listener +## MQTT Listeners ##-------------------------------------------------------------------- ## TCP Listener: 1883, 127.0.0.1:1883, ::1:1883 @@ -189,10 +189,6 @@ mqtt.listener.tcp.backlog = 1024 ## mqtt.listener.tcp.buffer = 4096 ## mqtt.listener.tcp.nodelay = true -##-------------------------------------------------------------------- -## SSL Listener -##-------------------------------------------------------------------- - ## SSL Listener: 8883, 127.0.0.1:8883, ::1:8883 mqtt.listener.ssl = 8883 @@ -207,27 +203,19 @@ mqtt.listener.ssl.max_clients = 512 ## Configuring SSL Options ## See http://erlang.org/doc/man/ssl.html -mqtt.listener.ssl.handshake_timeout = 10 #seconds -## mqtt.listener.ssl.keyfile = /path/to/key.pem -## mqtt.listener.ssl.certfile = /path/to/cert.pem -## mqtt.listener.ssl.cacertfile = /path/to/cacert.pem +mqtt.listener.ssl.handshake_timeout = 15 #seconds +## mqtt.listener.ssl.keyfile = etc/ssl/key.pem +## mqtt.listener.ssl.certfile = etc/ssl/cert.pem +## mqtt.listener.ssl.cacertfile = etc/ssl/cacert.pem ## mqtt.listener.ssl.verify = verify_peer ## mqtt.listener.ssl.failed_if_no_peer_cert = true -##-------------------------------------------------------------------- ## HTTP Listener -##-------------------------------------------------------------------- - mqtt.listener.http = 8083 - mqtt.listener.http.acceptors = 4 - mqtt.listener.http.max_clients = 64 -##-------------------------------------------------------------------- ## HTTP(SSL) Listener -##-------------------------------------------------------------------- - ## mqtt.listener.https = 8083 ## mqtt.listener.https.acceptors = 4 ## mqtt.listener.https.max_clients = 64 diff --git a/priv/emq.schema b/priv/emq.schema index cb57b8eab..16deda53f 100644 --- a/priv/emq.schema +++ b/priv/emq.schema @@ -510,7 +510,7 @@ end}. ]}. {mapping, "mqtt.listener.ssl.handshake_timeout", "emqttd.listeners", [ - {default, 10}, + {default, 15}, {datatype, integer} ]}. @@ -566,41 +566,43 @@ end}. ]}. {translation, "emqttd.listeners", fun(Conf) -> - Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, - TcpListeners = case cuttlefish:conf_get("mqtt.listener.tcp", Conf) of - undefined -> - []; - TcpPort -> - TcpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.tcp.acceptors", Conf)}, - {max_clients, cuttlefish:conf_get("mqtt.listener.tcp.max_clients", Conf)}, - {rate_limt, cuttlefish:conf_get("mqtt.listener.tcp.rate_limit", Conf, undefined)}], - [{tcp, TcpPort, Filter(TcpOpts)}] - end, - SslListeners = case cuttlefish:conf_get("mqtt.listener.ssl", Conf) of - undefined -> - []; - SslPort -> - SslOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.ssl.acceptors", Conf)}, - {max_clients, cuttlefish:conf_get("mqtt.listener.ssl.max_clients", Conf)}], - [{ssl, SslPort, Filter(SslOpts)}] - end, - HttpListeners = case cuttlefish:conf_get("mqtt.listener.http", Conf) of - undefined -> - []; - HttPort -> - HttpOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.http.acceptors", Conf)}, - {max_clients, cuttlefish:conf_get("mqtt.listener.http.max_clients", Conf)}], - [{http, HttPort, Filter(HttpOpts)}] - end, - HttpsListeners = case cuttlefish:conf_get("mqtt.listener.https", Conf, undefined) of - undefined -> - []; - HttsPort -> - HttpsOpts = [{acceptors, cuttlefish:conf_get("mqtt.listener.https.acceptors", Conf)}, - {max_clients, cuttlefish:conf_get("mqtt.listener.https.max_clients", Conf)}], - [{https, HttsPort, Filter(HttpsOpts)}] - end, - TcpListeners ++ SslListeners ++ HttpListeners ++ HttpsListeners + Filter = fun(Opts) -> [{K, V} || {K, V} <- Opts, V =/= undefined] end, + LisOpts = fun(Prefix) -> + Filter([{acceptors, cuttlefish:conf_get(Prefix ++ ".acceptors", Conf)}, + {max_clients, cuttlefish:conf_get(Prefix ++ ".max_clients", Conf)}, + {rate_limt, cuttlefish:conf_get(Prefix ++ ".rate_limit", Conf, undefined)}]) + end, + TcpOpts = fun(Prefix) -> + Filter([{backlog, cuttlefish:conf_get(Prefix ++ ".backlog", Conf, undefined)}, + {recbuf, cuttlefish:conf_get(Prefix ++ ".recbuf", Conf, undefined)}, + {sndbuf, cuttlefish:conf_get(Prefix ++ ".sndbuf", Conf, undefined)}, + {buffer, cuttlefish:conf_get(Prefix ++ ".buffer", Conf, undefined)}, + {nodelay, cuttlefish:conf_get(Prefix ++ ".nodelay", Conf, true)}]) + end, + SslOpts = fun(Prefix) -> + Filter([{handshake_timeout, cuttlefish:conf_get(Prefix ++ ".handshake_timeout", Conf)}, + {keyfile, cuttlefish:conf_get(Prefix ++ ".keyfile", Conf, undefined)}, + {certfile, cuttlefish:conf_get(Prefix ++ ".certfile", Conf, undefined)}, + {cacertfile, cuttlefish:conf_get(Prefix ++ ".cacertfile", Conf, undefined)}, + {verify, cuttlefish:conf_get(Prefix ++ ".verify_peer", Conf, undefined)}, + {failed_if_no_peer_cert, cuttlefish:conf_get(Prefix ++ "failed_if_no_peer_cert", Conf, undefined)}]) + end, + + Listeners = fun(Name) when is_atom(Name) -> + Key = "mqtt.listener." ++ atom_to_list(Name), + case cuttlefish:conf_get(Key, Conf, undefined) of + undefined -> + []; + Port -> + ConnOpts = Filter([{rate_limit, cuttlefish:conf_get(Key ++ ".rate_limit", Conf, undefined)}]), + Opts = [{connopts, ConnOpts}, {sockopts, TcpOpts(Key)} | LisOpts(Key)], + [{Name, Port, case Name =:= ssl orelse Name =:= https of + true -> [{ssl, SslOpts(Key)} | Opts]; + false -> Opts + end}] + end + end, + [Listeners(tcp), Listeners(ssl), Listeners(http), Listeners(https)] end}. %%--------------------------------------------------------------------