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.

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