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.

373 lines
10 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
5 years ago
5 years ago
  1. package command
  2. import (
  3. "io/ioutil"
  4. "path/filepath"
  5. )
  6. func init() {
  7. cmdScaffold.Run = runScaffold // break init cycle
  8. }
  9. var cmdScaffold = &Command{
  10. UsageLine: "scaffold -config=[filer|notification|replication|security|master]",
  11. Short: "generate basic configuration files",
  12. Long: `Generate filer.toml with all possible configurations for you to customize.
  13. `,
  14. }
  15. var (
  16. outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
  17. config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master] the configuration file to generate")
  18. )
  19. func runScaffold(cmd *Command, args []string) bool {
  20. content := ""
  21. switch *config {
  22. case "filer":
  23. content = FILER_TOML_EXAMPLE
  24. case "notification":
  25. content = NOTIFICATION_TOML_EXAMPLE
  26. case "replication":
  27. content = REPLICATION_TOML_EXAMPLE
  28. case "security":
  29. content = SECURITY_TOML_EXAMPLE
  30. case "master":
  31. content = MASTER_TOML_EXAMPLE
  32. }
  33. if content == "" {
  34. println("need a valid -config option")
  35. return false
  36. }
  37. if *outputPath != "" {
  38. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  39. } else {
  40. println(content)
  41. }
  42. return true
  43. }
  44. const (
  45. FILER_TOML_EXAMPLE = `
  46. # A sample TOML config file for SeaweedFS filer store
  47. # Used with "weed filer" or "weed server -filer"
  48. # Put this file to one of the location, with descending priority
  49. # ./filer.toml
  50. # $HOME/.seaweedfs/filer.toml
  51. # /etc/seaweedfs/filer.toml
  52. ####################################################
  53. # Customizable filer server options
  54. ####################################################
  55. [filer.options]
  56. # with http DELETE, by default the filer would check whether a folder is empty.
  57. # recursive_delete will delete all sub folders and files, similar to "rm -Rf"
  58. recursive_delete = false
  59. ####################################################
  60. # The following are filer store options
  61. ####################################################
  62. [leveldb2]
  63. # local on disk, mostly for simple single-machine setup, fairly scalable
  64. # faster than previous leveldb, recommended.
  65. enabled = true
  66. dir = "." # directory to store level db files
  67. [mysql] # or tidb
  68. # CREATE TABLE IF NOT EXISTS filemeta (
  69. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  70. # name VARCHAR(1000) COMMENT 'directory or file name',
  71. # directory TEXT COMMENT 'full path to parent directory',
  72. # meta LONGBLOB,
  73. # PRIMARY KEY (dirhash, name)
  74. # ) DEFAULT CHARSET=utf8;
  75. enabled = false
  76. hostname = "localhost"
  77. port = 3306
  78. username = "root"
  79. password = ""
  80. database = "" # create or use an existing database
  81. connection_max_idle = 2
  82. connection_max_open = 100
  83. interpolateParams = false
  84. [postgres] # or cockroachdb
  85. # CREATE TABLE IF NOT EXISTS filemeta (
  86. # dirhash BIGINT,
  87. # name VARCHAR(65535),
  88. # directory VARCHAR(65535),
  89. # meta bytea,
  90. # PRIMARY KEY (dirhash, name)
  91. # );
  92. enabled = false
  93. hostname = "localhost"
  94. port = 5432
  95. username = "postgres"
  96. password = ""
  97. database = "" # create or use an existing database
  98. sslmode = "disable"
  99. connection_max_idle = 100
  100. connection_max_open = 100
  101. [cassandra]
  102. # CREATE TABLE filemeta (
  103. # directory varchar,
  104. # name varchar,
  105. # meta blob,
  106. # PRIMARY KEY (directory, name)
  107. # ) WITH CLUSTERING ORDER BY (name ASC);
  108. enabled = false
  109. keyspace="seaweedfs"
  110. hosts=[
  111. "localhost:9042",
  112. ]
  113. [redis]
  114. enabled = false
  115. address = "localhost:6379"
  116. password = ""
  117. database = 0
  118. [redis_cluster]
  119. enabled = false
  120. addresses = [
  121. "localhost:30001",
  122. "localhost:30002",
  123. "localhost:30003",
  124. "localhost:30004",
  125. "localhost:30005",
  126. "localhost:30006",
  127. ]
  128. password = ""
  129. # allows reads from slave servers or the master, but all writes still go to the master
  130. readOnly = true
  131. # automatically use the closest Redis server for reads
  132. routeByLatency = true
  133. [etcd]
  134. enabled = false
  135. servers = "localhost:2379"
  136. timeout = "3s"
  137. [tikv]
  138. enabled = false
  139. pdAddress = "192.168.199.113:2379"
  140. `
  141. NOTIFICATION_TOML_EXAMPLE = `
  142. # A sample TOML config file for SeaweedFS filer store
  143. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  144. # Put this file to one of the location, with descending priority
  145. # ./notification.toml
  146. # $HOME/.seaweedfs/notification.toml
  147. # /etc/seaweedfs/notification.toml
  148. ####################################################
  149. # notification
  150. # send and receive filer updates for each file to an external message queue
  151. ####################################################
  152. [notification.log]
  153. # this is only for debugging perpose and does not work with "weed filer.replicate"
  154. enabled = false
  155. [notification.kafka]
  156. enabled = false
  157. hosts = [
  158. "localhost:9092"
  159. ]
  160. topic = "seaweedfs_filer"
  161. offsetFile = "./last.offset"
  162. offsetSaveIntervalSeconds = 10
  163. [notification.aws_sqs]
  164. # experimental, let me know if it works
  165. enabled = false
  166. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  167. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  168. region = "us-east-2"
  169. sqs_queue_name = "my_filer_queue" # an existing queue name
  170. [notification.google_pub_sub]
  171. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  172. enabled = false
  173. google_application_credentials = "/path/to/x.json" # path to json credential file
  174. project_id = "" # an existing project id
  175. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  176. [notification.gocdk_pub_sub]
  177. # The Go Cloud Development Kit (https://gocloud.dev).
  178. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  179. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  180. enabled = false
  181. # This URL will Dial the RabbitMQ server at the URL in the environment
  182. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  183. # The exchange must have already been created by some other means, like
  184. # the RabbitMQ management plugin.
  185. topic_url = "rabbit://myexchange"
  186. sub_url = "rabbit://myqueue"
  187. `
  188. REPLICATION_TOML_EXAMPLE = `
  189. # A sample TOML config file for replicating SeaweedFS filer
  190. # Used with "weed filer.replicate"
  191. # Put this file to one of the location, with descending priority
  192. # ./replication.toml
  193. # $HOME/.seaweedfs/replication.toml
  194. # /etc/seaweedfs/replication.toml
  195. [source.filer]
  196. enabled = true
  197. grpcAddress = "localhost:18888"
  198. # all files under this directory tree are replicated.
  199. # this is not a directory on your hard drive, but on your filer.
  200. # i.e., all files with this "prefix" are sent to notification message queue.
  201. directory = "/buckets"
  202. [sink.filer]
  203. enabled = false
  204. grpcAddress = "localhost:18888"
  205. # all replicated files are under this directory tree
  206. # this is not a directory on your hard drive, but on your filer.
  207. # i.e., all received files will be "prefixed" to this directory.
  208. directory = "/backup"
  209. replication = ""
  210. collection = ""
  211. ttlSec = 0
  212. [sink.s3]
  213. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  214. # default loads credentials from the shared credentials file (~/.aws/credentials).
  215. enabled = false
  216. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  217. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  218. region = "us-east-2"
  219. bucket = "your_bucket_name" # an existing bucket
  220. directory = "/" # destination directory
  221. [sink.google_cloud_storage]
  222. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  223. enabled = false
  224. google_application_credentials = "/path/to/x.json" # path to json credential file
  225. bucket = "your_bucket_seaweedfs" # an existing bucket
  226. directory = "/" # destination directory
  227. [sink.azure]
  228. # experimental, let me know if it works
  229. enabled = false
  230. account_name = ""
  231. account_key = ""
  232. container = "mycontainer" # an existing container
  233. directory = "/" # destination directory
  234. [sink.backblaze]
  235. enabled = false
  236. b2_account_id = ""
  237. b2_master_application_key = ""
  238. bucket = "mybucket" # an existing bucket
  239. directory = "/" # destination directory
  240. `
  241. SECURITY_TOML_EXAMPLE = `
  242. # Put this file to one of the location, with descending priority
  243. # ./security.toml
  244. # $HOME/.seaweedfs/security.toml
  245. # /etc/seaweedfs/security.toml
  246. # this file is read by master, volume server, and filer
  247. # the jwt signing key is read by master and volume server.
  248. # a jwt defaults to expire after 10 seconds.
  249. [jwt.signing]
  250. key = ""
  251. expires_after_seconds = 10 # seconds
  252. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  253. [jwt.signing.read]
  254. key = ""
  255. expires_after_seconds = 10 # seconds
  256. # all grpc tls authentications are mutual
  257. # the values for the following ca, cert, and key are paths to the PERM files.
  258. # the host name is not checked, so the PERM files can be shared.
  259. [grpc]
  260. ca = ""
  261. [grpc.volume]
  262. cert = ""
  263. key = ""
  264. [grpc.master]
  265. cert = ""
  266. key = ""
  267. [grpc.filer]
  268. cert = ""
  269. key = ""
  270. # use this for any place needs a grpc client
  271. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  272. [grpc.client]
  273. cert = ""
  274. key = ""
  275. # volume server https options
  276. # Note: work in progress!
  277. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  278. [https.client]
  279. enabled = true
  280. [https.volume]
  281. cert = ""
  282. key = ""
  283. `
  284. MASTER_TOML_EXAMPLE = `
  285. # Put this file to one of the location, with descending priority
  286. # ./master.toml
  287. # $HOME/.seaweedfs/master.toml
  288. # /etc/seaweedfs/master.toml
  289. # this file is read by master
  290. [master.maintenance]
  291. # periodically run these scripts are the same as running them from 'weed shell'
  292. scripts = """
  293. ec.encode -fullPercent=95 -quietFor=1h
  294. ec.rebuild -force
  295. ec.balance -force
  296. volume.balance -force
  297. """
  298. sleep_minutes = 17 # sleep minutes between each script execution
  299. [master.filer]
  300. default_filer_url = "http://localhost:8888/"
  301. [master.sequencer]
  302. type = "memory" # Choose [memory|etcd] type for storing the file id sequence
  303. # when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
  304. # example : http://127.0.0.1:2379,http://127.0.0.1:2389
  305. sequencer_etcd_urls = "http://127.0.0.1:2379"
  306. [storage.backend]
  307. [storage.backend.s3.default]
  308. enabled = false
  309. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  310. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  311. region = "us-east-2"
  312. bucket = "your_bucket_name" # an existing bucket
  313. `
  314. )