mirror of
https://github.com/ossrs/srs.git
synced 2025-02-13 03:41:55 +00:00
for #319, move the edge configs to cluster.
This commit is contained in:
parent
6bd05f9cfc
commit
2b4fa2d73e
5 changed files with 154 additions and 71 deletions
|
@ -7,6 +7,8 @@ max_connections 1000;
|
|||
pid objs/edge.pid;
|
||||
srs_log_file ./objs/edge.log;
|
||||
vhost __defaultVhost__ {
|
||||
mode remote;
|
||||
origin 127.0.0.1:19350;
|
||||
cluster {
|
||||
mode remote;
|
||||
origin 127.0.0.1:19350;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,9 @@
|
|||
listen 1935
|
||||
max_connections 1000;
|
||||
vhost __defaultVhost__ {
|
||||
mode remote;
|
||||
origin 127.0.0.1:19350;
|
||||
token_traverse on;
|
||||
cluster {
|
||||
mode remote;
|
||||
origin 127.0.0.1:19350;
|
||||
token_traverse on;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -520,6 +520,73 @@ vhost same.vhost.forward.srs.com {
|
|||
}
|
||||
}
|
||||
|
||||
# vhost for stream cluster for RTMP/FLV
|
||||
vhost cluster.srs.com {
|
||||
# stream RTMP/FLV cluster config.
|
||||
cluster {
|
||||
# the mode of vhost, local or remote.
|
||||
# local: vhost is origin vhost, which provides stream source.
|
||||
# remote: vhost is edge vhost, which pull/push to origin.
|
||||
# default: local
|
||||
mode remote;
|
||||
# for edge(remote mode), user must specifies the origin server
|
||||
# format as: <server_name|ip>[:port]
|
||||
# @remark user can specifies multiple origin for error backup, by space,
|
||||
# for example, 192.168.1.100:1935 192.168.1.101:1935 192.168.1.102:1935
|
||||
origin 127.0.0.1:1935 localhost:1935;
|
||||
|
||||
# for edge, whether open the token traverse mode,
|
||||
# if token traverse on, all connections of edge will forward to origin to check(auth),
|
||||
# it's very important for the edge to do the token auth.
|
||||
# the better way is use http callback to do the token auth by the edge,
|
||||
# but if user prefer origin check(auth), the token_traverse if better solution.
|
||||
# default: off
|
||||
token_traverse off;
|
||||
|
||||
# the vhost to transform for edge,
|
||||
# to fetch from the specified vhost at origin,
|
||||
# if not specified, use the current vhost of edge in origin, the variable [vhost].
|
||||
# default: [vhost]
|
||||
vhost same.edge.srs.com;
|
||||
|
||||
# when upnode(forward to, edge push to, edge pull from) is srs,
|
||||
# it's strongly recommend to open the debug_srs_upnode,
|
||||
# when connect to upnode, it will take the debug info,
|
||||
# for example, the id, source id, pid.
|
||||
# please see: https://github.com/simple-rtmp-server/srs/wiki/v1_CN_SrsLog
|
||||
# default: on
|
||||
debug_srs_upnode on;
|
||||
}
|
||||
}
|
||||
|
||||
# vhost for edge, edge and origin is the same vhost
|
||||
vhost same.edge.srs.com {
|
||||
# @see cluster.srs.com
|
||||
cluster {
|
||||
mode remote;
|
||||
origin 127.0.0.1:1935 localhost:1935;
|
||||
token_traverse off;
|
||||
}
|
||||
}
|
||||
|
||||
# vhost for edge, edge transform vhost to fetch from another vhost.
|
||||
vhost transform.edge.srs.com {
|
||||
# @see cluster.srs.com
|
||||
cluster {
|
||||
mode remote;
|
||||
origin 127.0.0.1:1935;
|
||||
vhost same.edge.srs.com;
|
||||
}
|
||||
}
|
||||
|
||||
# the vhost for srs debug info, whether send args in connect(tcUrl).
|
||||
vhost debug.srs.com {
|
||||
# @see cluster.srs.com
|
||||
cluster {
|
||||
debug_srs_upnode on;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -600,38 +667,6 @@ vhost security.srs.com {
|
|||
}
|
||||
}
|
||||
|
||||
# vhost for edge, edge and origin is the same vhost
|
||||
vhost same.edge.srs.com {
|
||||
# the mode of vhost, local or remote.
|
||||
# local: vhost is origin vhost, which provides stream source.
|
||||
# remote: vhost is edge vhost, which pull/push to origin.
|
||||
# default: local
|
||||
mode remote;
|
||||
# for edge(remote mode), user must specifies the origin server
|
||||
# format as: <server_name|ip>[:port]
|
||||
# @remark user can specifies multiple origin for error backup, by space,
|
||||
# for example, 192.168.1.100:1935 192.168.1.101:1935 192.168.1.102:1935
|
||||
origin 127.0.0.1:1935 localhost:1935;
|
||||
# for edge, whether open the token traverse mode,
|
||||
# if token traverse on, all connections of edge will forward to origin to check(auth),
|
||||
# it's very important for the edge to do the token auth.
|
||||
# the better way is use http callback to do the token auth by the edge,
|
||||
# but if user prefer origin check(auth), the token_traverse if better solution.
|
||||
# default: off
|
||||
token_traverse off;
|
||||
}
|
||||
|
||||
# vhost for edge, edge transform vhost to fetch from another vhost.
|
||||
vhost transform.edge.srs.com {
|
||||
mode remote;
|
||||
origin 127.0.0.1:1935;
|
||||
# the vhost to transform for edge,
|
||||
# to fetch from the specified vhost at origin,
|
||||
# if not specified, use the current vhost of edge in origin, the variable [vhost].
|
||||
# default: [vhost]
|
||||
vhost same.edge.srs.com;
|
||||
}
|
||||
|
||||
# vhost for dvr
|
||||
vhost dvr.srs.com {
|
||||
# dvr RTMP stream to file,
|
||||
|
@ -1187,17 +1222,6 @@ vhost hooks.callback.srs.com {
|
|||
}
|
||||
}
|
||||
|
||||
# the vhost for srs debug info, whether send args in connect(tcUrl).
|
||||
vhost debug.srs.com {
|
||||
# when upnode(forward to, edge push to, edge pull from) is srs,
|
||||
# it's strongly recommend to open the debug_srs_upnode,
|
||||
# when connect to upnode, it will take the debug info,
|
||||
# for example, the id, source id, pid.
|
||||
# please see: https://github.com/simple-rtmp-server/srs/wiki/v1_CN_SrsLog
|
||||
# default: on
|
||||
debug_srs_upnode on;
|
||||
}
|
||||
|
||||
# the main comments for transcode
|
||||
vhost example.transcode.srs.com {
|
||||
# the streaming transcode configs.
|
||||
|
|
|
@ -615,6 +615,9 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
// merge config.
|
||||
std::vector<ISrsReloadHandler*>::iterator it;
|
||||
|
||||
// following directly support reload.
|
||||
// origin, token_traverse, vhost, debug_srs_upnode
|
||||
|
||||
// state graph
|
||||
// old_vhost new_vhost
|
||||
// DISABLED => ENABLED
|
||||
|
@ -679,7 +682,7 @@ int SrsConfig::reload_vhost(SrsConfDirective* old_root)
|
|||
continue;
|
||||
}
|
||||
|
||||
// mode, never supports reload.
|
||||
// cluster.mode, never supports reload.
|
||||
// first, for the origin and edge role change is too complex.
|
||||
// second, the vhosts in origin device group normally are all origin,
|
||||
// they never change to edge sometimes.
|
||||
|
@ -877,8 +880,7 @@ int SrsConfig::reload_conf(SrsConfig* conf)
|
|||
//
|
||||
// always support reload without additional code:
|
||||
// chunk_size, ff_log_dir,
|
||||
// bandcheck, http_hooks, heartbeat,
|
||||
// token_traverse, debug_srs_upnode,
|
||||
// bandcheck, http_hooks, heartbeat,
|
||||
// security
|
||||
|
||||
// merge config: max_connections
|
||||
|
@ -1663,18 +1665,26 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
|
|||
obj->set("tcp_nodelay", dir->dumps_arg0_to_boolean());
|
||||
}
|
||||
|
||||
// edge.
|
||||
if ((dir = vhost->get("mode")) != NULL) {
|
||||
obj->set("mode", dir->dumps_arg0_to_str());
|
||||
}
|
||||
if ((dir = vhost->get("origin")) != NULL) {
|
||||
obj->set("origin", dir->dumps_args());
|
||||
}
|
||||
if ((dir = vhost->get("token_traverse")) != NULL) {
|
||||
obj->set("token_traverse", dir->dumps_arg0_to_boolean());
|
||||
}
|
||||
if ((dir = vhost->get("vhost")) != NULL) {
|
||||
obj->set("vhost", dir->dumps_arg0_to_str());
|
||||
// cluster.
|
||||
if ((dir = vhost->get("cluster")) != NULL) {
|
||||
SrsAmf0Object* cluster = SrsAmf0Any::object();
|
||||
obj->set("cluster", cluster);
|
||||
|
||||
for (int i = 0; i < (int)dir->directives.size(); i++) {
|
||||
SrsConfDirective* sdir = dir->directives.at(i);
|
||||
|
||||
if (sdir->name == "mode") {
|
||||
cluster->set("mode", sdir->dumps_arg0_to_str());
|
||||
} else if (sdir->name == "origin") {
|
||||
cluster->set("origin", sdir->dumps_arg0_to_str());
|
||||
} else if (sdir->name == "token_traverse") {
|
||||
cluster->set("token_traverse", sdir->dumps_arg0_to_boolean());
|
||||
} else if (sdir->name == "vhost") {
|
||||
cluster->set("vhost", sdir->dumps_arg0_to_str());
|
||||
} else if (sdir->name == "debug_srs_upnode") {
|
||||
cluster->set("debug_srs_upnode", sdir->dumps_arg0_to_boolean());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// forward
|
||||
|
@ -1693,11 +1703,6 @@ int SrsConfig::vhost_to_json(SrsConfDirective* vhost, SrsAmf0Object* obj)
|
|||
}
|
||||
}
|
||||
|
||||
// debug_srs_upnode
|
||||
if ((dir = vhost->get("debug_srs_upnode")) != NULL) {
|
||||
obj->set("debug_srs_upnode", dir->dumps_arg0_to_boolean());
|
||||
}
|
||||
|
||||
// play
|
||||
if ((dir = vhost->get("play")) != NULL) {
|
||||
SrsAmf0Object* play = SrsAmf0Any::object();
|
||||
|
@ -2602,10 +2607,9 @@ int SrsConfig::check_config()
|
|||
SrsConfDirective* conf = vhost->at(i);
|
||||
string n = conf->name;
|
||||
if (n != "enabled" && n != "chunk_size" && n != "min_latency" && n != "tcp_nodelay"
|
||||
&& n != "mode" && n != "origin" && n != "token_traverse" && n != "vhost"
|
||||
&& n != "dvr" && n != "ingest" && n != "hls" && n != "http_hooks"
|
||||
&& n != "refer" && n != "forward" && n != "transcode" && n != "bandcheck"
|
||||
&& n != "debug_srs_upnode" && n != "play" && n != "publish"
|
||||
&& n != "play" && n != "publish" && n != "cluster"
|
||||
&& n != "security" && n != "http_remux"
|
||||
&& n != "http_static" && n != "hds" && n != "exec"
|
||||
) {
|
||||
|
@ -2654,6 +2658,15 @@ int SrsConfig::check_config()
|
|||
return ret;
|
||||
}
|
||||
}
|
||||
} else if (n == "cluster") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name.c_str();
|
||||
if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode") {
|
||||
ret = ERROR_SYSTEM_CONFIG_INVALID;
|
||||
srs_error("unsupported vhost cluster directive %s, ret=%d", m.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
} else if (n == "publish") {
|
||||
for (int j = 0; j < (int)conf->directives.size(); j++) {
|
||||
string m = conf->at(j)->name.c_str();
|
||||
|
@ -3185,6 +3198,11 @@ bool SrsConfig::get_debug_srs_upnode(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("cluster");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("debug_srs_upnode");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
|
@ -3847,6 +3865,11 @@ bool SrsConfig::get_vhost_is_edge(SrsConfDirective* vhost)
|
|||
if (!conf) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("cluster");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("mode");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
|
@ -3863,6 +3886,11 @@ SrsConfDirective* SrsConfig::get_vhost_edge_origin(string vhost)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
conf = conf->get("cluster");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return conf->get("origin");
|
||||
}
|
||||
|
||||
|
@ -3875,6 +3903,11 @@ bool SrsConfig::get_vhost_edge_token_traverse(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("cluster");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("token_traverse");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
|
@ -3892,6 +3925,11 @@ string SrsConfig::get_vhost_edge_transform_vhost(string vhost)
|
|||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("cluster");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
}
|
||||
|
||||
conf = conf->get("vhost");
|
||||
if (!conf || conf->arg0().empty()) {
|
||||
return DEFAULT;
|
||||
|
@ -5827,6 +5865,23 @@ int srs_config_transform_vhost(SrsConfDirective* root)
|
|||
continue;
|
||||
}
|
||||
|
||||
// SRS3.0, change the folowing like a shadow:
|
||||
// mode, origin, token_traverse, vhost, debug_srs_upnode
|
||||
// SRS1/2:
|
||||
// vhost { shadow; }
|
||||
// SRS3+:
|
||||
// vhost { cluster { shadow; } }
|
||||
if (n == "mode" || n == "origin" || n == "token_traverse" || n == "vhost" || n == "debug_srs_upnode") {
|
||||
it = dir->directives.erase(it);
|
||||
|
||||
SrsConfDirective* cluster = dir->get_or_create("cluster");
|
||||
SrsConfDirective* shadow = cluster->get_or_create(conf->name);
|
||||
shadow->args = conf->args;
|
||||
|
||||
srs_freep(conf);
|
||||
continue;
|
||||
}
|
||||
|
||||
++it;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -688,7 +688,7 @@ public:
|
|||
* @remark this is used to protect the service bandwidth.
|
||||
*/
|
||||
virtual int get_bw_check_limit_kbps(std::string vhost);
|
||||
// vhost edge section
|
||||
// vhost cluster section
|
||||
public:
|
||||
/**
|
||||
* whether vhost is edge mode.
|
||||
|
|
Loading…
Reference in a new issue