mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
volume: best effort to detect ip address
fix https://github.com/chrislusf/seaweedfs/issues/1264
This commit is contained in:
parent
f6a7e79dc3
commit
59f40e2027
|
@ -127,7 +127,7 @@ func (v VolumeServerOptions) startVolumeServer(volumeFolders, maxVolumeCounts, v
|
|||
}
|
||||
|
||||
if *v.ip == "" {
|
||||
*v.ip = "127.0.0.1"
|
||||
*v.ip = util.DetectedHostAddress()
|
||||
}
|
||||
|
||||
if *v.publicPort == 0 {
|
||||
|
|
25
weed/util/network.go
Normal file
25
weed/util/network.go
Normal file
|
@ -0,0 +1,25 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
"github.com/chrislusf/seaweedfs/weed/glog"
|
||||
)
|
||||
|
||||
func DetectedHostAddress() string {
|
||||
addrs, err := net.InterfaceAddrs()
|
||||
if err != nil {
|
||||
glog.V(0).Infof("failed to detect ip address: %v", err)
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, a := range addrs {
|
||||
if ipnet, ok := a.(*net.IPNet); ok && !ipnet.IP.IsLoopback() {
|
||||
if ipnet.IP.To4() != nil {
|
||||
return ipnet.IP.String()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "localhost"
|
||||
}
|
Loading…
Reference in a new issue