mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add option to set server's ip address
This commit is contained in:
parent
019173b1cc
commit
7ee12f14a8
|
@ -32,7 +32,7 @@ var (
|
||||||
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
capacity = cmdMaster.Flag.Int("capacity", 100, "maximum number of volumes to hold")
|
||||||
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes")
|
volumeSizeLimitMB = cmdMaster.Flag.Uint("volumeSizeLimitMB", 32*1024, "Default Volume Size in MegaBytes")
|
||||||
mpulse = cmdMaster.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
mpulse = cmdMaster.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||||
confFile = cmdMaster.Flag.String("conf", "/etc/weed.conf", "xml configuration file")
|
confFile = cmdMaster.Flag.String("conf", "/etc/weedfs/weedfs.conf", "xml configuration file")
|
||||||
defaultRepType = cmdMaster.Flag.String("defaultReplicationType", "00", "Default replication type if not specified.")
|
defaultRepType = cmdMaster.Flag.String("defaultReplicationType", "00", "Default replication type if not specified.")
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -51,7 +51,7 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if machines != nil {
|
if machines != nil {
|
||||||
ret := []map[string]string{}
|
ret := []map[string]string{}
|
||||||
for _, dn := range *machines {
|
for _, dn := range *machines {
|
||||||
ret = append(ret, map[string]string{"url": dn.Ip + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl})
|
ret = append(ret, map[string]string{"url": dn.Url(), "publicUrl":dn.PublicUrl})
|
||||||
}
|
}
|
||||||
writeJson(w, r, map[string]interface{}{"locations": ret})
|
writeJson(w, r, map[string]interface{}{"locations": ret})
|
||||||
} else {
|
} else {
|
||||||
|
@ -83,14 +83,17 @@ func dirAssignHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
fid, count, dn, err := topo.PickForWrite(rt, c)
|
fid, count, dn, err := topo.PickForWrite(rt, c)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
writeJson(w, r, map[string]interface{}{"fid": fid, "url": dn.Ip + ":" + strconv.Itoa(dn.Port), "publicUrl": dn.PublicUrl, "count": count})
|
writeJson(w, r, map[string]interface{}{"fid": fid, "url": dn.Url(), "count": count})
|
||||||
} else {
|
} else {
|
||||||
writeJson(w, r, map[string]string{"error": err.Error()})
|
writeJson(w, r, map[string]string{"error": err.Error()})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
func dirJoinHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
ip := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
|
ip := r.FormValue("ip")
|
||||||
|
if ip == ""{
|
||||||
|
ip = r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")]
|
||||||
|
}
|
||||||
port, _ := strconv.Atoi(r.FormValue("port"))
|
port, _ := strconv.Atoi(r.FormValue("port"))
|
||||||
maxVolumeCount, _ := strconv.Atoi(r.FormValue("maxVolumeCount"))
|
maxVolumeCount, _ := strconv.Atoi(r.FormValue("maxVolumeCount"))
|
||||||
s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port")
|
s := r.RemoteAddr[0:strings.Index(r.RemoteAddr, ":")+1] + r.FormValue("port")
|
||||||
|
|
|
@ -20,7 +20,7 @@ func init() {
|
||||||
}
|
}
|
||||||
|
|
||||||
var cmdVolume = &Command{
|
var cmdVolume = &Command{
|
||||||
UsageLine: "volume -port=8080 -dir=/tmp -max=5 -publicUrl=server_name:8080 -mserver=localhost:9333",
|
UsageLine: "volume -port=8080 -dir=/tmp -max=5 -ip=server_name -mserver=localhost:9333",
|
||||||
Short: "start a volume server",
|
Short: "start a volume server",
|
||||||
Long: `start a volume server to provide storage spaces
|
Long: `start a volume server to provide storage spaces
|
||||||
|
|
||||||
|
@ -30,7 +30,8 @@ var cmdVolume = &Command{
|
||||||
var (
|
var (
|
||||||
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
vport = cmdVolume.Flag.Int("port", 8080, "http listen port")
|
||||||
volumeFolder = cmdVolume.Flag.String("dir", "/tmp", "directory to store data files")
|
volumeFolder = cmdVolume.Flag.String("dir", "/tmp", "directory to store data files")
|
||||||
publicUrl = cmdVolume.Flag.String("publicUrl", "localhost:8080", "public url to serve data read")
|
ip = cmdVolume.Flag.String("ip", "", "ip or server name")
|
||||||
|
publicUrl = cmdVolume.Flag.String("publicUrl", "", "Publicly accessible <ip|server_name>:<port>")
|
||||||
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")
|
vpulse = cmdVolume.Flag.Int("pulseSeconds", 5, "number of seconds between heartbeats")
|
||||||
maxVolumeCount = cmdVolume.Flag.Int("max", 5, "maximum number of volumes")
|
maxVolumeCount = cmdVolume.Flag.Int("max", 5, "maximum number of volumes")
|
||||||
|
@ -137,11 +138,11 @@ func PostHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
if lookupResult, lookupErr := operation.Lookup(*server, volumeId); lookupErr == nil {
|
if lookupResult, lookupErr := operation.Lookup(*server, volumeId); lookupErr == nil {
|
||||||
sendFunc := func(background bool) {
|
sendFunc := func(background bool) {
|
||||||
postContentFunc := func(location operation.Location) bool {
|
postContentFunc := func(location operation.Location) bool {
|
||||||
operation.Upload("http://"+location.PublicUrl+r.URL.Path+"?type=standard", filename, bytes.NewReader(needle.Data))
|
operation.Upload("http://"+location.Url+r.URL.Path+"?type=standard", filename, bytes.NewReader(needle.Data))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
for _, location := range lookupResult.Locations {
|
for _, location := range lookupResult.Locations {
|
||||||
if location.PublicUrl != *publicUrl {
|
if location.Url != (*ip+":"+strconv.Itoa(*vport)) {
|
||||||
if background {
|
if background {
|
||||||
go postContentFunc(location)
|
go postContentFunc(location)
|
||||||
} else {
|
} else {
|
||||||
|
@ -228,7 +229,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
perm := fileInfo.Mode().Perm()
|
perm := fileInfo.Mode().Perm()
|
||||||
log.Println("Volume Folder permission:", perm)
|
log.Println("Volume Folder permission:", perm)
|
||||||
|
|
||||||
store = storage.NewStore(*vport, *publicUrl, *volumeFolder, *maxVolumeCount)
|
store = storage.NewStore(*vport, *ip, *publicUrl, *volumeFolder, *maxVolumeCount)
|
||||||
defer store.Close()
|
defer store.Close()
|
||||||
http.HandleFunc("/", storeHandler)
|
http.HandleFunc("/", storeHandler)
|
||||||
http.HandleFunc("/status", statusHandler)
|
http.HandleFunc("/status", statusHandler)
|
||||||
|
@ -242,7 +243,7 @@ func runVolume(cmd *Command, args []string) bool {
|
||||||
}()
|
}()
|
||||||
log.Println("store joined at", *masterNode)
|
log.Println("store joined at", *masterNode)
|
||||||
|
|
||||||
log.Println("Start storage service at http://127.0.0.1:"+strconv.Itoa(*vport), "public url", *publicUrl)
|
log.Println("Start storage service at http://"+*ip+":"+strconv.Itoa(*vport))
|
||||||
e := http.ListenAndServe(":"+strconv.Itoa(*vport), nil)
|
e := http.ListenAndServe(":"+strconv.Itoa(*vport), nil)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
log.Fatalf("Fail to start:%s", e.Error())
|
log.Fatalf("Fail to start:%s", e.Error())
|
||||||
|
|
|
@ -7,7 +7,6 @@ import (
|
||||||
"pkg/storage"
|
"pkg/storage"
|
||||||
"pkg/topology"
|
"pkg/topology"
|
||||||
"pkg/util"
|
"pkg/util"
|
||||||
"strconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AllocateVolumeResult struct {
|
type AllocateVolumeResult struct {
|
||||||
|
@ -18,7 +17,7 @@ func AllocateVolume(dn *topology.DataNode, vid storage.VolumeId, repType storage
|
||||||
values := make(url.Values)
|
values := make(url.Values)
|
||||||
values.Add("volume", vid.String())
|
values.Add("volume", vid.String())
|
||||||
values.Add("replicationType", repType.String())
|
values.Add("replicationType", repType.String())
|
||||||
jsonBlob, err := util.Post("http://"+dn.Ip+":"+strconv.Itoa(dn.Port)+"/admin/assign_volume", values)
|
jsonBlob, err := util.Post("http://"+dn.Url()+"/admin/assign_volume", values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
type Location struct {
|
type Location struct {
|
||||||
Url string "url"
|
Url string "url"
|
||||||
PublicUrl string "publicUrl"
|
PublicUrl string "publicUrl"
|
||||||
}
|
}
|
||||||
type LookupResult struct {
|
type LookupResult struct {
|
||||||
Locations []Location "locations"
|
Locations []Location "locations"
|
||||||
|
|
|
@ -15,23 +15,24 @@ type Store struct {
|
||||||
volumes map[VolumeId]*Volume
|
volumes map[VolumeId]*Volume
|
||||||
dir string
|
dir string
|
||||||
Port int
|
Port int
|
||||||
|
Ip string
|
||||||
PublicUrl string
|
PublicUrl string
|
||||||
MaxVolumeCount int
|
MaxVolumeCount int
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStore(port int, publicUrl, dirname string, maxVolumeCount int) (s *Store) {
|
func NewStore(port int, ip, publicUrl, dirname string, maxVolumeCount int) (s *Store) {
|
||||||
s = &Store{Port: port, PublicUrl: publicUrl, dir: dirname, MaxVolumeCount: maxVolumeCount}
|
s = &Store{Port: port, Ip: ip, PublicUrl: publicUrl, dir: dirname, MaxVolumeCount: maxVolumeCount}
|
||||||
s.volumes = make(map[VolumeId]*Volume)
|
s.volumes = make(map[VolumeId]*Volume)
|
||||||
s.loadExistingVolumes()
|
s.loadExistingVolumes()
|
||||||
|
|
||||||
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
|
log.Println("Store started on dir:", dirname, "with", len(s.volumes), "volumes")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
func (s *Store) AddVolume(volumeListString string, replicationType string) (error) {
|
func (s *Store) AddVolume(volumeListString string, replicationType string) error {
|
||||||
rt, e := NewReplicationType(replicationType)
|
rt, e := NewReplicationType(replicationType)
|
||||||
if e!=nil {
|
if e != nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
for _, range_string := range strings.Split(volumeListString, ",") {
|
for _, range_string := range strings.Split(volumeListString, ",") {
|
||||||
if strings.Index(range_string, "-") < 0 {
|
if strings.Index(range_string, "-") < 0 {
|
||||||
id_string := range_string
|
id_string := range_string
|
||||||
|
@ -103,6 +104,7 @@ func (s *Store) Join(mserver string) error {
|
||||||
bytes, _ := json.Marshal(stats)
|
bytes, _ := json.Marshal(stats)
|
||||||
values := make(url.Values)
|
values := make(url.Values)
|
||||||
values.Add("port", strconv.Itoa(s.Port))
|
values.Add("port", strconv.Itoa(s.Port))
|
||||||
|
values.Add("ip", s.Ip)
|
||||||
values.Add("publicUrl", s.PublicUrl)
|
values.Add("publicUrl", s.PublicUrl)
|
||||||
values.Add("volumes", string(bytes))
|
values.Add("volumes", string(bytes))
|
||||||
values.Add("maxVolumeCount", strconv.Itoa(s.MaxVolumeCount))
|
values.Add("maxVolumeCount", strconv.Itoa(s.MaxVolumeCount))
|
||||||
|
@ -133,10 +135,10 @@ func (s *Store) Read(i VolumeId, n *Needle) (int, error) {
|
||||||
return 0, errors.New("Not Found")
|
return 0, errors.New("Not Found")
|
||||||
}
|
}
|
||||||
func (s *Store) GetVolume(i VolumeId) *Volume {
|
func (s *Store) GetVolume(i VolumeId) *Volume {
|
||||||
return s.volumes[i]
|
return s.volumes[i]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Store) HasVolume(i VolumeId) bool {
|
func (s *Store) HasVolume(i VolumeId) bool {
|
||||||
_, ok := s.volumes[i]
|
_, ok := s.volumes[i]
|
||||||
return ok
|
return ok
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package topology
|
||||||
import (
|
import (
|
||||||
_ "fmt"
|
_ "fmt"
|
||||||
"pkg/storage"
|
"pkg/storage"
|
||||||
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DataNode struct {
|
type DataNode struct {
|
||||||
|
@ -43,11 +44,13 @@ func (dn *DataNode) GetTopology() *Topology {
|
||||||
func (dn *DataNode) MatchLocation(ip string, port int) bool {
|
func (dn *DataNode) MatchLocation(ip string, port int) bool {
|
||||||
return dn.Ip == ip && dn.Port == port
|
return dn.Ip == ip && dn.Port == port
|
||||||
}
|
}
|
||||||
|
func (dn *DataNode) Url() string {
|
||||||
|
return dn.Ip + strconv.Itoa(dn.Port)
|
||||||
|
}
|
||||||
|
|
||||||
func (dn *DataNode) ToMap() interface{} {
|
func (dn *DataNode) ToMap() interface{} {
|
||||||
ret := make(map[string]interface{})
|
ret := make(map[string]interface{})
|
||||||
ret["Ip"] = dn.Ip
|
ret["Url"] = dn.Url()
|
||||||
ret["Port"] = dn.Port
|
|
||||||
ret["Volumes"] = dn.GetActiveVolumeCount()
|
ret["Volumes"] = dn.GetActiveVolumeCount()
|
||||||
ret["Max"] = dn.GetMaxVolumeCount()
|
ret["Max"] = dn.GetMaxVolumeCount()
|
||||||
ret["Free"] = dn.FreeSpace()
|
ret["Free"] = dn.FreeSpace()
|
||||||
|
|
|
@ -10,13 +10,13 @@ import (
|
||||||
func Post(url string, values url.Values) ([]byte, error) {
|
func Post(url string, values url.Values) ([]byte, error) {
|
||||||
r, err := http.PostForm(url, values)
|
r, err := http.PostForm(url, values)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("post:", err)
|
log.Println("post to", url, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
defer r.Body.Close()
|
defer r.Body.Close()
|
||||||
b, err := ioutil.ReadAll(r.Body)
|
b, err := ioutil.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Println("post:", err)
|
log.Println("read post result from", url, err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return b, nil
|
return b, nil
|
||||||
|
|
Loading…
Reference in a new issue