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.

491 lines
14 KiB

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