aboutsummaryrefslogtreecommitdiff
path: root/weed/command
diff options
context:
space:
mode:
authorchrislu <chris.lu@gmail.com>2022-03-15 22:28:18 -0700
committerchrislu <chris.lu@gmail.com>2022-03-15 22:28:18 -0700
commit3639cad69cf58f7161aff2a639829c195d08ec30 (patch)
tree9f45239b5ef240a36f22b428cbb88438c551ab2b /weed/command
parentfbc9f0eb64346fdfcdb70e43bedec068f1447c64 (diff)
downloadseaweedfs-3639cad69cf58f7161aff2a639829c195d08ec30.tar.xz
seaweedfs-3639cad69cf58f7161aff2a639829c195d08ec30.zip
master, filer, s3: also listen to "localhost" in addition to specific ip address
related to https://github.com/chrislusf/seaweedfs/issues/1937
Diffstat (limited to 'weed/command')
-rw-r--r--weed/command/filer.go25
-rw-r--r--weed/command/iam.go11
-rw-r--r--weed/command/master.go10
-rw-r--r--weed/command/master_follower.go10
-rw-r--r--weed/command/msg_broker.go2
-rw-r--r--weed/command/s3.go16
-rw-r--r--weed/command/server.go1
7 files changed, 64 insertions, 11 deletions
diff --git a/weed/command/filer.go b/weed/command/filer.go
index d48e19873..36190335b 100644
--- a/weed/command/filer.go
+++ b/weed/command/filer.go
@@ -219,7 +219,7 @@ func (fo *FilerOptions) startFiler() {
if *fo.publicPort != 0 {
publicListeningAddress := util.JoinHostPort(*fo.bindIp, *fo.publicPort)
glog.V(0).Infoln("Start Seaweed filer server", util.Version(), "public at", publicListeningAddress)
- publicListener, e := util.NewListener(publicListeningAddress, 0)
+ publicListener, localPublicListner, e := util.NewIpAndLocalListeners(*fo.bindIp, *fo.publicPort, 0)
if e != nil {
glog.Fatalf("Filer server public listener error on port %d:%v", *fo.publicPort, e)
}
@@ -228,11 +228,18 @@ func (fo *FilerOptions) startFiler() {
glog.Fatalf("Volume server fail to serve public: %v", e)
}
}()
+ if localPublicListner != nil {
+ go func() {
+ if e := http.Serve(localPublicListner, publicVolumeMux); e != nil {
+ glog.Errorf("Volume server fail to serve public: %v", e)
+ }
+ }()
+ }
}
glog.V(0).Infof("Start Seaweed Filer %s at %s:%d", util.Version(), *fo.ip, *fo.port)
- filerListener, e := util.NewListener(
- util.JoinHostPort(*fo.bindIp, *fo.port),
+ filerListener, filerLocalListener, e := util.NewIpAndLocalListeners(
+ *fo.bindIp, *fo.port,
time.Duration(10)*time.Second,
)
if e != nil {
@@ -253,19 +260,29 @@ func (fo *FilerOptions) startFiler() {
// starting grpc server
grpcPort := *fo.portGrpc
- grpcL, err := util.NewListener(util.JoinHostPort(*fo.bindIp, grpcPort), 0)
+ grpcL, grpcLocalL, err := util.NewIpAndLocalListeners(*fo.bindIp, grpcPort, 0)
if err != nil {
glog.Fatalf("failed to listen on grpc port %d: %v", grpcPort, err)
}
grpcS := pb.NewGrpcServer(security.LoadServerTLS(util.GetViper(), "grpc.filer"))
filer_pb.RegisterSeaweedFilerServer(grpcS, fs)
reflection.Register(grpcS)
+ if grpcLocalL != nil {
+ go grpcS.Serve(grpcLocalL)
+ }
go grpcS.Serve(grpcL)
httpS := &http.Server{Handler: defaultMux}
go func() {
httpS.Serve(filerSocketListener)
}()
+ if filerLocalListener != nil {
+ go func() {
+ if err := httpS.Serve(filerLocalListener); err != nil {
+ glog.Errorf("Filer Fail to serve: %v", e)
+ }
+ }()
+ }
if err := httpS.Serve(filerListener); err != nil {
glog.Fatalf("Filer Fail to serve: %v", e)
}
diff --git a/weed/command/iam.go b/weed/command/iam.go
index 8fb14be06..88b17b1a2 100644
--- a/weed/command/iam.go
+++ b/weed/command/iam.go
@@ -22,6 +22,7 @@ var (
type IamOptions struct {
filer *string
masters *string
+ ip *string
port *int
}
@@ -29,6 +30,7 @@ func init() {
cmdIam.Run = runIam // break init cycle
iamStandaloneOptions.filer = cmdIam.Flag.String("filer", "localhost:8888", "filer server address")
iamStandaloneOptions.masters = cmdIam.Flag.String("master", "localhost:9333", "comma-separated master servers")
+ iamStandaloneOptions.ip = cmdIam.Flag.String("ip", util.DetectedHostAddress(), "iam server http listen ip address")
iamStandaloneOptions.port = cmdIam.Flag.Int("port", 8111, "iam server http listen port")
}
@@ -81,12 +83,19 @@ func (iamopt *IamOptions) startIamServer() bool {
httpS := &http.Server{Handler: router}
listenAddress := fmt.Sprintf(":%d", *iamopt.port)
- iamApiListener, err := util.NewListener(listenAddress, time.Duration(10)*time.Second)
+ iamApiListener, iamApiLocalListener, err := util.NewIpAndLocalListeners(*iamopt.ip, *iamopt.port, time.Duration(10)*time.Second)
if err != nil {
glog.Fatalf("IAM API Server listener on %s error: %v", listenAddress, err)
}
glog.V(0).Infof("Start Seaweed IAM API Server %s at http port %d", util.Version(), *iamopt.port)
+ if iamApiLocalListener != nil {
+ go func() {
+ if err = httpS.Serve(iamApiLocalListener); err != nil {
+ glog.Errorf("IAM API Server Fail to serve: %v", err)
+ }
+ }()
+ }
if err = httpS.Serve(iamApiListener); err != nil {
glog.Fatalf("IAM API Server Fail to serve: %v", err)
}
diff --git a/weed/command/master.go b/weed/command/master.go
index 20fdc8a7b..1d236d532 100644
--- a/weed/command/master.go
+++ b/weed/command/master.go
@@ -134,7 +134,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
ms := weed_server.NewMasterServer(r, masterOption.toMasterOption(masterWhiteList), peers)
listeningAddress := util.JoinHostPort(*masterOption.ipBind, *masterOption.port)
glog.V(0).Infof("Start Seaweed Master %s at %s", util.Version(), listeningAddress)
- masterListener, e := util.NewListener(listeningAddress, 0)
+ masterListener, masterLocalListner, e := util.NewIpAndLocalListeners(*masterOption.ipBind, *masterOption.port, 0)
if e != nil {
glog.Fatalf("Master startup error: %v", e)
}
@@ -157,7 +157,7 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
r.HandleFunc("/cluster/status", raftServer.StatusHandler).Methods("GET")
// starting grpc server
grpcPort := *masterOption.portGrpc
- grpcL, err := util.NewListener(util.JoinHostPort(*masterOption.ipBind, grpcPort), 0)
+ grpcL, grpcLocalL, err := util.NewIpAndLocalListeners(*masterOption.ipBind, grpcPort, 0)
if err != nil {
glog.Fatalf("master failed to listen on grpc port %d: %v", grpcPort, err)
}
@@ -166,6 +166,9 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
protobuf.RegisterRaftServer(grpcS, raftServer)
reflection.Register(grpcS)
glog.V(0).Infof("Start Seaweed Master %s grpc server at %s:%d", util.Version(), *masterOption.ipBind, grpcPort)
+ if grpcLocalL != nil {
+ go grpcS.Serve(grpcLocalL)
+ }
go grpcS.Serve(grpcL)
go func() {
@@ -181,6 +184,9 @@ func startMaster(masterOption MasterOptions, masterWhiteList []string) {
// start http server
httpS := &http.Server{Handler: r}
+ if masterLocalListner != nil {
+ go httpS.Serve(masterLocalListner)
+ }
go httpS.Serve(masterListener)
select {}
diff --git a/weed/command/master_follower.go b/weed/command/master_follower.go
index 2c71b34d5..502ce3cd3 100644
--- a/weed/command/master_follower.go
+++ b/weed/command/master_follower.go
@@ -119,14 +119,14 @@ func startMasterFollower(masterOptions MasterOptions) {
ms := weed_server.NewMasterServer(r, option, masters)
listeningAddress := util.JoinHostPort(*masterOptions.ipBind, *masterOptions.port)
glog.V(0).Infof("Start Seaweed Master %s at %s", util.Version(), listeningAddress)
- masterListener, e := util.NewListener(listeningAddress, 0)
+ masterListener, masterLocalListner, e := util.NewIpAndLocalListeners(*masterOptions.ipBind, *masterOptions.port, 0)
if e != nil {
glog.Fatalf("Master startup error: %v", e)
}
// starting grpc server
grpcPort := *masterOptions.portGrpc
- grpcL, err := util.NewListener(util.JoinHostPort(*masterOptions.ipBind, grpcPort), 0)
+ grpcL, grpcLocalL, err := util.NewIpAndLocalListeners(*masterOptions.ipBind, grpcPort, 0)
if err != nil {
glog.Fatalf("master failed to listen on grpc port %d: %v", grpcPort, err)
}
@@ -134,12 +134,18 @@ func startMasterFollower(masterOptions MasterOptions) {
master_pb.RegisterSeaweedServer(grpcS, ms)
reflection.Register(grpcS)
glog.V(0).Infof("Start Seaweed Master %s grpc server at %s:%d", util.Version(), *masterOptions.ip, grpcPort)
+ if grpcLocalL != nil {
+ go grpcS.Serve(grpcLocalL)
+ }
go grpcS.Serve(grpcL)
go ms.MasterClient.KeepConnectedToMaster()
// start http server
httpS := &http.Server{Handler: r}
+ if masterLocalListner != nil {
+ go httpS.Serve(masterLocalListner)
+ }
go httpS.Serve(masterListener)
select {}
diff --git a/weed/command/msg_broker.go b/weed/command/msg_broker.go
index 35d59ea20..3274f599b 100644
--- a/weed/command/msg_broker.go
+++ b/weed/command/msg_broker.go
@@ -95,7 +95,7 @@ func (msgBrokerOpt *MessageBrokerOptions) startQueueServer() bool {
}, grpcDialOption)
// start grpc listener
- grpcL, err := util.NewListener(util.JoinHostPort("", *msgBrokerOpt.port), 0)
+ grpcL, _, err := util.NewIpAndLocalListeners("", *msgBrokerOpt.port, 0)
if err != nil {
glog.Fatalf("failed to listen on grpc port %d: %v", *msgBrokerOpt.port, err)
}
diff --git a/weed/command/s3.go b/weed/command/s3.go
index 08e0afa4c..467da73fd 100644
--- a/weed/command/s3.go
+++ b/weed/command/s3.go
@@ -198,7 +198,7 @@ func (s3opt *S3Options) startS3Server() bool {
}
listenAddress := fmt.Sprintf("%s:%d", *s3opt.bindIp, *s3opt.port)
- s3ApiListener, err := util.NewListener(listenAddress, time.Duration(10)*time.Second)
+ s3ApiListener, s3ApiLocalListner, err := util.NewIpAndLocalListeners(*s3opt.bindIp, *s3opt.port, time.Duration(10)*time.Second)
if err != nil {
glog.Fatalf("S3 API Server listener on %s error: %v", listenAddress, err)
}
@@ -212,11 +212,25 @@ func (s3opt *S3Options) startS3Server() bool {
if *s3opt.tlsPrivateKey != "" {
glog.V(0).Infof("Start Seaweed S3 API Server %s at https port %d", util.Version(), *s3opt.port)
+ if s3ApiLocalListner != nil {
+ go func() {
+ if err = httpS.ServeTLS(s3ApiLocalListner, *s3opt.tlsCertificate, *s3opt.tlsPrivateKey); err != nil {
+ glog.Fatalf("S3 API Server Fail to serve: %v", err)
+ }
+ }()
+ }
if err = httpS.ServeTLS(s3ApiListener, *s3opt.tlsCertificate, *s3opt.tlsPrivateKey); err != nil {
glog.Fatalf("S3 API Server Fail to serve: %v", err)
}
} else {
glog.V(0).Infof("Start Seaweed S3 API Server %s at http port %d", util.Version(), *s3opt.port)
+ if s3ApiLocalListner != nil {
+ go func() {
+ if err = httpS.Serve(s3ApiLocalListner); err != nil {
+ glog.Fatalf("S3 API Server Fail to serve: %v", err)
+ }
+ }()
+ }
if err = httpS.Serve(s3ApiListener); err != nil {
glog.Fatalf("S3 API Server Fail to serve: %v", err)
}
diff --git a/weed/command/server.go b/weed/command/server.go
index ef2db9bfa..a1b495c5f 100644
--- a/weed/command/server.go
+++ b/weed/command/server.go
@@ -195,6 +195,7 @@ func runServer(cmd *Command, args []string) bool {
filerOptions.ip = serverIp
filerOptions.bindIp = serverBindIp
s3Options.bindIp = serverBindIp
+ iamOptions.ip = serverBindIp
iamOptions.masters = masterOptions.peers
serverOptions.v.ip = serverIp
serverOptions.v.bindIp = serverBindIp