SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
filer add readonly public port
Chris Lu478fe0ecf200
diff --git a/weed/command/filer.go b/weed/command/filer.goindex 2e1c9d1dc1..b90d88edca 100644--- a/weed/command/filer.go+++ b/weed/command/filer.go@@ -19,6 +19,7 @@ type FilerOptions struct {master *stringip *stringport *int+ publicPort *intcollection *stringdefaultReplicaPlacement *stringdir *string@@ -40,6 +41,7 @@ func init() {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.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.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")@@ -83,21 +85,50 @@ func runFiler(cmd *Command, args []string) bool {glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)}+ f.start()++ return true+}++func (fo *FilerOptions) start() {+defaultMux := http.NewServeMux()- _, nfs_err := weed_server.NewFilerServer(defaultMux, *f.ip, *f.port, *f.master, *f.dir, *f.collection,- *f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing,- *f.confFile,- *f.maxMB,- *f.secretKey,- *f.cassandra_server, *f.cassandra_keyspace,- *f.redis_server, *f.redis_password, *f.redis_database,+ publicVolumeMux := defaultMux++ if *fo.publicPort != 0 {+ publicVolumeMux = http.NewServeMux()+ }++ _, 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 {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(- ":"+strconv.Itoa(*f.port),+ ":"+strconv.Itoa(*fo.port),time.Duration(10)*time.Second,)if e != nil {@@ -107,5 +138,4 @@ func runFiler(cmd *Command, args []string) bool {glog.Fatalf("Filer Fail to serve: %v", e)}- return true}diff --git a/weed/command/server.go b/weed/command/server.goindex ad6916b8fa..0c50709814 100644--- a/weed/command/server.go+++ b/weed/command/server.go@@ -87,6 +87,7 @@ func init() {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.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.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")@@ -116,6 +117,7 @@ func runServer(cmd *Command, args []string) bool {}*filerOptions.master = *serverIp + ":" + strconv.Itoa(*masterPort)+ filerOptions.ip = serverIpif *filerOptions.defaultReplicaPlacement == "" {*filerOptions.defaultReplicaPlacement = *masterDefaultReplicaPlacement@@ -172,30 +174,9 @@ func runServer(cmd *Command, args []string) bool {if *isStartingFiler {go func() {time.Sleep(1 * time.Second)- r := http.NewServeMux()- _, nfs_err := weed_server.NewFilerServer(r, *serverBindIp, *filerOptions.port, *filerOptions.master, *filerOptions.dir, *filerOptions.collection,- *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)- }++ filerOptions.start()+}()}diff --git a/weed/server/filer_server.go b/weed/server/filer_server.goindex 467545dfd6..26b261087f 100644--- a/weed/server/filer_server.go+++ b/weed/server/filer_server.go@@ -57,7 +57,7 @@ type FilerServer struct {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,confFile string,maxMB int,@@ -111,6 +111,9 @@ func NewFilerServer(defaultMux *http.ServeMux, ip string, port int, master strin}defaultMux.HandleFunc("/", fs.filerHandler)+ if defaultMux != readonlyMux {+ readonlyMux.HandleFunc("/", fs.readonlyFilerHandler)+ }go func() {connected := truediff --git a/weed/server/filer_server_handlers.go b/weed/server/filer_server_handlers.goindex 4e39258af2..d76d7df8c4 100644--- a/weed/server/filer_server_handlers.go+++ b/weed/server/filer_server_handlers.go@@ -18,3 +18,12 @@ func (fs *FilerServer) filerHandler(w http.ResponseWriter, r *http.Request) {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)+ }+}