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.

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