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.

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