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.

340 lines
9.4 KiB

6 years ago
6 years ago
6 years ago
6 years ago
6 years ago
6 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. `,
  14. }
  15. var (
  16. outputPath = cmdScaffold.Flag.String("output", "", "if not empty, save the configuration file to this directory")
  17. config = cmdScaffold.Flag.String("config", "filer", "[filer|notification|replication|security|master] the configuration file to generate")
  18. )
  19. func runScaffold(cmd *Command, args []string) bool {
  20. content := ""
  21. switch *config {
  22. case "filer":
  23. content = FILER_TOML_EXAMPLE
  24. case "notification":
  25. content = NOTIFICATION_TOML_EXAMPLE
  26. case "replication":
  27. content = REPLICATION_TOML_EXAMPLE
  28. case "security":
  29. content = SECURITY_TOML_EXAMPLE
  30. case "master":
  31. content = MASTER_TOML_EXAMPLE
  32. }
  33. if content == "" {
  34. println("need a valid -config option")
  35. return false
  36. }
  37. if *outputPath != "" {
  38. ioutil.WriteFile(filepath.Join(*outputPath, *config+".toml"), []byte(content), 0644)
  39. } else {
  40. println(content)
  41. }
  42. return true
  43. }
  44. const (
  45. FILER_TOML_EXAMPLE = `
  46. # A sample TOML config file for SeaweedFS filer store
  47. # Used with "weed filer" or "weed server -filer"
  48. # Put this file to one of the location, with descending priority
  49. # ./filer.toml
  50. # $HOME/.seaweedfs/filer.toml
  51. # /etc/seaweedfs/filer.toml
  52. [memory]
  53. # local in memory, mostly for testing purpose
  54. enabled = false
  55. [leveldb]
  56. # local on disk, mostly for simple single-machine setup, fairly scalable
  57. enabled = false
  58. dir = "." # directory to store level db files
  59. [leveldb2]
  60. # local on disk, mostly for simple single-machine setup, fairly scalable
  61. # faster than previous leveldb, recommended.
  62. enabled = true
  63. dir = "." # directory to store level db files
  64. ####################################################
  65. # multiple filers on shared storage, fairly scalable
  66. ####################################################
  67. [mysql]
  68. # CREATE TABLE IF NOT EXISTS filemeta (
  69. # dirhash BIGINT COMMENT 'first 64 bits of MD5 hash value of directory field',
  70. # name VARCHAR(1000) COMMENT 'directory or file name',
  71. # directory TEXT COMMENT 'full path to parent directory',
  72. # meta LONGBLOB,
  73. # PRIMARY KEY (dirhash, name)
  74. # ) DEFAULT CHARSET=utf8;
  75. enabled = false
  76. hostname = "localhost"
  77. port = 3306
  78. username = "root"
  79. password = ""
  80. database = "" # create or use an existing database
  81. connection_max_idle = 2
  82. connection_max_open = 100
  83. [postgres]
  84. # CREATE TABLE IF NOT EXISTS filemeta (
  85. # dirhash BIGINT,
  86. # name VARCHAR(65535),
  87. # directory VARCHAR(65535),
  88. # meta bytea,
  89. # PRIMARY KEY (dirhash, name)
  90. # );
  91. enabled = false
  92. hostname = "localhost"
  93. port = 5432
  94. username = "postgres"
  95. password = ""
  96. database = "" # create or use an existing database
  97. sslmode = "disable"
  98. connection_max_idle = 100
  99. connection_max_open = 100
  100. [cassandra]
  101. # CREATE TABLE filemeta (
  102. # directory varchar,
  103. # name varchar,
  104. # meta blob,
  105. # PRIMARY KEY (directory, name)
  106. # ) WITH CLUSTERING ORDER BY (name ASC);
  107. enabled = false
  108. keyspace="seaweedfs"
  109. hosts=[
  110. "localhost:9042",
  111. ]
  112. [redis]
  113. enabled = false
  114. address = "localhost:6379"
  115. password = ""
  116. db = 0
  117. [redis_cluster]
  118. enabled = false
  119. addresses = [
  120. "localhost:30001",
  121. "localhost:30002",
  122. "localhost:30003",
  123. "localhost:30004",
  124. "localhost:30005",
  125. "localhost:30006",
  126. ]
  127. password = ""
  128. `
  129. NOTIFICATION_TOML_EXAMPLE = `
  130. # A sample TOML config file for SeaweedFS filer store
  131. # Used by both "weed filer" or "weed server -filer" and "weed filer.replicate"
  132. # Put this file to one of the location, with descending priority
  133. # ./notification.toml
  134. # $HOME/.seaweedfs/notification.toml
  135. # /etc/seaweedfs/notification.toml
  136. ####################################################
  137. # notification
  138. # send and receive filer updates for each file to an external message queue
  139. ####################################################
  140. [notification.log]
  141. # this is only for debugging perpose and does not work with "weed filer.replicate"
  142. enabled = false
  143. [notification.kafka]
  144. enabled = false
  145. hosts = [
  146. "localhost:9092"
  147. ]
  148. topic = "seaweedfs_filer"
  149. offsetFile = "./last.offset"
  150. offsetSaveIntervalSeconds = 10
  151. [notification.aws_sqs]
  152. # experimental, let me know if it works
  153. enabled = false
  154. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  155. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  156. region = "us-east-2"
  157. sqs_queue_name = "my_filer_queue" # an existing queue name
  158. [notification.google_pub_sub]
  159. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  160. enabled = false
  161. google_application_credentials = "/path/to/x.json" # path to json credential file
  162. project_id = "" # an existing project id
  163. topic = "seaweedfs_filer_topic" # a topic, auto created if does not exists
  164. [notification.gocdk_pub_sub]
  165. # The Go Cloud Development Kit (https://gocloud.dev).
  166. # PubSub API (https://godoc.org/gocloud.dev/pubsub).
  167. # Supports AWS SNS/SQS, Azure Service Bus, Google PubSub, NATS and RabbitMQ.
  168. enabled = false
  169. # This URL will Dial the RabbitMQ server at the URL in the environment
  170. # variable RABBIT_SERVER_URL and open the exchange "myexchange".
  171. # The exchange must have already been created by some other means, like
  172. # the RabbitMQ management plugin.
  173. topic_url = "rabbit://myexchange"
  174. sub_url = "rabbit://myqueue"
  175. `
  176. REPLICATION_TOML_EXAMPLE = `
  177. # A sample TOML config file for replicating SeaweedFS filer
  178. # Used with "weed filer.replicate"
  179. # Put this file to one of the location, with descending priority
  180. # ./replication.toml
  181. # $HOME/.seaweedfs/replication.toml
  182. # /etc/seaweedfs/replication.toml
  183. [source.filer]
  184. enabled = true
  185. grpcAddress = "localhost:18888"
  186. # all files under this directory tree are replicated.
  187. # this is not a directory on your hard drive, but on your filer.
  188. # i.e., all files with this "prefix" are sent to notification message queue.
  189. directory = "/buckets"
  190. [sink.filer]
  191. enabled = false
  192. grpcAddress = "localhost:18888"
  193. # all replicated files are under this directory tree
  194. # this is not a directory on your hard drive, but on your filer.
  195. # i.e., all received files will be "prefixed" to this directory.
  196. directory = "/backup"
  197. replication = ""
  198. collection = ""
  199. ttlSec = 0
  200. [sink.s3]
  201. # read credentials doc at https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/sessions.html
  202. # default loads credentials from the shared credentials file (~/.aws/credentials).
  203. enabled = false
  204. aws_access_key_id = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  205. aws_secret_access_key = "" # if empty, loads from the shared credentials file (~/.aws/credentials).
  206. region = "us-east-2"
  207. bucket = "your_bucket_name" # an existing bucket
  208. directory = "/" # destination directory
  209. [sink.google_cloud_storage]
  210. # read credentials doc at https://cloud.google.com/docs/authentication/getting-started
  211. enabled = false
  212. google_application_credentials = "/path/to/x.json" # path to json credential file
  213. bucket = "your_bucket_seaweedfs" # an existing bucket
  214. directory = "/" # destination directory
  215. [sink.azure]
  216. # experimental, let me know if it works
  217. enabled = false
  218. account_name = ""
  219. account_key = ""
  220. container = "mycontainer" # an existing container
  221. directory = "/" # destination directory
  222. [sink.backblaze]
  223. enabled = false
  224. b2_account_id = ""
  225. b2_master_application_key = ""
  226. bucket = "mybucket" # an existing bucket
  227. directory = "/" # destination directory
  228. `
  229. SECURITY_TOML_EXAMPLE = `
  230. # Put this file to one of the location, with descending priority
  231. # ./security.toml
  232. # $HOME/.seaweedfs/security.toml
  233. # /etc/seaweedfs/security.toml
  234. # this file is read by master, volume server, and filer
  235. # the jwt signing key is read by master and volume server.
  236. # a jwt defaults to expire after 10 seconds.
  237. [jwt.signing]
  238. key = ""
  239. expires_after_seconds = 10 # seconds
  240. # jwt for read is only supported with master+volume setup. Filer does not support this mode.
  241. [jwt.signing.read]
  242. key = ""
  243. expires_after_seconds = 10 # seconds
  244. # all grpc tls authentications are mutual
  245. # the values for the following ca, cert, and key are paths to the PERM files.
  246. # the host name is not checked, so the PERM files can be shared.
  247. [grpc]
  248. ca = ""
  249. [grpc.volume]
  250. cert = ""
  251. key = ""
  252. [grpc.master]
  253. cert = ""
  254. key = ""
  255. [grpc.filer]
  256. cert = ""
  257. key = ""
  258. # use this for any place needs a grpc client
  259. # i.e., "weed backup|benchmark|filer.copy|filer.replicate|mount|s3|upload"
  260. [grpc.client]
  261. cert = ""
  262. key = ""
  263. # volume server https options
  264. # Note: work in progress!
  265. # this does not work with other clients, e.g., "weed filer|mount" etc, yet.
  266. [https.client]
  267. enabled = true
  268. [https.volume]
  269. cert = ""
  270. key = ""
  271. `
  272. MASTER_TOML_EXAMPLE = `
  273. # Put this file to one of the location, with descending priority
  274. # ./master.toml
  275. # $HOME/.seaweedfs/master.toml
  276. # /etc/seaweedfs/master.toml
  277. # this file is read by master
  278. [master.maintenance]
  279. # periodically run these scripts are the same as running them from 'weed shell'
  280. scripts = """
  281. ec.encode -fullPercent=95 -quietFor=1h
  282. ec.rebuild -force
  283. ec.balance -force
  284. volume.balance -force
  285. """
  286. sleep_minutes = 17 # sleep minutes between each script execution
  287. `
  288. )