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.

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