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.

141 lines
4.9 KiB

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