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.

345 lines
9.5 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. [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. `
  133. NOTIFICATION_TOML_EXAMPLE = `
  134. # A sample TOML config file for SeaweedFS filer store
  135. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  136. # Put this file to one of the location, with descending priority
  137. # ./notification.toml
  138. # $HOME/.seaweedfs/notification.toml
  139. # /etc/seaweedfs/notification.toml
  140. ####################################################
  141. # notification
  142. # send and receive filer updates for each file to an external message queue
  143. ####################################################
  144. [notification.log]
  145. # this is only for debugging perpose and does not work with "weed filer.replicate"
  146. enabled = false
  147. [notification.kafka]
  148. enabled = false
  149. hosts = [
  150. "localhost:9092"
  151. ]
  152. topic = "seaweedfs_filer"
  153. offsetFile = "./last.offset"
  154. offsetSaveIntervalSeconds = 10
  155. [notification.aws_sqs]
  156. # experimental, let me know if it works
  157. enabled = false
  158. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  159. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  160. region = "us-east-2"
  161. sqs_queue_name = "my_filer_queue" # an existing queue name
  162. [notification.google_pub_sub]
  163. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  164. enabled = false
  165. google_application_credentials = "/path/to/x.json" # path to json credential file
  166. project_id = "" # an existing project id
  167. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  168. [notification.gocdk_pub_sub]
  169. # The Go Cloud Development Kit (https://gocloud.dev).
  170. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  171. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  172. enabled = false
  173. # This URL will Dial the RabbitMQ server at the URL in the environment
  174. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  175. # The exchange must have already been created by some other means, like
  176. # the RabbitMQ management plugin.
  177. topic_url = "rabbit://myexchange"
  178. sub_url = "rabbit://myqueue"
  179. `
  180. REPLICATION_TOML_EXAMPLE = `
  181. # A sample TOML config file for replicating SeaweedFS filer
  182. # Used with "weed filer.replicate"
  183. # Put this file to one of the location, with descending priority
  184. # ./replication.toml
  185. # $HOME/.seaweedfs/replication.toml
  186. # /etc/seaweedfs/replication.toml
  187. [source.filer]
  188. enabled = true
  189. grpcAddress = "localhost:18888"
  190. # all files under this directory tree are replicated.
  191. # this is not a directory on your hard drive, but on your filer.
  192. # i.e., all files with this "prefix" are sent to notification message queue.
  193. directory = "/buckets"
  194. [sink.filer]
  195. enabled = false
  196. grpcAddress = "localhost:18888"
  197. # all replicated files are under this directory tree
  198. # this is not a directory on your hard drive, but on your filer.
  199. # i.e., all received files will be "prefixed" to this directory.
  200. directory = "/backup"
  201. replication = ""
  202. collection = ""
  203. ttlSec = 0
  204. [sink.s3]
  205. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  206. # default loads credentials from the shared credentials file (~/.aws/credentials).
  207. enabled = false
  208. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  209. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  210. region = "us-east-2"
  211. bucket = "your_bucket_name" # an existing bucket
  212. directory = "/" # destination directory
  213. [sink.google_cloud_storage]
  214. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  215. enabled = false
  216. google_application_credentials = "/path/to/x.json" # path to json credential file
  217. bucket = "your_bucket_seaweedfs" # an existing bucket
  218. directory = "/" # destination directory
  219. [sink.azure]
  220. # experimental, let me know if it works
  221. enabled = false
  222. account_name = ""
  223. account_key = ""
  224. container = "mycontainer" # an existing container
  225. directory = "/" # destination directory
  226. [sink.backblaze]
  227. enabled = false
  228. b2_account_id = ""
  229. b2_master_application_key = ""
  230. bucket = "mybucket" # an existing bucket
  231. directory = "/" # destination directory
  232. `
  233. SECURITY_TOML_EXAMPLE = `
  234. # Put this file to one of the location, with descending priority
  235. # ./security.toml
  236. # $HOME/.seaweedfs/security.toml
  237. # /etc/seaweedfs/security.toml
  238. # this file is read by master, volume server, and filer
  239. # the jwt signing key is read by master and volume server.
  240. # a jwt defaults to expire after 10 seconds.
  241. [jwt.signing]
  242. key = ""
  243. expires_after_seconds = 10 # seconds
  244. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  245. [jwt.signing.read]
  246. key = ""
  247. expires_after_seconds = 10 # seconds
  248. # all grpc tls authentications are mutual
  249. # the values for the following ca, cert, and key are paths to the PERM files.
  250. # the host name is not checked, so the PERM files can be shared.
  251. [grpc]
  252. ca = ""
  253. [grpc.volume]
  254. cert = ""
  255. key = ""
  256. [grpc.master]
  257. cert = ""
  258. key = ""
  259. [grpc.filer]
  260. cert = ""
  261. key = ""
  262. # use this for any place needs a grpc client
  263. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  264. [grpc.client]
  265. cert = ""
  266. key = ""
  267. # volume server https options
  268. # Note: work in progress!
  269. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  270. [https.client]
  271. enabled = true
  272. [https.volume]
  273. cert = ""
  274. key = ""
  275. `
  276. MASTER_TOML_EXAMPLE = `
  277. # Put this file to one of the location, with descending priority
  278. # ./master.toml
  279. # $HOME/.seaweedfs/master.toml
  280. # /etc/seaweedfs/master.toml
  281. # this file is read by master
  282. [master.maintenance]
  283. # periodically run these scripts are the same as running them from 'weed shell'
  284. scripts = """
  285. ec.encode -fullPercent=95 -quietFor=1h
  286. ec.rebuild -force
  287. ec.balance -force
  288. volume.balance -force
  289. """
  290. sleep_minutes = 17 # sleep minutes between each script execution
  291. `
  292. )