Browse Source

Adjust command line options.

1. switch to use -publicIp instead of -publicUrl
2. -ip can be empty. It will listen to all available interfaces.
3. For "weed master", these options are changed:
  -masterPort => -master.port
  -peers => -master.peers
  -mdir => -master.dir
  -volumeSizeLimitMB => -master.volumeSizeLimitMB
  -conf => -master.conf
  -defaultReplicaPlacement => -master.defaultReplicaPlacement
  -port => -volume.port
  -max => -volume.max
pull/2/head
Chris Lu 11 years ago
parent
commit
d344e87de0
  1. 23
      go/weed/master.go
  2. 52
      go/weed/server.go
  3. 24
      go/weed/volume.go
  4. 4
      go/weed/weed_server/volume_server.go

23
go/weed/master.go

@ -28,7 +28,8 @@ var cmdMaster = &Command{
var ( var (
mport = cmdMaster.Flag.Int("port", 9333, "http listen port") mport = cmdMaster.Flag.Int("port", 9333, "http listen port")
masterIp = cmdMaster.Flag.String("ip", "localhost", "master ip address")
masterIp = cmdMaster.Flag.String("ip", "", "master listening ip address, default to listen on all network interfaces")
mPublicIp = cmdMaster.Flag.String("publicIp", "", "peer accessible <ip>|<server_name>")
metaFolder = cmdMaster.Flag.String("mdir", os.TempDir(), "data directory to store meta data") metaFolder = cmdMaster.Flag.String("mdir", os.TempDir(), "data directory to store meta data")
masterPeers = cmdMaster.Flag.String("peers", "", "other master nodes in comma separated ip:port list") masterPeers = cmdMaster.Flag.String("peers", "", "other master nodes in comma separated ip:port list")
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.") volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.")
@ -60,24 +61,30 @@ func runMaster(cmd *Command, args []string) bool {
*volumeSizeLimitMB, *mpulse, *confFile, *defaultReplicaPlacement, *garbageThreshold, masterWhiteList, *volumeSizeLimitMB, *mpulse, *confFile, *defaultReplicaPlacement, *garbageThreshold, masterWhiteList,
) )
glog.V(0).Infoln("Start Weed Master", util.VERSION, "at port", *masterIp+":"+strconv.Itoa(*mport))
listeningAddress := *masterIp + ":" + strconv.Itoa(*mport)
listener, e := util.NewListener(
*masterIp+":"+strconv.Itoa(*mport),
time.Duration(*mTimeout)*time.Second,
)
glog.V(0).Infoln("Start Weed Master", util.VERSION, "at", listeningAddress)
listener, e := util.NewListener(listeningAddress, time.Duration(*mTimeout)*time.Second)
if e != nil { if e != nil {
glog.Fatalf(e.Error()) glog.Fatalf(e.Error())
} }
go func() { go func() {
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
myAddress := *masterIp + ":" + strconv.Itoa(*mport)
if *mPublicIp == "" {
if *masterIp == "" {
*mPublicIp = "localhost"
} else {
*mPublicIp = *masterIp
}
}
myPublicMasterAddress := *mPublicIp + ":" + strconv.Itoa(*mport)
var peers []string var peers []string
if *masterPeers != "" { if *masterPeers != "" {
peers = strings.Split(*masterPeers, ",") peers = strings.Split(*masterPeers, ",")
} }
raftServer := weed_server.NewRaftServer(r, peers, myAddress, *metaFolder, ms.Topo, *mpulse)
raftServer := weed_server.NewRaftServer(r, peers, myPublicMasterAddress, *metaFolder, ms.Topo, *mpulse)
ms.SetRaftServer(raftServer) ms.SetRaftServer(raftServer)
}() }()

52
go/weed/server.go

@ -29,29 +29,33 @@ var cmdServer = &Command{
and a master server to provide volume=>location mapping service and sequence number of file ids and a master server to provide volume=>location mapping service and sequence number of file ids
This is provided as a convenient way to start both volume server and master server. This is provided as a convenient way to start both volume server and master server.
The servers are the same as starting them separately.
The servers are exactly the same as starting them separately.
So other volume servers can use this embedded master server also. So other volume servers can use this embedded master server also.
Optionally, one filer server can be started. Logically, filer servers should not be in a cluster.
They run with meta data on disk, not shared. So each filer server is different.
`, `,
} }
var ( var (
serverIp = cmdServer.Flag.String("ip", "localhost", "ip or server name")
serverIp = cmdServer.Flag.String("ip", "", "ip or server name")
serverPublicIp = cmdServer.Flag.String("publicIp", "", "ip or server name")
serverMaxCpu = cmdServer.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs") serverMaxCpu = cmdServer.Flag.Int("maxCpu", 0, "maximum number of CPUs. 0 means all available CPUs")
serverTimeout = cmdServer.Flag.Int("idleTimeout", 10, "connection idle seconds") serverTimeout = cmdServer.Flag.Int("idleTimeout", 10, "connection idle seconds")
serverDataCenter = cmdServer.Flag.String("dataCenter", "", "current volume server's data center name") serverDataCenter = cmdServer.Flag.String("dataCenter", "", "current volume server's data center name")
serverRack = cmdServer.Flag.String("rack", "", "current volume server's rack name") serverRack = cmdServer.Flag.String("rack", "", "current volume server's rack name")
serverWhiteListOption = cmdServer.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.") serverWhiteListOption = cmdServer.Flag.String("whiteList", "", "comma separated Ip addresses having write permission. No limit if empty.")
serverPeers = cmdServer.Flag.String("peers", "", "other master nodes in comma separated ip:masterPort list")
masterPort = cmdServer.Flag.Int("masterPort", 9333, "master server http listen port")
masterMetaFolder = cmdServer.Flag.String("mdir", "", "data directory to store meta data, default to same as -dir specified")
masterVolumeSizeLimitMB = cmdServer.Flag.Uint("volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.")
masterConfFile = cmdServer.Flag.String("conf", "/etc/weedfs/weedfs.conf", "xml configuration file")
masterDefaultReplicaPlacement = cmdServer.Flag.String("defaultReplicaPlacement", "000", "Default replication type if not specified.")
volumePort = cmdServer.Flag.Int("port", 8080, "volume server http listen port")
volumePublicUrl = cmdServer.Flag.String("publicUrl", "", "Publicly accessible <ip|server_name>:<port>")
serverPeers = cmdServer.Flag.String("master.peers", "", "other master nodes in comma separated ip:masterPort list")
masterPort = cmdServer.Flag.Int("master.port", 9333, "master server http listen port")
masterMetaFolder = cmdServer.Flag.String("master.dir", "", "data directory to store meta data, default to same as -dir specified")
masterVolumeSizeLimitMB = cmdServer.Flag.Uint("master.volumeSizeLimitMB", 30*1000, "Master stops directing writes to oversized volumes.")
masterConfFile = cmdServer.Flag.String("master.conf", "/etc/weedfs/weedfs.conf", "xml configuration file")
masterDefaultReplicaPlacement = cmdServer.Flag.String("master.defaultReplicaPlacement", "000", "Default replication type if not specified.")
volumePort = cmdServer.Flag.Int("volume.port", 8080, "volume server http listen port")
volumeDataFolders = cmdServer.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") volumeDataFolders = cmdServer.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...")
volumeMaxDataVolumeCounts = cmdServer.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...")
volumeMaxDataVolumeCounts = cmdServer.Flag.String("volume.max", "7", "maximum numbers of volumes, count[,count]...")
volumePulse = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats") volumePulse = cmdServer.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer") isStartingFiler = cmdServer.Flag.Bool("filer", false, "whether to start filer")
@ -68,7 +72,15 @@ func init() {
func runServer(cmd *Command, args []string) bool { func runServer(cmd *Command, args []string) bool {
*filer.master = *serverIp + ":" + strconv.Itoa(*masterPort)
if *serverPublicIp == "" {
if *serverIp == "" {
*serverPublicIp = "localhost"
} else {
*serverPublicIp = *serverIp
}
}
*filer.master = *serverPublicIp + ":" + strconv.Itoa(*masterPort)
if *filer.defaultReplicaPlacement == "" { if *filer.defaultReplicaPlacement == "" {
*filer.defaultReplicaPlacement = *masterDefaultReplicaPlacement *filer.defaultReplicaPlacement = *masterDefaultReplicaPlacement
@ -112,9 +124,6 @@ func runServer(cmd *Command, args []string) bool {
glog.Fatalf("Check Mapping Meta Folder (-filer.dir=\"%s\") Writable: %s", *filer.dir, err) glog.Fatalf("Check Mapping Meta Folder (-filer.dir=\"%s\") Writable: %s", *filer.dir, err)
} }
if *volumePublicUrl == "" {
*volumePublicUrl = *serverIp + ":" + strconv.Itoa(*volumePort)
}
if *serverWhiteListOption != "" { if *serverWhiteListOption != "" {
serverWhiteList = strings.Split(*serverWhiteListOption, ",") serverWhiteList = strings.Split(*serverWhiteListOption, ",")
} }
@ -152,11 +161,8 @@ func runServer(cmd *Command, args []string) bool {
*masterVolumeSizeLimitMB, *volumePulse, *masterConfFile, *masterDefaultReplicaPlacement, *garbageThreshold, serverWhiteList, *masterVolumeSizeLimitMB, *volumePulse, *masterConfFile, *masterDefaultReplicaPlacement, *garbageThreshold, serverWhiteList,
) )
glog.V(0).Infoln("Start Weed Master", util.VERSION, "at port", *serverIp+":"+strconv.Itoa(*masterPort))
masterListener, e := util.NewListener(
*serverIp+":"+strconv.Itoa(*masterPort),
time.Duration(*serverTimeout)*time.Second,
)
glog.V(0).Infoln("Start Weed Master", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*masterPort))
masterListener, e := util.NewListener(*serverIp+":"+strconv.Itoa(*masterPort), time.Duration(*serverTimeout)*time.Second)
if e != nil { if e != nil {
glog.Fatalf(e.Error()) glog.Fatalf(e.Error())
} }
@ -164,7 +170,7 @@ func runServer(cmd *Command, args []string) bool {
go func() { go func() {
raftWaitForMaster.Wait() raftWaitForMaster.Wait()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
myAddress := *serverIp + ":" + strconv.Itoa(*masterPort)
myAddress := *serverPublicIp + ":" + strconv.Itoa(*masterPort)
var peers []string var peers []string
if *serverPeers != "" { if *serverPeers != "" {
peers = strings.Split(*serverPeers, ",") peers = strings.Split(*serverPeers, ",")
@ -183,11 +189,11 @@ func runServer(cmd *Command, args []string) bool {
volumeWait.Wait() volumeWait.Wait()
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
r := http.NewServeMux() r := http.NewServeMux()
weed_server.NewVolumeServer(r, *serverIp, *volumePort, *volumePublicUrl, folders, maxCounts,
weed_server.NewVolumeServer(r, *serverIp, *volumePort, *serverPublicIp, folders, maxCounts,
*serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack, serverWhiteList, *serverIp+":"+strconv.Itoa(*masterPort), *volumePulse, *serverDataCenter, *serverRack, serverWhiteList,
) )
glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at http://"+*serverIp+":"+strconv.Itoa(*volumePort))
glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at", *serverIp+":"+strconv.Itoa(*volumePort))
volumeListener, e := util.NewListener( volumeListener, e := util.NewListener(
*serverIp+":"+strconv.Itoa(*volumePort), *serverIp+":"+strconv.Itoa(*volumePort),
time.Duration(*serverTimeout)*time.Second, time.Duration(*serverTimeout)*time.Second,

24
go/weed/volume.go

@ -28,8 +28,8 @@ var (
vport = cmdVolume.Flag.Int("port", 8080, "http listen port") vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...") volumeFolders = cmdVolume.Flag.String("dir", os.TempDir(), "directories to store data files. dir[,dir]...")
maxVolumeCounts = cmdVolume.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...") maxVolumeCounts = cmdVolume.Flag.String("max", "7", "maximum numbers of volumes, count[,count]...")
ip = cmdVolume.Flag.String("ip", "localhost", "ip or server name")
publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible <ip|server_name>:<port>")
ip = cmdVolume.Flag.String("ip", "", "ip or server name")
publicIp = cmdVolume.Flag.String("publicIp", "", "Publicly accessible <ip|server_name>")
masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location") masterNode = cmdVolume.Flag.String("mserver", "localhost:9333", "master server location")
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting") vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats, must be smaller than or equal to the master's setting")
vTimeout = cmdVolume.Flag.Int("idleTimeout", 10, "connection idle seconds") vTimeout = cmdVolume.Flag.Int("idleTimeout", 10, "connection idle seconds")
@ -65,8 +65,12 @@ func runVolume(cmd *Command, args []string) bool {
} }
} }
if *publicUrl == "" {
*publicUrl = *ip + ":" + strconv.Itoa(*vport)
if *publicIp == "" {
if *ip == "" {
*publicIp = "localhost"
} else {
*publicIp = *ip
}
} }
if *volumeWhiteListOption != "" { if *volumeWhiteListOption != "" {
volumeWhiteList = strings.Split(*volumeWhiteListOption, ",") volumeWhiteList = strings.Split(*volumeWhiteListOption, ",")
@ -74,15 +78,15 @@ func runVolume(cmd *Command, args []string) bool {
r := http.NewServeMux() r := http.NewServeMux()
weed_server.NewVolumeServer(r, *ip, *vport, *publicUrl, folders, maxCounts,
weed_server.NewVolumeServer(r, *ip, *vport, *publicIp, folders, maxCounts,
*masterNode, *vpulse, *dataCenter, *rack, volumeWhiteList, *masterNode, *vpulse, *dataCenter, *rack, volumeWhiteList,
) )
glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at http://"+*ip+":"+strconv.Itoa(*vport))
listener, e := util.NewListener(
*ip+":"+strconv.Itoa(*vport),
time.Duration(*vTimeout)*time.Second,
)
listeningAddress := *ip + ":" + strconv.Itoa(*vport)
glog.V(0).Infoln("Start Weed volume server", util.VERSION, "at", listeningAddress)
listener, e := util.NewListener(listeningAddress, time.Duration(*vTimeout)*time.Second)
if e != nil { if e != nil {
glog.Fatalf(e.Error()) glog.Fatalf(e.Error())
} }

4
go/weed/weed_server/volume_server.go

@ -5,6 +5,7 @@ import (
"code.google.com/p/weed-fs/go/storage" "code.google.com/p/weed-fs/go/storage"
"math/rand" "math/rand"
"net/http" "net/http"
"strconv"
"time" "time"
) )
@ -17,10 +18,11 @@ type VolumeServer struct {
store *storage.Store store *storage.Store
} }
func NewVolumeServer(r *http.ServeMux, ip string, port int, publicUrl string, folders []string, maxCounts []int,
func NewVolumeServer(r *http.ServeMux, ip string, port int, publicIp string, folders []string, maxCounts []int,
masterNode string, pulseSeconds int, masterNode string, pulseSeconds int,
dataCenter string, rack string, dataCenter string, rack string,
whiteList []string) *VolumeServer { whiteList []string) *VolumeServer {
publicUrl := publicIp + ":" + strconv.Itoa(port)
vs := &VolumeServer{ vs := &VolumeServer{
masterNode: masterNode, masterNode: masterNode,
pulseSeconds: pulseSeconds, pulseSeconds: pulseSeconds,

Loading…
Cancel
Save