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.

458 lines
13 KiB

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