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.

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