scaffold.go 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  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. [memory]
  53. # local in memory, mostly for testing purpose
  54. enabled = false
  55. [leveldb]
  56. # local on disk, mostly for simple single-machine setup, fairly scalable
  57. enabled = false
  58. dir = "." # directory to store level db files
  59. [leveldb2]
  60. # local on disk, mostly for simple single-machine setup, fairly scalable
  61. # faster than previous leveldb, recommended.
  62. enabled = true
  63. dir = "." # directory to store level db files
  64. ####################################################
  65. # multiple filers on shared storage, fairly scalable
  66. ####################################################
  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. [postgres] # or cockroachdb
  84. # CREATE TABLE IF NOT EXISTS filemeta (
  85. # dirhash BIGINT,
  86. # name VARCHAR(65535),
  87. # directory VARCHAR(65535),
  88. # meta bytea,
  89. # PRIMARY KEY (dirhash, name)
  90. # );
  91. enabled = false
  92. hostname = "localhost"
  93. port = 5432
  94. username = "postgres"
  95. password = ""
  96. database = "" # create or use an existing database
  97. sslmode = "disable"
  98. connection_max_idle = 100
  99. connection_max_open = 100
  100. [cassandra]
  101. # CREATE TABLE filemeta (
  102. # directory varchar,
  103. # name varchar,
  104. # meta blob,
  105. # PRIMARY KEY (directory, name)
  106. # ) WITH CLUSTERING ORDER BY (name ASC);
  107. enabled = false
  108. keyspace="seaweedfs"
  109. hosts=[
  110. "localhost:9042",
  111. ]
  112. [redis]
  113. enabled = false
  114. address = "localhost:6379"
  115. password = ""
  116. database = 0
  117. [redis_cluster]
  118. enabled = false
  119. addresses = [
  120. "localhost:30001",
  121. "localhost:30002",
  122. "localhost:30003",
  123. "localhost:30004",
  124. "localhost:30005",
  125. "localhost:30006",
  126. ]
  127. password = ""
  128. [etcd]
  129. enabled = false
  130. servers = "localhost:2379"
  131. timeout = "3s"
  132. [tikv]
  133. enabled = false
  134. pdAddress = "192.168.199.113:2379"
  135. `
  136. NOTIFICATION_TOML_EXAMPLE = `
  137. # A sample TOML config file for SeaweedFS filer store
  138. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  139. # Put this file to one of the location, with descending priority
  140. # ./notification.toml
  141. # $HOME/.seaweedfs/notification.toml
  142. # /etc/seaweedfs/notification.toml
  143. ####################################################
  144. # notification
  145. # send and receive filer updates for each file to an external message queue
  146. ####################################################
  147. [notification.log]
  148. # this is only for debugging perpose and does not work with "weed filer.replicate"
  149. enabled = false
  150. [notification.kafka]
  151. enabled = false
  152. hosts = [
  153. "localhost:9092"
  154. ]
  155. topic = "seaweedfs_filer"
  156. offsetFile = "./last.offset"
  157. offsetSaveIntervalSeconds = 10
  158. [notification.aws_sqs]
  159. # experimental, let me know if it works
  160. enabled = false
  161. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  162. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  163. region = "us-east-2"
  164. sqs_queue_name = "my_filer_queue" # an existing queue name
  165. [notification.google_pub_sub]
  166. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  167. enabled = false
  168. google_application_credentials = "/path/to/x.json" # path to json credential file
  169. project_id = "" # an existing project id
  170. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  171. [notification.gocdk_pub_sub]
  172. # The Go Cloud Development Kit (https://gocloud.dev).
  173. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  174. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  175. enabled = false
  176. # This URL will Dial the RabbitMQ server at the URL in the environment
  177. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  178. # The exchange must have already been created by some other means, like
  179. # the RabbitMQ management plugin.
  180. topic_url = "rabbit://myexchange"
  181. sub_url = "rabbit://myqueue"
  182. `
  183. REPLICATION_TOML_EXAMPLE = `
  184. # A sample TOML config file for replicating SeaweedFS filer
  185. # Used with "weed filer.replicate"
  186. # Put this file to one of the location, with descending priority
  187. # ./replication.toml
  188. # $HOME/.seaweedfs/replication.toml
  189. # /etc/seaweedfs/replication.toml
  190. [source.filer]
  191. enabled = true
  192. grpcAddress = "localhost:18888"
  193. # all files under this directory tree are replicated.
  194. # this is not a directory on your hard drive, but on your filer.
  195. # i.e., all files with this "prefix" are sent to notification message queue.
  196. directory = "/buckets"
  197. [sink.filer]
  198. enabled = false
  199. grpcAddress = "localhost:18888"
  200. # all replicated files are under this directory tree
  201. # this is not a directory on your hard drive, but on your filer.
  202. # i.e., all received files will be "prefixed" to this directory.
  203. directory = "/backup"
  204. replication = ""
  205. collection = ""
  206. ttlSec = 0
  207. [sink.s3]
  208. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  209. # default loads credentials from the shared credentials file (~/.aws/credentials).
  210. enabled = false
  211. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  212. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  213. region = "us-east-2"
  214. bucket = "your_bucket_name" # an existing bucket
  215. directory = "/" # destination directory
  216. [sink.google_cloud_storage]
  217. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  218. enabled = false
  219. google_application_credentials = "/path/to/x.json" # path to json credential file
  220. bucket = "your_bucket_seaweedfs" # an existing bucket
  221. directory = "/" # destination directory
  222. [sink.azure]
  223. # experimental, let me know if it works
  224. enabled = false
  225. account_name = ""
  226. account_key = ""
  227. container = "mycontainer" # an existing container
  228. directory = "/" # destination directory
  229. [sink.backblaze]
  230. enabled = false
  231. b2_account_id = ""
  232. b2_master_application_key = ""
  233. bucket = "mybucket" # an existing bucket
  234. directory = "/" # destination directory
  235. `
  236. SECURITY_TOML_EXAMPLE = `
  237. # Put this file to one of the location, with descending priority
  238. # ./security.toml
  239. # $HOME/.seaweedfs/security.toml
  240. # /etc/seaweedfs/security.toml
  241. # this file is read by master, volume server, and filer
  242. # the jwt signing key is read by master and volume server.
  243. # a jwt defaults to expire after 10 seconds.
  244. [jwt.signing]
  245. key = ""
  246. expires_after_seconds = 10 # seconds
  247. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  248. [jwt.signing.read]
  249. key = ""
  250. expires_after_seconds = 10 # seconds
  251. # all grpc tls authentications are mutual
  252. # the values for the following ca, cert, and key are paths to the PERM files.
  253. # the host name is not checked, so the PERM files can be shared.
  254. [grpc]
  255. ca = ""
  256. [grpc.volume]
  257. cert = ""
  258. key = ""
  259. [grpc.master]
  260. cert = ""
  261. key = ""
  262. [grpc.filer]
  263. cert = ""
  264. key = ""
  265. # use this for any place needs a grpc client
  266. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  267. [grpc.client]
  268. cert = ""
  269. key = ""
  270. # volume server https options
  271. # Note: work in progress!
  272. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  273. [https.client]
  274. enabled = true
  275. [https.volume]
  276. cert = ""
  277. key = ""
  278. `
  279. MASTER_TOML_EXAMPLE = `
  280. # Put this file to one of the location, with descending priority
  281. # ./master.toml
  282. # $HOME/.seaweedfs/master.toml
  283. # /etc/seaweedfs/master.toml
  284. # this file is read by master
  285. [master.maintenance]
  286. # periodically run these scripts are the same as running them from 'weed shell'
  287. scripts = """
  288. ec.encode -fullPercent=95 -quietFor=1h
  289. ec.rebuild -force
  290. ec.balance -force
  291. volume.balance -force
  292. """
  293. sleep_minutes = 17 # sleep minutes between each script execution
  294. [master.filer]
  295. default_filer_url = "http://localhost:8888/"
  296. [master.sequencer]
  297. type = memory # Choose [memory|etcd] type for storing the file id sequence
  298. # when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
  299. # example : http://127.0.0.1:2379,http://127.0.0.1:2389
  300. sequencer_etcd_urls = http://127.0.0.1:2379
  301. [storage.backend.s3]
  302. enabled = true
  303. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  304. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  305. region = "us-east-2"
  306. bucket = "your_bucket_name" # an existing bucket
  307. directory = "/" # destination directory
  308. `
  309. )