diff --git a/cdn/config/config_test.go b/cdn/config/config_test.go index 3e6db0472b1..8de2fd34b4a 100644 --- a/cdn/config/config_test.go +++ b/cdn/config/config_test.go @@ -139,6 +139,7 @@ func TestConfig_Convert(t *testing.T) { }, RPCServer: rpcserver.Config{ AdvertiseIP: "127.0.0.1", + Listen: "0.0.0.0", ListenPort: 8006, DownloadPort: 8000, }, diff --git a/cdn/config/old_config.go b/cdn/config/old_config.go index e847d7655b8..597640d0ac2 100644 --- a/cdn/config/old_config.go +++ b/cdn/config/old_config.go @@ -78,6 +78,7 @@ func (c DeprecatedConfig) Convert() *Config { newConfig.CDN.MaxBandwidth = baseProperties.MaxBandwidth newConfig.RPCServer = rpcserver.Config{ AdvertiseIP: baseProperties.AdvertiseIP, + Listen: "0.0.0.0", ListenPort: baseProperties.ListenPort, DownloadPort: baseProperties.DownloadPort, } diff --git a/cdn/rpcserver/config.go b/cdn/rpcserver/config.go index 4abd5c62801..fae25f4364c 100644 --- a/cdn/rpcserver/config.go +++ b/cdn/rpcserver/config.go @@ -28,6 +28,9 @@ type Config struct { // By default, the first non-loop address is advertised. AdvertiseIP string `yaml:"advertiseIP" mapstructure:"advertiseIP"` + // Listen stands listen interface, like: 0.0.0.0, 192.168.0.1 + Listen string `yaml:"listen" mapstructure:"listen"` + // ListenPort is the port cdn server listens on. // default: 8002 ListenPort int `yaml:"listenPort" mapstructure:"listenPort"` @@ -46,6 +49,9 @@ func (c Config) applyDefaults() Config { if c.AdvertiseIP == "" { c.AdvertiseIP = iputils.IPv4 } + if c.Listen == "" { + c.Listen = "0.0.0.0" + } if c.ListenPort == 0 { c.ListenPort = DefaultListenPort } diff --git a/cdn/rpcserver/rpcserver.go b/cdn/rpcserver/rpcserver.go index 230891662b3..b4848f895c3 100644 --- a/cdn/rpcserver/rpcserver.go +++ b/cdn/rpcserver/rpcserver.go @@ -250,7 +250,7 @@ func (css *Server) SyncPieceTasks(sync cdnsystem.Seeder_SyncPieceTasksServer) er func (css *Server) ListenAndServe() error { // Generate GRPC listener - lis, _, err := rpc.ListenWithPortRange(css.config.AdvertiseIP, css.config.ListenPort, css.config.ListenPort) + lis, _, err := rpc.ListenWithPortRange(css.config.Listen, css.config.ListenPort, css.config.ListenPort) if err != nil { return err } diff --git a/scheduler/config/config.go b/scheduler/config/config.go index 1a3a98d3eba..30c02c2ffdc 100644 --- a/scheduler/config/config.go +++ b/scheduler/config/config.go @@ -59,9 +59,10 @@ type Config struct { func New() *Config { return &Config{ Server: &ServerConfig{ - IP: iputils.IPv4, - Host: hostutils.FQDNHostname, - Port: 8002, + IP: iputils.IPv4, + Host: hostutils.FQDNHostname, + Listen: "0.0.0.0", + Port: 8002, }, Scheduler: &SchedulerConfig{ Algorithm: "default", @@ -123,6 +124,10 @@ func (c *Config) Validate() error { return errors.New("server requires parameter port") } + if c.Server.Listen == "" { + return errors.New("server requires parameter listen") + } + if c.Scheduler.Algorithm == "" { return errors.New("scheduler requires parameter algorithm") } @@ -213,6 +218,9 @@ type ServerConfig struct { // Server hostname Host string `yaml:"host" mapstructure:"host"` + // Listen stands listen interface, like: 0.0.0.0, 192.168.0.1 + Listen string `yaml:"listen" mapstructure:"listen"` + // Server port Port int `yaml:"port" mapstructure:"port"` diff --git a/scheduler/config/config_test.go b/scheduler/config/config_test.go index 7b7e19911d4..70ad238970f 100644 --- a/scheduler/config/config_test.go +++ b/scheduler/config/config_test.go @@ -33,6 +33,7 @@ func TestConfig_Load(t *testing.T) { Server: &ServerConfig{ IP: "127.0.0.1", Host: "foo", + Listen: "0.0.0.0", Port: 8002, CacheDir: "foo", LogDir: "bar", diff --git a/scheduler/config/testdata/scheduler.yaml b/scheduler/config/testdata/scheduler.yaml index 3a88b515fcd..ed3f7aa20f8 100644 --- a/scheduler/config/testdata/scheduler.yaml +++ b/scheduler/config/testdata/scheduler.yaml @@ -1,6 +1,7 @@ server: ip: 127.0.0.1 host: foo + listen: 0.0.0.0 port: 8002 cacheDir: foo logDir: bar diff --git a/scheduler/scheduler.go b/scheduler/scheduler.go index 20fa4760940..641ab6db1a2 100644 --- a/scheduler/scheduler.go +++ b/scheduler/scheduler.go @@ -199,7 +199,7 @@ func (s *Server) Serve() error { } // Generate GRPC limit listener - listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.IP, s.config.Server.Port)) + listener, err := net.Listen("tcp", fmt.Sprintf("%s:%d", s.config.Server.Listen, s.config.Server.Port)) if err != nil { logger.Fatalf("net listener failed to start: %v", err) }