Support redis cluster mode (#1181)
* use redisConfig of protocol instead of redisConfig and use redis of protocol to create redis client to support redis cluster mode too
This commit is contained in:
@@ -19,6 +19,13 @@ redis:
|
|||||||
# If you use a different set of credentials for sentinel add
|
# If you use a different set of credentials for sentinel add
|
||||||
# sentinel_username: user
|
# sentinel_username: user
|
||||||
# sentinel_password: pass
|
# sentinel_password: pass
|
||||||
|
#
|
||||||
|
# To use cluster remove the address key above and add the following
|
||||||
|
# cluster_addresses:
|
||||||
|
# - livekit-redis-node-0.livekit-redis-headless:6379
|
||||||
|
# - livekit-redis-node-1.livekit-redis-headless:6380
|
||||||
|
# And it will use the password key above as cluster password
|
||||||
|
# And the db key will not be used due to cluster mode not support it.
|
||||||
|
|
||||||
# WebRTC configuration
|
# WebRTC configuration
|
||||||
rtc:
|
rtc:
|
||||||
|
|||||||
+17
-36
@@ -14,6 +14,7 @@ import (
|
|||||||
"gopkg.in/yaml.v3"
|
"gopkg.in/yaml.v3"
|
||||||
|
|
||||||
"github.com/livekit/protocol/logger"
|
"github.com/livekit/protocol/logger"
|
||||||
|
redisLiveKit "github.com/livekit/protocol/redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
var DefaultStunServers = []string{
|
var DefaultStunServers = []string{
|
||||||
@@ -33,21 +34,21 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Port uint32 `yaml:"port"`
|
Port uint32 `yaml:"port"`
|
||||||
BindAddresses []string `yaml:"bind_addresses"`
|
BindAddresses []string `yaml:"bind_addresses"`
|
||||||
PrometheusPort uint32 `yaml:"prometheus_port,omitempty"`
|
PrometheusPort uint32 `yaml:"prometheus_port,omitempty"`
|
||||||
RTC RTCConfig `yaml:"rtc,omitempty"`
|
RTC RTCConfig `yaml:"rtc,omitempty"`
|
||||||
Redis RedisConfig `yaml:"redis,omitempty"`
|
Redis redisLiveKit.RedisConfig `yaml:"redis,omitempty"`
|
||||||
Audio AudioConfig `yaml:"audio,omitempty"`
|
Audio AudioConfig `yaml:"audio,omitempty"`
|
||||||
Video VideoConfig `yaml:"video,omitempty"`
|
Video VideoConfig `yaml:"video,omitempty"`
|
||||||
Room RoomConfig `yaml:"room,omitempty"`
|
Room RoomConfig `yaml:"room,omitempty"`
|
||||||
TURN TURNConfig `yaml:"turn,omitempty"`
|
TURN TURNConfig `yaml:"turn,omitempty"`
|
||||||
Ingress IngressConfig `yaml:"ingress,omitempty"`
|
Ingress IngressConfig `yaml:"ingress,omitempty"`
|
||||||
WebHook WebHookConfig `yaml:"webhook,omitempty"`
|
WebHook WebHookConfig `yaml:"webhook,omitempty"`
|
||||||
NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"`
|
NodeSelector NodeSelectorConfig `yaml:"node_selector,omitempty"`
|
||||||
KeyFile string `yaml:"key_file,omitempty"`
|
KeyFile string `yaml:"key_file,omitempty"`
|
||||||
Keys map[string]string `yaml:"keys,omitempty"`
|
Keys map[string]string `yaml:"keys,omitempty"`
|
||||||
Region string `yaml:"region,omitempty"`
|
Region string `yaml:"region,omitempty"`
|
||||||
// LogLevel is deprecated
|
// LogLevel is deprecated
|
||||||
LogLevel string `yaml:"log_level,omitempty"`
|
LogLevel string `yaml:"log_level,omitempty"`
|
||||||
Logging LoggingConfig `yaml:"logging,omitempty"`
|
Logging LoggingConfig `yaml:"logging,omitempty"`
|
||||||
@@ -134,18 +135,6 @@ type VideoConfig struct {
|
|||||||
DynacastPauseDelay time.Duration `yaml:"dynacast_pause_delay,omitempty"`
|
DynacastPauseDelay time.Duration `yaml:"dynacast_pause_delay,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisConfig struct {
|
|
||||||
Address string `yaml:"address"`
|
|
||||||
Username string `yaml:"username"`
|
|
||||||
Password string `yaml:"password"`
|
|
||||||
DB int `yaml:"db"`
|
|
||||||
UseTLS bool `yaml:"use_tls"`
|
|
||||||
MasterName string `yaml:"sentinel_master_name"`
|
|
||||||
SentinelUsername string `yaml:"sentinel_username"`
|
|
||||||
SentinelPassword string `yaml:"sentinel_password"`
|
|
||||||
SentinelAddresses []string `yaml:"sentinel_addresses"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type RoomConfig struct {
|
type RoomConfig struct {
|
||||||
// enable rooms to be automatically created
|
// enable rooms to be automatically created
|
||||||
AutoCreate bool `yaml:"auto_create"`
|
AutoCreate bool `yaml:"auto_create"`
|
||||||
@@ -241,7 +230,7 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
|
|||||||
Video: VideoConfig{
|
Video: VideoConfig{
|
||||||
DynacastPauseDelay: 5 * time.Second,
|
DynacastPauseDelay: 5 * time.Second,
|
||||||
},
|
},
|
||||||
Redis: RedisConfig{},
|
Redis: redisLiveKit.RedisConfig{},
|
||||||
Room: RoomConfig{
|
Room: RoomConfig{
|
||||||
AutoCreate: true,
|
AutoCreate: true,
|
||||||
EnabledCodecs: []CodecSpec{
|
EnabledCodecs: []CodecSpec{
|
||||||
@@ -331,14 +320,6 @@ func NewConfig(confString string, strictMode bool, c *cli.Context, baseFlags []c
|
|||||||
return conf, nil
|
return conf, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (conf *Config) HasRedis() bool {
|
|
||||||
return conf.Redis.Address != "" || conf.Redis.SentinelAddresses != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conf *Config) UseSentinel() bool {
|
|
||||||
return conf.Redis.SentinelAddresses != nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (conf *Config) IsTURNSEnabled() bool {
|
func (conf *Config) IsTURNSEnabled() bool {
|
||||||
if conf.TURN.Enabled && conf.TURN.TLSPort != 0 {
|
if conf.TURN.Enabled && conf.TURN.TLSPort != 0 {
|
||||||
return true
|
return true
|
||||||
|
|||||||
+2
-50
@@ -4,8 +4,6 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
|
||||||
"crypto/tls"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
|
||||||
@@ -19,7 +17,7 @@ import (
|
|||||||
"github.com/livekit/protocol/egress"
|
"github.com/livekit/protocol/egress"
|
||||||
"github.com/livekit/protocol/ingress"
|
"github.com/livekit/protocol/ingress"
|
||||||
"github.com/livekit/protocol/livekit"
|
"github.com/livekit/protocol/livekit"
|
||||||
"github.com/livekit/protocol/logger"
|
redisLiveKit "github.com/livekit/protocol/redis"
|
||||||
"github.com/livekit/protocol/webhook"
|
"github.com/livekit/protocol/webhook"
|
||||||
|
|
||||||
"github.com/livekit/livekit-server/pkg/clientconfiguration"
|
"github.com/livekit/livekit-server/pkg/clientconfiguration"
|
||||||
@@ -118,53 +116,7 @@ func createWebhookNotifier(conf *config.Config, provider auth.KeyProvider) (webh
|
|||||||
}
|
}
|
||||||
|
|
||||||
func createRedisClient(conf *config.Config) (redis.UniversalClient, error) {
|
func createRedisClient(conf *config.Config) (redis.UniversalClient, error) {
|
||||||
if !conf.HasRedis() {
|
return redisLiveKit.GetRedisClient(&conf.Redis)
|
||||||
return nil, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var rc redis.UniversalClient
|
|
||||||
var tlsConfig *tls.Config
|
|
||||||
|
|
||||||
if conf.Redis.UseTLS {
|
|
||||||
tlsConfig = &tls.Config{
|
|
||||||
MinVersion: tls.VersionTLS12,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
values := make([]interface{}, 0)
|
|
||||||
values = append(values, "sentinel", conf.UseSentinel())
|
|
||||||
if conf.UseSentinel() {
|
|
||||||
values = append(values, "addr", conf.Redis.SentinelAddresses, "masterName", conf.Redis.MasterName)
|
|
||||||
rcOptions := &redis.FailoverOptions{
|
|
||||||
SentinelAddrs: conf.Redis.SentinelAddresses,
|
|
||||||
SentinelUsername: conf.Redis.SentinelUsername,
|
|
||||||
SentinelPassword: conf.Redis.SentinelPassword,
|
|
||||||
MasterName: conf.Redis.MasterName,
|
|
||||||
Username: conf.Redis.Username,
|
|
||||||
Password: conf.Redis.Password,
|
|
||||||
DB: conf.Redis.DB,
|
|
||||||
TLSConfig: tlsConfig,
|
|
||||||
}
|
|
||||||
rc = redis.NewFailoverClient(rcOptions)
|
|
||||||
} else {
|
|
||||||
values = append(values, "addr", conf.Redis.Address)
|
|
||||||
rcOptions := &redis.Options{
|
|
||||||
Addr: conf.Redis.Address,
|
|
||||||
Username: conf.Redis.Username,
|
|
||||||
Password: conf.Redis.Password,
|
|
||||||
DB: conf.Redis.DB,
|
|
||||||
TLSConfig: tlsConfig,
|
|
||||||
}
|
|
||||||
rc = redis.NewClient(rcOptions)
|
|
||||||
}
|
|
||||||
logger.Infow("using multi-node routing via redis", values...)
|
|
||||||
|
|
||||||
if err := rc.Ping(context.Background()).Err(); err != nil {
|
|
||||||
err = errors.Wrap(err, "unable to connect to redis")
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return rc, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func createStore(rc redis.UniversalClient) ObjectStore {
|
func createStore(rc redis.UniversalClient) ObjectStore {
|
||||||
|
|||||||
Reference in New Issue
Block a user