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.

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