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.

573 lines
17 KiB

5 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
4 years ago
4 years ago
4 years ago
4 years ago
5 years ago
4 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. case "shell":
  40. content = SHELL_TOML_EXAMPLE
  41. }
  42. if content == "" {
  43. println("need a valid -config option")
  44. return false
  45. }
  46. if *outputPath != "" {
  47. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  48. } else {
  49. println(content)
  50. }
  51. return true
  52. }
  53. const (
  54. FILER_TOML_EXAMPLE = `
  55. # A sample TOML config file for SeaweedFS filer store
  56. # Used with "weed filer" or "weed server -filer"
  57. # Put this file to one of the location, with descending priority
  58. # ./filer.toml
  59. # $HOME/.seaweedfs/filer.toml
  60. # /etc/seaweedfs/filer.toml
  61. ####################################################
  62. # Customizable filer server options
  63. ####################################################
  64. [filer.options]
  65. # with http DELETE, by default the filer would check whether a folder is empty.
  66. # recursive_delete will delete all sub folders and files, similar to "rm -Rf"
  67. recursive_delete = false
  68. # directories under this folder will be automatically creating a separate bucket
  69. buckets_folder = "/buckets"
  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 = "./filerldb2" # directory to store level db files
  78. [leveldb3]
  79. # similar to leveldb2.
  80. # each bucket has its own meta store.
  81. enabled = false
  82. dir = "./filerldb3" # directory to store level db files
  83. [rocksdb]
  84. # local on disk, similar to leveldb
  85. # since it is using a C wrapper, you need to install rocksdb and build it by yourself
  86. enabled = false
  87. dir = "./filerrdb" # directory to store rocksdb files
  88. [mysql] # or memsql, tidb
  89. # CREATE TABLE IF NOT EXISTS filemeta (
  90. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  91. # name VARCHAR(1000) BINARY COMMENT 'directory or file name',
  92. # directory TEXT COMMENT 'full path to parent directory',
  93. # meta LONGBLOB,
  94. # PRIMARY KEY (dirhash, name)
  95. # ) DEFAULT CHARSET=utf8;
  96. enabled = false
  97. hostname = "localhost"
  98. port = 3306
  99. username = "root"
  100. password = ""
  101. database = "" # create or use an existing database
  102. connection_max_idle = 2
  103. connection_max_open = 100
  104. connection_max_lifetime_seconds = 0
  105. interpolateParams = false
  106. # if insert/upsert failing, you can disable upsert or update query syntax to match your RDBMS syntax:
  107. enableUpsert = true
  108. upsertQuery = """INSERT INTO ` + "`%s`" + ` (dirhash,name,directory,meta) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE meta = VALUES(meta)"""
  109. [mysql2] # or memsql, tidb
  110. enabled = false
  111. createTable = """
  112. CREATE TABLE IF NOT EXISTS ` + "`%s`" + ` (
  113. dirhash BIGINT,
  114. name VARCHAR(1000) BINARY,
  115. directory TEXT,
  116. meta LONGBLOB,
  117. PRIMARY KEY (dirhash, name)
  118. ) DEFAULT CHARSET=utf8;
  119. """
  120. hostname = "localhost"
  121. port = 3306
  122. username = "root"
  123. password = ""
  124. database = "" # create or use an existing database
  125. connection_max_idle = 2
  126. connection_max_open = 100
  127. connection_max_lifetime_seconds = 0
  128. interpolateParams = false
  129. # if insert/upsert failing, you can disable upsert or update query syntax to match your RDBMS syntax:
  130. enableUpsert = true
  131. upsertQuery = """INSERT INTO ` + "`%s`" + ` (dirhash,name,directory,meta) VALUES(?,?,?,?) ON DUPLICATE KEY UPDATE meta = VALUES(meta)"""
  132. [postgres] # or cockroachdb, YugabyteDB
  133. # CREATE TABLE IF NOT EXISTS filemeta (
  134. # dirhash BIGINT,
  135. # name VARCHAR(65535),
  136. # directory VARCHAR(65535),
  137. # meta bytea,
  138. # PRIMARY KEY (dirhash, name)
  139. # );
  140. enabled = false
  141. hostname = "localhost"
  142. port = 5432
  143. username = "postgres"
  144. password = ""
  145. database = "postgres" # create or use an existing database
  146. schema = ""
  147. sslmode = "disable"
  148. connection_max_idle = 100
  149. connection_max_open = 100
  150. connection_max_lifetime_seconds = 0
  151. # if insert/upsert failing, you can disable upsert or update query syntax to match your RDBMS syntax:
  152. enableUpsert = true
  153. upsertQuery = """INSERT INTO "%[1]s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4) ON CONFLICT (dirhash,name) DO UPDATE SET meta = EXCLUDED.meta WHERE "%[1]s".meta != EXCLUDED.meta"""
  154. [postgres2]
  155. enabled = false
  156. createTable = """
  157. CREATE TABLE IF NOT EXISTS "%s" (
  158. dirhash BIGINT,
  159. name VARCHAR(65535),
  160. directory VARCHAR(65535),
  161. meta bytea,
  162. PRIMARY KEY (dirhash, name)
  163. );
  164. """
  165. hostname = "localhost"
  166. port = 5432
  167. username = "postgres"
  168. password = ""
  169. database = "postgres" # create or use an existing database
  170. schema = ""
  171. sslmode = "disable"
  172. connection_max_idle = 100
  173. connection_max_open = 100
  174. connection_max_lifetime_seconds = 0
  175. # if insert/upsert failing, you can disable upsert or update query syntax to match your RDBMS syntax:
  176. enableUpsert = true
  177. upsertQuery = """INSERT INTO "%[1]s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4) ON CONFLICT (dirhash,name) DO UPDATE SET meta = EXCLUDED.meta WHERE "%[1]s".meta != EXCLUDED.meta"""
  178. [cassandra]
  179. # CREATE TABLE filemeta (
  180. # directory varchar,
  181. # name varchar,
  182. # meta blob,
  183. # PRIMARY KEY (directory, name)
  184. # ) WITH CLUSTERING ORDER BY (name ASC);
  185. enabled = false
  186. keyspace="seaweedfs"
  187. hosts=[
  188. "localhost:9042",
  189. ]
  190. username=""
  191. password=""
  192. # This changes the data layout. Only add new directories. Removing/Updating will cause data loss.
  193. superLargeDirectories = []
  194. [hbase]
  195. enabled = false
  196. zkquorum = ""
  197. table = "seaweedfs"
  198. [redis2]
  199. enabled = false
  200. address = "localhost:6379"
  201. password = ""
  202. database = 0
  203. # This changes the data layout. Only add new directories. Removing/Updating will cause data loss.
  204. superLargeDirectories = []
  205. [redis_cluster2]
  206. enabled = false
  207. addresses = [
  208. "localhost:30001",
  209. "localhost:30002",
  210. "localhost:30003",
  211. "localhost:30004",
  212. "localhost:30005",
  213. "localhost:30006",
  214. ]
  215. password = ""
  216. # allows reads from slave servers or the master, but all writes still go to the master
  217. readOnly = false
  218. # automatically use the closest Redis server for reads
  219. routeByLatency = false
  220. # This changes the data layout. Only add new directories. Removing/Updating will cause data loss.
  221. superLargeDirectories = []
  222. [etcd]
  223. enabled = false
  224. servers = "localhost:2379"
  225. timeout = "3s"
  226. [mongodb]
  227. enabled = false
  228. uri = "mongodb://localhost:27017"
  229. option_pool_size = 0
  230. database = "seaweedfs"
  231. [elastic7]
  232. enabled = false
  233. servers = [
  234. "http://localhost1:9200",
  235. "http://localhost2:9200",
  236. "http://localhost3:9200",
  237. ]
  238. username = ""
  239. password = ""
  240. sniff_enabled = false
  241. healthcheck_enabled = false
  242. # increase the value is recommend, be sure the value in Elastic is greater or equal here
  243. index.max_result_window = 10000
  244. ##########################
  245. ##########################
  246. # To add path-specific filer store:
  247. #
  248. # 1. Add a name following the store type separated by a dot ".". E.g., cassandra.tmp
  249. # 2. Add a location configuraiton. E.g., location = "/tmp/"
  250. # 3. Copy and customize all other configurations.
  251. # Make sure they are not the same if using the same store type!
  252. # 4. Set enabled to true
  253. #
  254. # The following is just using redis as an example
  255. ##########################
  256. [redis2.tmp]
  257. enabled = false
  258. location = "/tmp/"
  259. address = "localhost:6379"
  260. password = ""
  261. database = 1
  262. `
  263. NOTIFICATION_TOML_EXAMPLE = `
  264. # A sample TOML config file for SeaweedFS filer store
  265. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  266. # Put this file to one of the location, with descending priority
  267. # ./notification.toml
  268. # $HOME/.seaweedfs/notification.toml
  269. # /etc/seaweedfs/notification.toml
  270. ####################################################
  271. # notification
  272. # send and receive filer updates for each file to an external message queue
  273. ####################################################
  274. [notification.log]
  275. # this is only for debugging perpose and does not work with "weed filer.replicate"
  276. enabled = false
  277. [notification.kafka]
  278. enabled = false
  279. hosts = [
  280. "localhost:9092"
  281. ]
  282. topic = "seaweedfs_filer"
  283. offsetFile = "./last.offset"
  284. offsetSaveIntervalSeconds = 10
  285. [notification.aws_sqs]
  286. # experimental, let me know if it works
  287. enabled = false
  288. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  289. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  290. region = "us-east-2"
  291. sqs_queue_name = "my_filer_queue" # an existing queue name
  292. [notification.google_pub_sub]
  293. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  294. enabled = false
  295. google_application_credentials = "/path/to/x.json" # path to json credential file
  296. project_id = "" # an existing project id
  297. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  298. [notification.gocdk_pub_sub]
  299. # The Go Cloud Development Kit (https://gocloud.dev).
  300. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  301. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  302. enabled = false
  303. # This URL will Dial the RabbitMQ server at the URL in the environment
  304. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  305. # The exchange must have already been created by some other means, like
  306. # the RabbitMQ management plugin. Сreate myexchange of type fanout and myqueue then
  307. # create binding myexchange => myqueue
  308. topic_url = "rabbit://myexchange"
  309. sub_url = "rabbit://myqueue"
  310. `
  311. REPLICATION_TOML_EXAMPLE = `
  312. # A sample TOML config file for replicating SeaweedFS filer
  313. # Used with "weed filer.replicate"
  314. # Put this file to one of the location, with descending priority
  315. # ./replication.toml
  316. # $HOME/.seaweedfs/replication.toml
  317. # /etc/seaweedfs/replication.toml
  318. [source.filer]
  319. enabled = true
  320. grpcAddress = "localhost:18888"
  321. # all files under this directory tree are replicated.
  322. # this is not a directory on your hard drive, but on your filer.
  323. # i.e., all files with this "prefix" are sent to notification message queue.
  324. directory = "/buckets"
  325. [sink.local]
  326. enabled = false
  327. directory = "/data"
  328. # all replicated files are under modified time as yyyy-mm-dd directories
  329. # so each date directory contains all new and updated files.
  330. is_incremental = false
  331. [sink.local_incremental]
  332. # all replicated files are under modified time as yyyy-mm-dd directories
  333. # so each date directory contains all new and updated files.
  334. enabled = false
  335. directory = "/backup"
  336. [sink.filer]
  337. enabled = false
  338. grpcAddress = "localhost:18888"
  339. # all replicated files are under this directory tree
  340. # this is not a directory on your hard drive, but on your filer.
  341. # i.e., all received files will be "prefixed" to this directory.
  342. directory = "/backup"
  343. replication = ""
  344. collection = ""
  345. ttlSec = 0
  346. is_incremental = false
  347. [sink.s3]
  348. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  349. # default loads credentials from the shared credentials file (~/.aws/credentials).
  350. enabled = false
  351. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  352. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  353. region = "us-east-2"
  354. bucket = "your_bucket_name" # an existing bucket
  355. directory = "/" # destination directory
  356. endpoint = ""
  357. is_incremental = false
  358. [sink.google_cloud_storage]
  359. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  360. enabled = false
  361. google_application_credentials = "/path/to/x.json" # path to json credential file
  362. bucket = "your_bucket_seaweedfs" # an existing bucket
  363. directory = "/" # destination directory
  364. is_incremental = false
  365. [sink.azure]
  366. # experimental, let me know if it works
  367. enabled = false
  368. account_name = ""
  369. account_key = ""
  370. container = "mycontainer" # an existing container
  371. directory = "/" # destination directory
  372. is_incremental = false
  373. [sink.backblaze]
  374. enabled = false
  375. b2_account_id = ""
  376. b2_master_application_key = ""
  377. bucket = "mybucket" # an existing bucket
  378. directory = "/" # destination directory
  379. is_incremental = false
  380. `
  381. SECURITY_TOML_EXAMPLE = `
  382. # Put this file to one of the location, with descending priority
  383. # ./security.toml
  384. # $HOME/.seaweedfs/security.toml
  385. # /etc/seaweedfs/security.toml
  386. # this file is read by master, volume server, and filer
  387. # the jwt signing key is read by master and volume server.
  388. # a jwt defaults to expire after 10 seconds.
  389. [jwt.signing]
  390. key = ""
  391. expires_after_seconds = 10 # seconds
  392. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  393. [jwt.signing.read]
  394. key = ""
  395. expires_after_seconds = 10 # seconds
  396. # all grpc tls authentications are mutual
  397. # the values for the following ca, cert, and key are paths to the PERM files.
  398. # the host name is not checked, so the PERM files can be shared.
  399. [grpc]
  400. ca = ""
  401. # Set wildcard domain for enable TLS authentication by common names
  402. allowed_wildcard_domain = "" # .mycompany.com
  403. [grpc.volume]
  404. cert = ""
  405. key = ""
  406. allowed_commonNames = "" # comma-separated SSL certificate common names
  407. [grpc.master]
  408. cert = ""
  409. key = ""
  410. allowed_commonNames = "" # comma-separated SSL certificate common names
  411. [grpc.filer]
  412. cert = ""
  413. key = ""
  414. allowed_commonNames = "" # comma-separated SSL certificate common names
  415. [grpc.msg_broker]
  416. cert = ""
  417. key = ""
  418. allowed_commonNames = "" # comma-separated SSL certificate common names
  419. # use this for any place needs a grpc client
  420. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  421. [grpc.client]
  422. cert = ""
  423. key = ""
  424. # volume server https options
  425. # Note: work in progress!
  426. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  427. [https.client]
  428. enabled = true
  429. [https.volume]
  430. cert = ""
  431. key = ""
  432. `
  433. MASTER_TOML_EXAMPLE = `
  434. # Put this file to one of the location, with descending priority
  435. # ./master.toml
  436. # $HOME/.seaweedfs/master.toml
  437. # /etc/seaweedfs/master.toml
  438. # this file is read by master
  439. [master.maintenance]
  440. # periodically run these scripts are the same as running them from 'weed shell'
  441. scripts = """
  442. lock
  443. ec.encode -fullPercent=95 -quietFor=1h
  444. ec.rebuild -force
  445. ec.balance -force
  446. volume.balance -force
  447. volume.fix.replication
  448. unlock
  449. """
  450. sleep_minutes = 17 # sleep minutes between each script execution
  451. [master.filer]
  452. default = "localhost:8888" # used by maintenance scripts if the scripts needs to use fs related commands
  453. [master.sequencer]
  454. type = "raft" # Choose [raft|etcd|snowflake] type for storing the file id sequence
  455. # when sequencer.type = etcd, set listen client urls of etcd cluster that store file id sequence
  456. # example : http://127.0.0.1:2379,http://127.0.0.1:2389
  457. sequencer_etcd_urls = "http://127.0.0.1:2379"
  458. # configurations for tiered cloud storage
  459. # old volumes are transparently moved to cloud for cost efficiency
  460. [storage.backend]
  461. [storage.backend.s3.default]
  462. enabled = false
  463. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  464. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  465. region = "us-east-2"
  466. bucket = "your_bucket_name" # an existing bucket
  467. endpoint = ""
  468. # create this number of logical volumes if no more writable volumes
  469. # count_x means how many copies of data.
  470. # e.g.:
  471. # 000 has only one copy, copy_1
  472. # 010 and 001 has two copies, copy_2
  473. # 011 has only 3 copies, copy_3
  474. [master.volume_growth]
  475. copy_1 = 7 # create 1 x 7 = 7 actual volumes
  476. copy_2 = 6 # create 2 x 6 = 12 actual volumes
  477. copy_3 = 3 # create 3 x 3 = 9 actual volumes
  478. copy_other = 1 # create n x 1 = n actual volumes
  479. # configuration flags for replication
  480. [master.replication]
  481. # any replication counts should be considered minimums. If you specify 010 and
  482. # have 3 different racks, that's still considered writable. Writes will still
  483. # try to replicate to all available volumes. You should only use this option
  484. # if you are doing your own replication or periodic sync of volumes.
  485. treat_replication_as_minimums = false
  486. `
  487. SHELL_TOML_EXAMPLE = `
  488. [cluster]
  489. default = "c1"
  490. [cluster.c1]
  491. master = "localhost:9333" # comma-separated master servers
  492. filer = "localhost:8888" # filer host and port
  493. [cluster.c2]
  494. master = ""
  495. filer = ""
  496. `
  497. )