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.

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