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.

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