diff --git a/weed/command/volume.go b/weed/command/volume.go index a767356e3..0e69325b6 100644 --- a/weed/command/volume.go +++ b/weed/command/volume.go @@ -43,7 +43,7 @@ func init() { cmdVolume.Run = runVolume // break init cycle v.port = cmdVolume.Flag.Int("port", 8080, "http listen port") v.publicPort = cmdVolume.Flag.Int("port.public", 0, "port opened to public") - v.ip = cmdVolume.Flag.String("ip", "localhost", "ip or server name") + v.ip = cmdVolume.Flag.String("ip", "", "ip or server name") v.publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible address") v.bindIp = cmdVolume.Flag.String("ip.bind", "0.0.0.0", "ip address to bind to") v.master = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location") diff --git a/weed/server/master_grpc_server.go b/weed/server/master_grpc_server.go index 29c95a3d4..b5cbd85b7 100644 --- a/weed/server/master_grpc_server.go +++ b/weed/server/master_grpc_server.go @@ -1,10 +1,14 @@ package weed_server import ( + "net" + "strings" + "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb" "github.com/chrislusf/seaweedfs/weed/storage" "github.com/chrislusf/seaweedfs/weed/topology" + "google.golang.org/grpc/peer" ) func (ms MasterServer) SendHeartbeat(stream pb.Seaweed_SendHeartbeatServer) error { @@ -15,6 +19,14 @@ func (ms MasterServer) SendHeartbeat(stream pb.Seaweed_SendHeartbeatServer) erro if err == nil { if dn == nil { t.Sequence.SetMax(heartbeat.MaxFileKey) + if heartbeat.Ip == "" { + if pr, ok := peer.FromContext(stream.Context()); ok { + if pr.Addr != net.Addr(nil) { + heartbeat.Ip = pr.Addr.String()[0:strings.LastIndex(pr.Addr.String(), ":")] + glog.V(0).Infof("remote IP address is detected as %v", heartbeat.Ip) + } + } + } dcName, rackName := t.Configuration.Locate(heartbeat.Ip, heartbeat.DataCenter, heartbeat.Rack) dc := t.GetOrCreateDataCenter(dcName) rack := dc.GetOrCreateRack(rackName)