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.

556 lines
16 KiB

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