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.

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