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.

479 lines
14 KiB

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