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.

409 lines
12 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
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 the variable name 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. # directories under this folder will be store message queue data
  69. queues_folder = "/queues"
  70. ####################################################
  71. # The following are filer store options
  72. ####################################################
  73. [leveldb2]
  74. # local on disk, mostly for simple single-machine setup, fairly scalable
  75. # faster than previous leveldb, recommended.
  76. enabled = true
  77. dir = "." # directory to store level db files
  78. [mysql] # or tidb
  79. # CREATE TABLE IF NOT EXISTS filemeta (
  80. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  81. # name VARCHAR(1000) COMMENT 'directory or file name',
  82. # directory TEXT COMMENT 'full path to parent directory',
  83. # meta LONGBLOB,
  84. # PRIMARY KEY (dirhash, name)
  85. # ) DEFAULT CHARSET=utf8;
  86. enabled = false
  87. hostname = "localhost"
  88. port = 3306
  89. username = "root"
  90. password = ""
  91. database = "" # create or use an existing database
  92. connection_max_idle = 2
  93. connection_max_open = 100
  94. interpolateParams = false
  95. [postgres] # or cockroachdb
  96. # CREATE TABLE IF NOT EXISTS filemeta (
  97. # dirhash BIGINT,
  98. # name VARCHAR(65535),
  99. # directory VARCHAR(65535),
  100. # meta bytea,
  101. # PRIMARY KEY (dirhash, name)
  102. # );
  103. enabled = false
  104. hostname = "localhost"
  105. port = 5432
  106. username = "postgres"
  107. password = ""
  108. database = "" # create or use an existing database
  109. sslmode = "disable"
  110. connection_max_idle = 100
  111. connection_max_open = 100
  112. [cassandra]
  113. # CREATE TABLE filemeta (
  114. # directory varchar,
  115. # name varchar,
  116. # meta blob,
  117. # PRIMARY KEY (directory, name)
  118. # ) WITH CLUSTERING ORDER BY (name ASC);
  119. enabled = false
  120. keyspace="seaweedfs"
  121. hosts=[
  122. "localhost:9042",
  123. ]
  124. [redis]
  125. enabled = false
  126. address = "localhost:6379"
  127. password = ""
  128. database = 0
  129. [redis_cluster]
  130. enabled = false
  131. addresses = [
  132. "localhost:30001",
  133. "localhost:30002",
  134. "localhost:30003",
  135. "localhost:30004",
  136. "localhost:30005",
  137. "localhost:30006",
  138. ]
  139. password = ""
  140. # allows reads from slave servers or the master, but all writes still go to the master
  141. readOnly = true
  142. # automatically use the closest Redis server for reads
  143. routeByLatency = true
  144. [etcd]
  145. enabled = false
  146. servers = "localhost:2379"
  147. timeout = "3s"
  148. `
  149. NOTIFICATION_TOML_EXAMPLE = `
  150. # A sample TOML config file for SeaweedFS filer store
  151. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  152. # Put this file to one of the location, with descending priority
  153. # ./notification.toml
  154. # $HOME/.seaweedfs/notification.toml
  155. # /etc/seaweedfs/notification.toml
  156. ####################################################
  157. # notification
  158. # send and receive filer updates for each file to an external message queue
  159. ####################################################
  160. [notification.log]
  161. # this is only for debugging perpose and does not work with "weed filer.replicate"
  162. enabled = false
  163. [notification.kafka]
  164. enabled = false
  165. hosts = [
  166. "localhost:9092"
  167. ]
  168. topic = "seaweedfs_filer"
  169. offsetFile = "./last.offset"
  170. offsetSaveIntervalSeconds = 10
  171. [notification.aws_sqs]
  172. # experimental, let me know if it works
  173. enabled = false
  174. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  175. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  176. region = "us-east-2"
  177. sqs_queue_name = "my_filer_queue" # an existing queue name
  178. [notification.google_pub_sub]
  179. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  180. enabled = false
  181. google_application_credentials = "/path/to/x.json" # path to json credential file
  182. project_id = "" # an existing project id
  183. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  184. [notification.gocdk_pub_sub]
  185. # The Go Cloud Development Kit (https://gocloud.dev).
  186. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  187. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  188. enabled = false
  189. # This URL will Dial the RabbitMQ server at the URL in the environment
  190. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  191. # The exchange must have already been created by some other means, like
  192. # the RabbitMQ management plugin.
  193. topic_url = "rabbit://myexchange"
  194. sub_url = "rabbit://myqueue"
  195. `
  196. REPLICATION_TOML_EXAMPLE = `
  197. # A sample TOML config file for replicating SeaweedFS filer
  198. # Used with "weed filer.replicate"
  199. # Put this file to one of the location, with descending priority
  200. # ./replication.toml
  201. # $HOME/.seaweedfs/replication.toml
  202. # /etc/seaweedfs/replication.toml
  203. [source.filer]
  204. enabled = true
  205. grpcAddress = "localhost:18888"
  206. # all files under this directory tree are replicated.
  207. # this is not a directory on your hard drive, but on your filer.
  208. # i.e., all files with this "prefix" are sent to notification message queue.
  209. directory = "/buckets"
  210. [sink.filer]
  211. enabled = false
  212. grpcAddress = "localhost:18888"
  213. # all replicated files are under this directory tree
  214. # this is not a directory on your hard drive, but on your filer.
  215. # i.e., all received files will be "prefixed" to this directory.
  216. directory = "/backup"
  217. replication = ""
  218. collection = ""
  219. ttlSec = 0
  220. [sink.s3]
  221. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  222. # default loads credentials from the shared credentials file (~/.aws/credentials).
  223. enabled = false
  224. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  225. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  226. region = "us-east-2"
  227. bucket = "your_bucket_name" # an existing bucket
  228. directory = "/" # destination directory
  229. endpoint = ""
  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. [grpc.msg_broker]
  280. cert = ""
  281. key = ""
  282. # use this for any place needs a grpc client
  283. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  284. [grpc.client]
  285. cert = ""
  286. key = ""
  287. # volume server https options
  288. # Note: work in progress!
  289. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  290. [https.client]
  291. enabled = true
  292. [https.volume]
  293. cert = ""
  294. key = ""
  295. `
  296. MASTER_TOML_EXAMPLE = `
  297. # Put this file to one of the location, with descending priority
  298. # ./master.toml
  299. # $HOME/.seaweedfs/master.toml
  300. # /etc/seaweedfs/master.toml
  301. # this file is read by master
  302. [master.maintenance]
  303. # periodically run these scripts are the same as running them from 'weed shell'
  304. scripts = """
  305. ec.encode -fullPercent=95 -quietFor=1h
  306. ec.rebuild -force
  307. ec.balance -force
  308. volume.balance -force
  309. volume.fix.replication
  310. """
  311. sleep_minutes = 17 # sleep minutes between each script execution
  312. [master.filer]
  313. default = "localhost:8888" # used by maintenance scripts if the scripts needs to use fs related commands
  314. [master.sequencer]
  315. type = "memory" # Choose [memory|etcd] type for storing the file id sequence
  316. # when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
  317. # example : http://127.0.0.1:2379,http://127.0.0.1:2389
  318. sequencer_etcd_urls = "http://127.0.0.1:2379"
  319. # configurations for tiered cloud storage
  320. # old volumes are transparently moved to cloud for cost efficiency
  321. [storage.backend]
  322. [storage.backend.s3.default]
  323. enabled = false
  324. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  325. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  326. region = "us-east-2"
  327. bucket = "your_bucket_name" # an existing bucket
  328. endpoint = ""
  329. # create this number of logical volumes if no more writable volumes
  330. # count_x means how many copies of data.
  331. # e.g.:
  332. # 000 has only one copy, copy_1
  333. # 010 and 001 has two copies, copy_2
  334. # 011 has only 3 copies, copy_3
  335. [master.volume_growth]
  336. copy_1 = 7 # create 1 x 7 = 7 actual volumes
  337. copy_2 = 6 # create 2 x 6 = 12 actual volumes
  338. copy_3 = 3 # create 3 x 3 = 9 actual volumes
  339. copy_other = 1 # create n x 1 = n actual volumes
  340. # configuration flags for replication
  341. [master.replication]
  342. # any replication counts should be considered minimums. If you specify 010 and
  343. # have 3 different racks, that's still considered writable. Writes will still
  344. # try to replicate to all available volumes. You should only use this option
  345. # if you are doing your own replication or periodic sync of volumes.
  346. treat_replication_as_minimums = false
  347. `
  348. )