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.

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