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.

391 lines
11 KiB

5 years ago
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. The options can also be overwritten by environment variables.
  14. For example, the filer.toml mysql password can be overwritten by environment variable
  15. export WEED_MYSQL_PASSWORD=some_password
  16. Environment variable rules:
  17. * Prefix fix with "WEED_"
  18. * Upppercase the reset of variable name.
  19. * Replace '.' with '_'
  20. `,
  21. }
  22. var (
  23. outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
  24. config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master] the configuration file to generate")
  25. )
  26. func runScaffold(cmd *Command, args []string) bool {
  27. content := ""
  28. switch *config {
  29. case "filer":
  30. content = FILER_TOML_EXAMPLE
  31. case "notification":
  32. content = NOTIFICATION_TOML_EXAMPLE
  33. case "replication":
  34. content = REPLICATION_TOML_EXAMPLE
  35. case "security":
  36. content = SECURITY_TOML_EXAMPLE
  37. case "master":
  38. content = MASTER_TOML_EXAMPLE
  39. }
  40. if content == "" {
  41. println("need a valid -config option")
  42. return false
  43. }
  44. if *outputPath != "" {
  45. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  46. } else {
  47. println(content)
  48. }
  49. return true
  50. }
  51. const (
  52. FILER_TOML_EXAMPLE = `
  53. # A sample TOML config file for SeaweedFS filer store
  54. # Used with "weed filer" or "weed server -filer"
  55. # Put this file to one of the location, with descending priority
  56. # ./filer.toml
  57. # $HOME/.seaweedfs/filer.toml
  58. # /etc/seaweedfs/filer.toml
  59. ####################################################
  60. # Customizable filer server options
  61. ####################################################
  62. [filer.options]
  63. # with http DELETE, by default the filer would check whether a folder is empty.
  64. # recursive_delete will delete all sub folders and files, similar to "rm -Rf"
  65. recursive_delete = false
  66. # directories under this folder will be automatically creating a separate bucket
  67. buckets_folder = /buckets
  68. ####################################################
  69. # The following are filer store options
  70. ####################################################
  71. [leveldb2]
  72. # local on disk, mostly for simple single-machine setup, fairly scalable
  73. # faster than previous leveldb, recommended.
  74. enabled = true
  75. dir = "." # directory to store level db files
  76. [mysql] # or tidb
  77. # CREATE TABLE IF NOT EXISTS filemeta (
  78. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  79. # name VARCHAR(1000) COMMENT 'directory or file name',
  80. # directory TEXT COMMENT 'full path to parent directory',
  81. # meta LONGBLOB,
  82. # PRIMARY KEY (dirhash, name)
  83. # ) DEFAULT CHARSET=utf8;
  84. enabled = false
  85. hostname = "localhost"
  86. port = 3306
  87. username = "root"
  88. password = ""
  89. database = "" # create or use an existing database
  90. connection_max_idle = 2
  91. connection_max_open = 100
  92. interpolateParams = false
  93. [postgres] # or cockroachdb
  94. # CREATE TABLE IF NOT EXISTS filemeta (
  95. # dirhash BIGINT,
  96. # name VARCHAR(65535),
  97. # directory VARCHAR(65535),
  98. # meta bytea,
  99. # PRIMARY KEY (dirhash, name)
  100. # );
  101. enabled = false
  102. hostname = "localhost"
  103. port = 5432
  104. username = "postgres"
  105. password = ""
  106. database = "" # create or use an existing database
  107. sslmode = "disable"
  108. connection_max_idle = 100
  109. connection_max_open = 100
  110. [cassandra]
  111. # CREATE TABLE filemeta (
  112. # directory varchar,
  113. # name varchar,
  114. # meta blob,
  115. # PRIMARY KEY (directory, name)
  116. # ) WITH CLUSTERING ORDER BY (name ASC);
  117. enabled = false
  118. keyspace="seaweedfs"
  119. hosts=[
  120. "localhost:9042",
  121. ]
  122. [redis]
  123. enabled = false
  124. address = "localhost:6379"
  125. password = ""
  126. database = 0
  127. [redis_cluster]
  128. enabled = false
  129. addresses = [
  130. "localhost:30001",
  131. "localhost:30002",
  132. "localhost:30003",
  133. "localhost:30004",
  134. "localhost:30005",
  135. "localhost:30006",
  136. ]
  137. password = ""
  138. # allows reads from slave servers or the master, but all writes still go to the master
  139. readOnly = true
  140. # automatically use the closest Redis server for reads
  141. routeByLatency = true
  142. [etcd]
  143. enabled = false
  144. servers = "localhost:2379"
  145. timeout = "3s"
  146. [tikv]
  147. enabled = false
  148. pdAddress = "192.168.199.113:2379"
  149. `
  150. NOTIFICATION_TOML_EXAMPLE = `
  151. # A sample TOML config file for SeaweedFS filer store
  152. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  153. # Put this file to one of the location, with descending priority
  154. # ./notification.toml
  155. # $HOME/.seaweedfs/notification.toml
  156. # /etc/seaweedfs/notification.toml
  157. ####################################################
  158. # notification
  159. # send and receive filer updates for each file to an external message queue
  160. ####################################################
  161. [notification.log]
  162. # this is only for debugging perpose and does not work with "weed filer.replicate"
  163. enabled = false
  164. [notification.kafka]
  165. enabled = false
  166. hosts = [
  167. "localhost:9092"
  168. ]
  169. topic = "seaweedfs_filer"
  170. offsetFile = "./last.offset"
  171. offsetSaveIntervalSeconds = 10
  172. [notification.aws_sqs]
  173. # experimental, let me know if it works
  174. enabled = false
  175. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  176. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  177. region = "us-east-2"
  178. sqs_queue_name = "my_filer_queue" # an existing queue name
  179. [notification.google_pub_sub]
  180. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  181. enabled = false
  182. google_application_credentials = "/path/to/x.json" # path to json credential file
  183. project_id = "" # an existing project id
  184. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  185. [notification.gocdk_pub_sub]
  186. # The Go Cloud Development Kit (https://gocloud.dev).
  187. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  188. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  189. enabled = false
  190. # This URL will Dial the RabbitMQ server at the URL in the environment
  191. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  192. # The exchange must have already been created by some other means, like
  193. # the RabbitMQ management plugin.
  194. topic_url = "rabbit://myexchange"
  195. sub_url = "rabbit://myqueue"
  196. `
  197. REPLICATION_TOML_EXAMPLE = `
  198. # A sample TOML config file for replicating SeaweedFS filer
  199. # Used with "weed filer.replicate"
  200. # Put this file to one of the location, with descending priority
  201. # ./replication.toml
  202. # $HOME/.seaweedfs/replication.toml
  203. # /etc/seaweedfs/replication.toml
  204. [source.filer]
  205. enabled = true
  206. grpcAddress = "localhost:18888"
  207. # all files under this directory tree are replicated.
  208. # this is not a directory on your hard drive, but on your filer.
  209. # i.e., all files with this "prefix" are sent to notification message queue.
  210. directory = "/buckets"
  211. [sink.filer]
  212. enabled = false
  213. grpcAddress = "localhost:18888"
  214. # all replicated files are under this directory tree
  215. # this is not a directory on your hard drive, but on your filer.
  216. # i.e., all received files will be "prefixed" to this directory.
  217. directory = "/backup"
  218. replication = ""
  219. collection = ""
  220. ttlSec = 0
  221. [sink.s3]
  222. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  223. # default loads credentials from the shared credentials file (~/.aws/credentials).
  224. enabled = false
  225. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  226. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  227. region = "us-east-2"
  228. bucket = "your_bucket_name" # an existing bucket
  229. directory = "/" # destination directory
  230. [sink.google_cloud_storage]
  231. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  232. enabled = false
  233. google_application_credentials = "/path/to/x.json" # path to json credential file
  234. bucket = "your_bucket_seaweedfs" # an existing bucket
  235. directory = "/" # destination directory
  236. [sink.azure]
  237. # experimental, let me know if it works
  238. enabled = false
  239. account_name = ""
  240. account_key = ""
  241. container = "mycontainer" # an existing container
  242. directory = "/" # destination directory
  243. [sink.backblaze]
  244. enabled = false
  245. b2_account_id = ""
  246. b2_master_application_key = ""
  247. bucket = "mybucket" # an existing bucket
  248. directory = "/" # destination directory
  249. `
  250. SECURITY_TOML_EXAMPLE = `
  251. # Put this file to one of the location, with descending priority
  252. # ./security.toml
  253. # $HOME/.seaweedfs/security.toml
  254. # /etc/seaweedfs/security.toml
  255. # this file is read by master, volume server, and filer
  256. # the jwt signing key is read by master and volume server.
  257. # a jwt defaults to expire after 10 seconds.
  258. [jwt.signing]
  259. key = ""
  260. expires_after_seconds = 10 # seconds
  261. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  262. [jwt.signing.read]
  263. key = ""
  264. expires_after_seconds = 10 # seconds
  265. # all grpc tls authentications are mutual
  266. # the values for the following ca, cert, and key are paths to the PERM files.
  267. # the host name is not checked, so the PERM files can be shared.
  268. [grpc]
  269. ca = ""
  270. [grpc.volume]
  271. cert = ""
  272. key = ""
  273. [grpc.master]
  274. cert = ""
  275. key = ""
  276. [grpc.filer]
  277. cert = ""
  278. key = ""
  279. # use this for any place needs a grpc client
  280. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  281. [grpc.client]
  282. cert = ""
  283. key = ""
  284. # volume server https options
  285. # Note: work in progress!
  286. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  287. [https.client]
  288. enabled = true
  289. [https.volume]
  290. cert = ""
  291. key = ""
  292. `
  293. MASTER_TOML_EXAMPLE = `
  294. # Put this file to one of the location, with descending priority
  295. # ./master.toml
  296. # $HOME/.seaweedfs/master.toml
  297. # /etc/seaweedfs/master.toml
  298. # this file is read by master
  299. [master.maintenance]
  300. # periodically run these scripts are the same as running them from 'weed shell'
  301. scripts = """
  302. ec.encode -fullPercent=95 -quietFor=1h
  303. ec.rebuild -force
  304. ec.balance -force
  305. volume.balance -force
  306. """
  307. sleep_minutes = 17 # sleep minutes between each script execution
  308. [master.filer]
  309. default_filer_url = "http://localhost:8888/"
  310. [master.sequencer]
  311. type = "memory" # Choose [memory|etcd] type for storing the file id sequence
  312. # when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
  313. # example : http://127.0.0.1:2379,http://127.0.0.1:2389
  314. sequencer_etcd_urls = "http://127.0.0.1:2379"
  315. # configurations for tiered cloud storage
  316. # old volumes are transparently moved to cloud for cost efficiency
  317. [storage.backend]
  318. [storage.backend.s3.default]
  319. enabled = false
  320. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  321. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  322. region = "us-east-2"
  323. bucket = "your_bucket_name" # an existing bucket
  324. # create this number of logical volumes if no more writable volumes
  325. [master.volume_growth]
  326. count_1 = 7 # create 1 x 7 = 7 actual volumes
  327. count_2 = 6 # create 2 x 6 = 12 actual volumes
  328. count_3 = 3 # create 3 x 3 = 9 actual volumes
  329. count_other = 1 # create n x 1 = n actual volumes
  330. `
  331. )