You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.0 KiB

11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
10 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
  1. package command
  2. import (
  3. "net/http"
  4. "os"
  5. "strconv"
  6. "time"
  7. "github.com/chrislusf/seaweedfs/weed/glog"
  8. "github.com/chrislusf/seaweedfs/weed/server"
  9. "github.com/chrislusf/seaweedfs/weed/util"
  10. )
  11. var (
  12. f FilerOptions
  13. )
  14. type FilerOptions struct {
  15. master *string
  16. ip *string
  17. port *int
  18. collection *string
  19. defaultReplicaPlacement *string
  20. dir *string
  21. redirectOnRead *bool
  22. disableDirListing *bool
  23. confFile *string
  24. maxMB *int
  25. secretKey *string
  26. cassandra_server *string
  27. cassandra_keyspace *string
  28. redis_server *string
  29. redis_password *string
  30. redis_database *int
  31. }
  32. func init() {
  33. cmdFiler.Run = runFiler // break init cycle
  34. f.master = cmdFiler.Flag.String("master", "localhost:9333", "master server location")
  35. f.collection = cmdFiler.Flag.String("collection", "", "all data will be stored in this collection")
  36. f.ip = cmdFiler.Flag.String("ip", "", "filer server http listen ip address")
  37. f.port = cmdFiler.Flag.Int("port", 8888, "filer server http listen port")
  38. f.dir = cmdFiler.Flag.String("dir", os.TempDir(), "directory to store meta data")
  39. f.defaultReplicaPlacement = cmdFiler.Flag.String("defaultReplicaPlacement", "000", "default replication type if not specified")
  40. f.redirectOnRead = cmdFiler.Flag.Bool("redirectOnRead", false, "whether proxy or redirect to volume server during file GET request")
  41. f.disableDirListing = cmdFiler.Flag.Bool("disableDirListing", false, "turn off directory listing")
  42. f.confFile = cmdFiler.Flag.String("confFile", "", "json encoded filer conf file")
  43. f.maxMB = cmdFiler.Flag.Int("maxMB", 0, "split files larger than the limit")
  44. f.cassandra_server = cmdFiler.Flag.String("cassandra.server", "", "host[:port] of the cassandra server")
  45. f.cassandra_keyspace = cmdFiler.Flag.String("cassandra.keyspace", "seaweed", "keyspace of the cassandra server")
  46. f.redis_server = cmdFiler.Flag.String("redis.server", "", "host:port of the redis server, e.g., 127.0.0.1:6379")
  47. f.redis_password = cmdFiler.Flag.String("redis.password", "", "password in clear text")
  48. f.redis_database = cmdFiler.Flag.Int("redis.database", 0, "the database on the redis server")
  49. f.secretKey = cmdFiler.Flag.String("secure.secret", "", "secret to encrypt Json Web Token(JWT)")
  50. }
  51. var cmdFiler = &Command{
  52. UsageLine: "filer -port=8888 -dir=/tmp -master=<ip:port>",
  53. Short: "start a file server that points to a master server",
  54. Long: `start a file server which accepts REST operation for any files.
  55. //create or overwrite the file, the directories /path/to will be automatically created
  56. POST /path/to/file
  57. //get the file content
  58. GET /path/to/file
  59. //create or overwrite the file, the filename in the multipart request will be used
  60. POST /path/to/
  61. //return a json format subdirectory and files listing
  62. GET /path/to/
  63. Current <fullpath~fileid> mapping metadata store is local embedded leveldb.
  64. It should be highly scalable to hundreds of millions of files on a modest machine.
  65. Future we will ensure it can avoid of being SPOF.
  66. `,
  67. }
  68. func runFiler(cmd *Command, args []string) bool {
  69. if err := util.TestFolderWritable(*f.dir); err != nil {
  70. glog.Fatalf("Check Meta Folder (-dir) Writable %s : %s", *f.dir, err)
  71. }
  72. r := http.NewServeMux()
  73. _, nfs_err := weed_server.NewFilerServer(r, *f.ip, *f.port, *f.master, *f.dir, *f.collection,
  74. *f.defaultReplicaPlacement, *f.redirectOnRead, *f.disableDirListing,
  75. *f.confFile,
  76. *f.maxMB,
  77. *f.secretKey,
  78. *f.cassandra_server, *f.cassandra_keyspace,
  79. *f.redis_server, *f.redis_password, *f.redis_database,
  80. )
  81. if nfs_err != nil {
  82. glog.Fatalf("Filer startup error: %v", nfs_err)
  83. }
  84. glog.V(0).Infoln("Start Seaweed Filer", util.VERSION, "at port", strconv.Itoa(*f.port))
  85. filerListener, e := util.NewListener(
  86. ":"+strconv.Itoa(*f.port),
  87. time.Duration(10)*time.Second,
  88. )
  89. if e != nil {
  90. glog.Fatalf("Filer listener error: %v", e)
  91. }
  92. if e := http.Serve(filerListener, r); e != nil {
  93. glog.Fatalf("Filer Fail to serve: %v", e)
  94. }
  95. return true
  96. }