mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-11-24 11:09:12 +08:00
filer add readonly public port
This commit is contained in:
parent
7ecc0f4b11
commit
478fe0ecf2
@ -19,6 +19,7 @@ type FilerOptions struct {
|
|||||||
master *string
|
master *string
|
||||||
ip *string
|
ip *string
|
||||||
port *int
|
port *int
|
||||||
|
publicPort *int
|
||||||
collection *string
|
collection *string
|
||||||
defaultReplicaPlacement *string
|
defaultReplicaPlacement *string
|
||||||
dir *string
|
dir *string
|
||||||
@ -40,6 +41,7 @@ func init() {
|
|||||||
f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this collection")
|
f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this collection")
|
||||||
f.ip = cmdFiler.Flag.String("ip", "", "filer server http listen ip address")
|
f.ip = cmdFiler.Flag.String("ip", "", "filer server http listen ip address")
|
||||||
f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port")
|
f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port")
|
||||||
|
f.publicPort = cmdFiler.Flag.Int("port.public", 0, "port opened to public")
|
||||||
f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
|
f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
|
||||||
f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified")
|
f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified")
|
||||||
f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
|
f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
|
||||||
@ -83,21 +85,50 @@ func runFiler(cmd *Command, args []string) bool {
|
|||||||
glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)
|
glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
f.start()
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fo *FilerOptions) start() {
|
||||||
|
|
||||||
defaultMux := http.NewServeMux()
|
defaultMux := http.NewServeMux()
|
||||||
_, nfs_err := weed_server.NewFilerServer(defaultMux, *f.ip, *f.port, *f.master, *f.dir, *f.collection,
|
publicVolumeMux := defaultMux
|
||||||
*f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing,
|
|
||||||
*f.confFile,
|
if *fo.publicPort != 0 {
|
||||||
*f.maxMB,
|
publicVolumeMux = http.NewServeMux()
|
||||||
*f.secretKey,
|
}
|
||||||
*f.cassandra_server, *f.cassandra_keyspace,
|
|
||||||
*f.redis_server, *f.redis_password, *f.redis_database,
|
_, nfs_err := weed_server.NewFilerServer(defaultMux, publicVolumeMux,
|
||||||
|
*fo.ip, *fo.port, *fo.master, *fo.dir, *fo.collection,
|
||||||
|
*fo.defaultReplicaPlacement, *fo.redirectOnRead, *fo.disableDirListing,
|
||||||
|
*fo.confFile,
|
||||||
|
*fo.maxMB,
|
||||||
|
*fo.secretKey,
|
||||||
|
*fo.cassandra_server, *fo.cassandra_keyspace,
|
||||||
|
*fo.redis_server, *fo.redis_password, *fo.redis_database,
|
||||||
)
|
)
|
||||||
if nfs_err != nil {
|
if nfs_err != nil {
|
||||||
glog.Fatalf("Filer startup error: %v", nfs_err)
|
glog.Fatalf("Filer startup error: %v", nfs_err)
|
||||||
}
|
}
|
||||||
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
|
|
||||||
|
if *fo.publicPort != 0 {
|
||||||
|
publicListeningAddress := *fo.ip + ":" + strconv.Itoa(*fo.publicPort)
|
||||||
|
glog.V(0).Infoln("Start Seaweed filer server", util.VERSION, "public at", publicListeningAddress)
|
||||||
|
publicListener, e := util.NewListener(publicListeningAddress, 0)
|
||||||
|
if e != nil {
|
||||||
|
glog.Fatalf("Filer server public listener error on port %d:%v", *fo.publicPort, e)
|
||||||
|
}
|
||||||
|
go func() {
|
||||||
|
if e := http.Serve(publicListener, publicVolumeMux); e != nil {
|
||||||
|
glog.Fatalf("Volume server fail to serve public: %v", e)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
|
||||||
|
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*fo.port))
|
||||||
filerListener, e := util.NewListener(
|
filerListener, e := util.NewListener(
|
||||||
":"+strconv.Itoa(*f.port),
|
":"+strconv.Itoa(*fo.port),
|
||||||
time.Duration(10)*time.Second,
|
time.Duration(10)*time.Second,
|
||||||
)
|
)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
@ -107,5 +138,4 @@ func runFiler(cmd *Command, args []string) bool {
|
|||||||
glog.Fatalf("Filer Fail to serve: %v", e)
|
glog.Fatalf("Filer Fail to serve: %v", e)
|
||||||
}
|
}
|
||||||
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ func init() {
|
|||||||
filerOptions.master = cmdServer.Flag.String("filer.master", "", "default to current master server")
|
filerOptions.master = cmdServer.Flag.String("filer.master", "", "default to current master server")
|
||||||
filerOptions.collection = cmdServer.Flag.String("filer.collection", "", "all data will be stored in this collection")
|
filerOptions.collection = cmdServer.Flag.String("filer.collection", "", "all data will be stored in this collection")
|
||||||
filerOptions.port = cmdServer.Flag.Int("filer.port", 8888, "filer server http listen port")
|
filerOptions.port = cmdServer.Flag.Int("filer.port", 8888, "filer server http listen port")
|
||||||
|
filerOptions.publicPort = cmdServer.Flag.Int("filer.port.public", 0, "filer server public http listen port")
|
||||||
filerOptions.dir = cmdServer.Flag.String("filer.dir", "", "directory to store meta data, default to a 'filer' sub directory of what -dir is specified")
|
filerOptions.dir = cmdServer.Flag.String("filer.dir", "", "directory to store meta data, default to a 'filer' sub directory of what -dir is specified")
|
||||||
filerOptions.defaultReplicaPlacement = cmdServer.Flag.String("filer.defaultReplicaPlacement", "", "Default replication type if not specified during runtime.")
|
filerOptions.defaultReplicaPlacement = cmdServer.Flag.String("filer.defaultReplicaPlacement", "", "Default replication type if not specified during runtime.")
|
||||||
filerOptions.redirectOnRead = cmdServer.Flag.Bool("filer.redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
|
filerOptions.redirectOnRead = cmdServer.Flag.Bool("filer.redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
|
||||||
@ -116,6 +117,7 @@ func runServer(cmd *Command, args []string) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*filerOptions.master = *serverIp + ":" + strconv.Itoa(*masterPort)
|
*filerOptions.master = *serverIp + ":" + strconv.Itoa(*masterPort)
|
||||||
|
filerOptions.ip = serverIp
|
||||||
|
|
||||||
if *filerOptions.defaultReplicaPlacement == "" {
|
if *filerOptions.defaultReplicaPlacement == "" {
|
||||||
*filerOptions.defaultReplicaPlacement = *masterDefaultReplicaPlacement
|
*filerOptions.defaultReplicaPlacement = *masterDefaultReplicaPlacement
|
||||||
@ -172,30 +174,9 @@ func runServer(cmd *Command, args []string) bool {
|
|||||||
if *isStartingFiler {
|
if *isStartingFiler {
|
||||||
go func() {
|
go func() {
|
||||||
time.Sleep(1 * time.Second)
|
time.Sleep(1 * time.Second)
|
||||||
r := http.NewServeMux()
|
|
||||||
_, nfs_err := weed_server.NewFilerServer(r, *serverBindIp, *filerOptions.port, *filerOptions.master, *filerOptions.dir, *filerOptions.collection,
|
filerOptions.start()
|
||||||
*filerOptions.defaultReplicaPlacement,
|
|
||||||
*filerOptions.redirectOnRead, *filerOptions.disableDirListing,
|
|
||||||
*filerOptions.confFile,
|
|
||||||
*filerOptions.maxMB,
|
|
||||||
*filerOptions.secretKey,
|
|
||||||
*filerOptions.cassandra_server, *filerOptions.cassandra_keyspace,
|
|
||||||
*filerOptions.redis_server, *filerOptions.redis_password, *filerOptions.redis_database,
|
|
||||||
)
|
|
||||||
if nfs_err != nil {
|
|
||||||
glog.Fatalf("Filer startup error: %v", nfs_err)
|
|
||||||
}
|
|
||||||
glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*filerOptions.port))
|
|
||||||
filerListener, e := util.NewListener(
|
|
||||||
":"+strconv.Itoa(*filerOptions.port),
|
|
||||||
time.Duration(10)*time.Second,
|
|
||||||
)
|
|
||||||
if e != nil {
|
|
||||||
glog.Fatalf("Filer listener error: %v", e)
|
|
||||||
}
|
|
||||||
if e := http.Serve(filerListener, r); e != nil {
|
|
||||||
glog.Fatalf("Filer Fail to serve: %v", e)
|
|
||||||
}
|
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,7 +57,7 @@ type FilerServer struct {
|
|||||||
masterNodes *storage.MasterNodes
|
masterNodes *storage.MasterNodes
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewFilerServer(defaultMux *http.ServeMux, ip string, port int, master string, dir string, collection string,
|
func NewFilerServer(defaultMux, readonlyMux *http.ServeMux, ip string, port int, master string, dir string, collection string,
|
||||||
replication string, redirectOnRead bool, disableDirListing bool,
|
replication string, redirectOnRead bool, disableDirListing bool,
|
||||||
confFile string,
|
confFile string,
|
||||||
maxMB int,
|
maxMB int,
|
||||||
@ -111,6 +111,9 @@ func NewFilerServer(defaultMux *http.ServeMux, ip string, port int, master strin
|
|||||||
}
|
}
|
||||||
|
|
||||||
defaultMux.HandleFunc("/", fs.filerHandler)
|
defaultMux.HandleFunc("/", fs.filerHandler)
|
||||||
|
if defaultMux != readonlyMux {
|
||||||
|
readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)
|
||||||
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
connected := true
|
connected := true
|
||||||
|
@ -18,3 +18,12 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {
|
|||||||
fs.PostHandler(w, r)
|
fs.PostHandler(w, r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (fs *FilerServer) readonlyFilerHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
switch r.Method {
|
||||||
|
case "GET":
|
||||||
|
fs.GetOrHeadHandler(w, r, true)
|
||||||
|
case "HEAD":
|
||||||
|
fs.GetOrHeadHandler(w, r, false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user