From 3a6eb8ca5ff6a8f3fbe76933847c0b804c26ba2a Mon Sep 17 00:00:00 2001 From: chrislu Date: Fri, 11 Mar 2022 14:02:39 -0800 Subject: [PATCH] default bind to one ip address fix https://github.com/chrislusf/seaweedfs/issues/1937 --- weed/command/filer.go | 5 ++++- weed/command/master.go | 5 ++++- weed/command/master_follower.go | 6 +++++- weed/command/s3.go | 6 +++++- weed/command/server.go | 6 +++++- weed/command/volume.go | 5 ++++- 6 files changed, 27 insertions(+), 6 deletions(-) diff --git a/weed/command/filer.go b/weed/command/filer.go index 9fb6191a7..d48e19873 100644 --- a/weed/command/filer.go +++ b/weed/command/filer.go @@ -60,7 +60,7 @@ func init() { f.mastersString = cmdFiler.Flag.String("master", "localhost:9333", "comma-separated master servers") f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this default collection") f.ip = cmdFiler.Flag.String("ip", util.DetectedHostAddress(), "filer server http listen ip address") - f.bindIp = cmdFiler.Flag.String("ip.bind", "", "ip address to bind to") + f.bindIp = cmdFiler.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.") f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port") f.portGrpc = cmdFiler.Flag.Int("port.grpc", 0, "filer server grpc listen port") f.publicPort = cmdFiler.Flag.Int("port.readonly", 0, "readonly port opened to public") @@ -188,6 +188,9 @@ func (fo *FilerOptions) startFiler() { if *fo.portGrpc == 0 { *fo.portGrpc = 10000 + *fo.port } + if *fo.bindIp == "" { + *fo.bindIp = *fo.ip + } defaultLevelDbDirectory := util.ResolvePath(*fo.defaultLevelDbDirectory + "/filerldb2") diff --git a/weed/command/master.go b/weed/command/master.go index 3e37f827b..20fdc8a7b 100644 --- a/weed/command/master.go +++ b/weed/command/master.go @@ -53,7 +53,7 @@ func init() { m.port = cmdMaster.Flag.Int("port", 9333, "http listen port") m.portGrpc = cmdMaster.Flag.Int("port.grpc", 0, "grpc listen port") m.ip = cmdMaster.Flag.String("ip", util.DetectedHostAddress(), "master | address, also used as identifier") - m.ipBind = cmdMaster.Flag.String("ip.bind", "", "ip address to bind to") + m.ipBind = cmdMaster.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.") m.metaFolder = cmdMaster.Flag.String("mdir", os.TempDir(), "data directory to store meta data") m.peers = cmdMaster.Flag.String("peers", "", "all master nodes in comma separated ip:port list, example: 127.0.0.1:9093,127.0.0.1:9094,127.0.0.1:9095") m.volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") @@ -124,6 +124,9 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) { if *masterOption.portGrpc == 0 { *masterOption.portGrpc = 10000 + *masterOption.port } + if *masterOption.ipBind == "" { + *masterOption.ipBind = "localhost" + } myMasterAddress, peers := checkPeers(*masterOption.ip, *masterOption.port, *masterOption.portGrpc, *masterOption.peers) diff --git a/weed/command/master_follower.go b/weed/command/master_follower.go index 6d7aa2848..2c71b34d5 100644 --- a/weed/command/master_follower.go +++ b/weed/command/master_follower.go @@ -24,7 +24,7 @@ func init() { cmdMasterFollower.Run = runMasterFollower // break init cycle mf.port = cmdMasterFollower.Flag.Int("port", 9334, "http listen port") mf.portGrpc = cmdMasterFollower.Flag.Int("port.grpc", 0, "grpc listen port") - mf.ipBind = cmdMasterFollower.Flag.String("ip.bind", "", "ip address to bind to") + mf.ipBind = cmdMasterFollower.Flag.String("ip.bind", "", "ip address to bind to. Default to localhost.") mf.peers = cmdMasterFollower.Flag.String("masters", "localhost:9333", "all master nodes in comma separated ip:port list, example: 127.0.0.1:9093,127.0.0.1:9094,127.0.0.1:9095") mf.ip = aws.String(util.DetectedHostAddress()) @@ -111,6 +111,10 @@ func startMasterFollower(masterOptions MasterOptions) { option := masterOptions.toMasterOption(nil) option.IsFollower = true + if *masterOptions.ipBind == "" { + *masterOptions.ipBind = "localhost" + } + r := mux.NewRouter() ms := weed_server.NewMasterServer(r, option, masters) listeningAddress := util.JoinHostPort(*masterOptions.ipBind, *masterOptions.port) diff --git a/weed/command/s3.go b/weed/command/s3.go index 3ce48ccb8..08e0afa4c 100644 --- a/weed/command/s3.go +++ b/weed/command/s3.go @@ -40,7 +40,7 @@ type S3Options struct { func init() { cmdS3.Run = runS3 // break init cycle s3StandaloneOptions.filer = cmdS3.Flag.String("filer", "localhost:8888", "filer server address") - s3StandaloneOptions.bindIp = cmdS3.Flag.String("ip.bind", "", "ip address to bind to") + s3StandaloneOptions.bindIp = cmdS3.Flag.String("ip.bind", "", "ip address to bind to. Default to localhost.") s3StandaloneOptions.port = cmdS3.Flag.Int("port", 8333, "s3 server http listen port") s3StandaloneOptions.domainName = cmdS3.Flag.String("domainName", "", "suffix of the host name in comma separated list, {bucket}.{domainName}") s3StandaloneOptions.config = cmdS3.Flag.String("config", "", "path to the config file") @@ -193,6 +193,10 @@ func (s3opt *S3Options) startS3Server() bool { httpS := &http.Server{Handler: router} + if *s3opt.bindIp == "" { + *s3opt.bindIp = "localhost" + } + listenAddress := fmt.Sprintf("%s:%d", *s3opt.bindIp, *s3opt.port) s3ApiListener, err := util.NewListener(listenAddress, time.Duration(10)*time.Second) if err != nil { diff --git a/weed/command/server.go b/weed/command/server.go index 45fb80b7a..ef2db9bfa 100644 --- a/weed/command/server.go +++ b/weed/command/server.go @@ -55,7 +55,7 @@ var cmdServer = &Command{ var ( serverIp = cmdServer.Flag.String("ip", util.DetectedHostAddress(), "ip or server name, also used as identifier") - serverBindIp = cmdServer.Flag.String("ip.bind", "", "ip address to bind to") + serverBindIp = cmdServer.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.") serverTimeout = cmdServer.Flag.Int("idleTimeout", 30, "connection idle seconds") serverDataCenter = cmdServer.Flag.String("dataCenter", "", "current volume server's data center name") serverRack = cmdServer.Flag.String("rack", "", "current volume server's rack name") @@ -184,6 +184,10 @@ func runServer(cmd *Command, args []string) bool { masterOptions.peers = &peers } + if *serverBindIp == "" { + serverBindIp = serverIp + } + // ip address masterOptions.ip = serverIp masterOptions.ipBind = serverBindIp diff --git a/weed/command/volume.go b/weed/command/volume.go index df67bf447..f3b36fcda 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -74,7 +74,7 @@ func init() { v.publicPort = cmdVolume.Flag.Int("port.public", 0, "port opened to public") v.ip = cmdVolume.Flag.String("ip", util.DetectedHostAddress(), "ip or server name, also used as identifier") v.publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible address") - v.bindIp = cmdVolume.Flag.String("ip.bind", "", "ip address to bind to") + v.bindIp = cmdVolume.Flag.String("ip.bind", "", "ip address to bind to. If empty, default to same as -ip option.") v.mastersString = cmdVolume.Flag.String("mserver", "localhost:9333", "comma-separated master servers") v.preStopSeconds = cmdVolume.Flag.Int("preStopSeconds", 10, "number of seconds between stop send heartbeats and stop volume server") // v.pulseSeconds = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting") @@ -193,6 +193,9 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v *v.ip = util.DetectedHostAddress() glog.V(0).Infof("detected volume server ip address: %v", *v.ip) } + if *v.bindIp == "" { + *v.bindIp = *v.ip + } if *v.publicPort == 0 { *v.publicPort = *v.port