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.

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