Skip to content

Commit

Permalink
For #464, support config for origin cluster.
Browse files Browse the repository at this point in the history
  • Loading branch information
winlinvip committed Feb 14, 2018
1 parent db6b8cf commit d0fbf44
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 40 deletions.
47 changes: 39 additions & 8 deletions trunk/conf/full.conf
Original file line number Diff line number Diff line change
Expand Up @@ -329,40 +329,46 @@ vhost removed.srs.com {

# vhost for stream cluster for RTMP/FLV
vhost cluster.srs.com {
# stream RTMP/FLV cluster config.
# The config for cluster.
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.
# The cluster mode, local or remote.
# local: It's an origin server, serve streams itself.
# remote: It's an edge server, fetch or push stream to origin server.
# default: local
mode remote;
# for edge(remote mode), user must specifies the origin server

# For edge(mode remote), 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,
# For edge(mode remote), 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,
# For edge(mode remote), 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,
# For edge(mode remote), 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/ossrs/srs/wiki/v1_CN_SrsLog
# default: on
debug_srs_upnode on;

# For origin (mode local) cluster, the co-worker's HTTP APIs.
# This origin will connect to co-workers and communicate with them.
# please read: https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster
coworkers 127.0.0.1:9091 127.0.0.1:9092;
}
}

Expand Down Expand Up @@ -1782,3 +1788,28 @@ vhost stream.transcode.srs.com {
}
}
}

#############################################################################################
# The origin cluster section
#############################################################################################
http_api {
enabled on;
listen 9090;
}
vhost a.origin.cluster.srs.com {
cluster {
mode local;
coworkers 127.0.0.1:9091;
}
}

http_api {
enabled on;
listen 9091;
}
vhost b.origin.cluster.srs.com {
cluster {
mode local;
coworkers 127.0.0.1:9090;
}
}
19 changes: 19 additions & 0 deletions trunk/conf/origin.cluster.serverA.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# the config for srs origin-origin cluster
# @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster
# @see full.conf for detail config.

listen 19350;
max_connections 1000;
daemon off;
srs_log_tank console;
pid ./objs/origin.cluster.serverA.pid;
http_api {
enabled on;
listen 9090;
}
vhost __defaultVhost__ {
cluster {
mode local;
coworkers 127.0.0.1:9091;
}
}
19 changes: 19 additions & 0 deletions trunk/conf/origin.cluster.serverB.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# the config for srs origin-origin cluster
# @see https://github.com/ossrs/srs/wiki/v3_EN_OriginCluster
# @see full.conf for detail config.

listen 19351;
max_connections 1000;
daemon off;
srs_log_tank console;
pid ./objs/origin.cluster.serverB.pid;
http_api {
enabled on;
listen 9091;
}
vhost __defaultVhost__ {
cluster {
mode local;
coworkers 127.0.0.1:9090;
}
}
29 changes: 28 additions & 1 deletion trunk/src/app/srs_app_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3726,7 +3726,7 @@ srs_error_t SrsConfig::check_normal_config()
} else if (n == "cluster") {
for (int j = 0; j < (int)conf->directives.size(); j++) {
string m = conf->at(j)->name;
if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode") {
if (m != "mode" && m != "origin" && m != "token_traverse" && m != "vhost" && m != "debug_srs_upnode" && m != "coworkers") {
return srs_error_new(ERROR_SYSTEM_CONFIG_INVALID, "illegal vhost.cluster.%s of %s", m.c_str(), vhost->arg0().c_str());
}
}
Expand Down Expand Up @@ -5157,6 +5157,33 @@ string SrsConfig::get_vhost_edge_transform_vhost(string vhost)
return conf->arg0();
}

vector<string> SrsConfig::get_vhost_coworkers(string vhost)
{
vector<string> coworkers;

SrsConfDirective* conf = get_vhost(vhost);
if (!conf) {
return coworkers;
}

conf = conf->get("cluster");
if (!conf) {
return coworkers;
}

conf = conf->get("coworkers");
for (int i = 0; i < (int)conf->directives.size(); i++) {
SrsConfDirective* option = conf->directives[i];
if (!option) {
continue;
}

coworkers.push_back(option->arg0());
}

return coworkers;
}

bool SrsConfig::get_security_enabled(string vhost)
{
static bool DEFAULT = false;
Expand Down
Loading

0 comments on commit d0fbf44

Please sign in to comment.