概述
seaweedfs是一个分布式的文件系统。
下面这段引用是官方github主页对其总的介绍
SeaweedFS is a simple and highly scalable distributed file system to store and serve billions of files fast! SeaweedFS object store has O(1) disk seek, transparent cloud integration, and SeaweedFS Filer supports Kubernetes, POSIX, S3 API, encryption, Erasure Coding for warm storage, FUSE mount, Hadoop, WebDAV.
seaweedfs支持集群模式,通过raft协议来保证数据的强一致性。
利用 docker启动一个seaweedfs集群
为了快速看到效果, 用docker在单机上启动一个集群看看
# pull weed镜像 docker pull chrislusf/seaweedfs:1.85 # 创建docker volume docker volume create weed-master docker volume create weed-volume1 docker volume create weed-volume2 # 启动master server, 两个volume server docker run -p 9333:9333 --name weed-master -v weed-master:/data -d chrislusf/seaweedfs:1.85 master docker run -p 8081:8080 --name weed-volume1 -v weed-volume1:/data \ --link weed-master:weed-master -d chrislusf/seaweedfs:1.85 \ volume -fileSizeLimitMB=128 -mserver="weed-master:9333" -port=8080 docker run -p 8082:8080 --name weed-volume2 -v weed-volume2:/data \ --link weed-master:weed-master -d chrislusf/seaweedfs:1.85 \ volume -fileSizeLimitMB=128 -mserver="weed-master:9333" -port=8080
其中-fileSizeLimitMB=128选项指定了上传文件时最大不能超过128M
http接口使用
为了方便演示, 建立了两个文件,大小分别为12字节和129M
root@gl-test: ~ # ls -l [13:44:16] total 6148 -rw-r--r-- 1 root root 12 Jul 18 13:40 a.txt -rw-r--r-- 1 root root Jul 18 13:43 largefile
- 直接上传
root@gl-test: ~ # curl -F file=@./a.txt http://localhost:9333/submit { "eTag":"28b81996","fid":"5,09dff3964d","fileName":"a.txt","fileUrl":"172.17.0.3:8080/5,09dff3964d","size":12}# - 先分配fileId再上传
root@gl-test: ~ # curl http://localhost:9333/dir/assign { "fid":"7,0b93c620ad","url":"172.17.0.4:8080","publicUrl":"172.17.0.4:8080","count":1}# # 直接用上面返回的url来作为上传地址 root@gl-test: ~ # curl -F file=@./a.txt http://172.17.0.4:8080/7,0b93c620ad { "name":"a.txt","size":12,"eTag":"f0ff7292","mime":"text/plain"}# - 查找
root@gl-test: ~ # curl http://localhost:9333/dir/lookup\?fileId\=7,0b93c620ad { "volumeId":"7","locations":[{ "url":"172.17.0.4:8080","publicUrl":"172.17.0.4:8080"}]}#可以找出某个fileId对应的文件在哪个volume server上(返回的url, publicUrl根据情况使用)
- 下载
root@gl-test: ~ # curl -i http://172.17.0.4:8080/7,0b93c620ad [13:56:27] HTTP/1.1 200 OK Accept-Ranges: bytes Content-Disposition: inline; filename="a.txt" Content-Length: 12 Content-Type: text/plain Etag: "f0ff7292" Last-Modified: Sat, 18 Jul 2020 05:48:04 GMT Date: Sat, 18 Jul 2020 05:56:30 GMT hello world注意:
- 下载地址可通过lookup的url 或者 publicUrl来指定
- 返回的Header中有
Content-Disposition: inline; filename="a.txt"; inline是说尽可能直接显示
比如这个请求,在浏览器中的话会直接显示文件内容。
如果无法直接显示(比如zip文件), 才会下载, 参考https://stackoverflow.com/questions//content-dispositionwhat-are-the-differences-between-inline-and-attachment。
总结
参考
- https://stackoverflow.com/questions//content-dispositionwhat-are-the-differences-between-inline-and-attachment
- https://github.com/chrislusf/seaweedfs/wiki
(完)
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/221004.html原文链接:https://javaforall.net
