exchange readme language

This commit is contained in:
s_jqzhang 2019-04-26 11:13:31 +08:00
parent 1ab9189bb3
commit 5198757124
2 changed files with 688 additions and 487 deletions

View File

@ -1,97 +1,100 @@
# [中文](README.md) [English](README-en.md)
# [中文](README-en.md) [English](README.md)
![logo](doc/logo.png) ![logo](doc/logo.png)
# go-fastdfs is a distributed file system based on http protocol. It is based on the design concept of avenue to simple. All the simple design makes its operation and expansion more simple. It has high performance, high reliability and no center. , maintenance-free and so on. # go-fastdfs是一个基于http协议的分布式文件系统它基于大道至简的设计理念一切从简设计使得它的运维及扩展变得更加简单它具有高性能、高可靠、无中心、免维护等优点。
### Everyone is worried about such a simple file system. Is it not reliable, can it be used in a production environment? The answer is yes, it is efficient because it is simple, and it is stable because it is simple. If you are worried about the function, then run the unit test, if you are worried about the performance, then run the stress test, the project comes with it, run more confident ^_^. ### 大家担心的是这么简单的文件系统,靠不靠谱,可不可以用于生产环境?答案是肯定的,正因为简单所以高效,因为简单所以稳定。如果你担心功能,那就跑单元测试,如果担心性能,那就跑压力测试,项目都自带了,跑一跑更放心^_^。
Note: Please read this article carefully before use, especially [QA](#qa) 注意:使用前请认真阅读完本文,特别是[wiki](https://github.com/sjqzhang/go-fastdfs/wiki)
- Support curl command upload - 支持curl命令上传
- Support browser upload - 支持浏览器上传
- Support HTTP download - 支持HTTP下载
- Support multi-machine automatic synchronization - 支持多机自动同步
- Support breakpoint download - 支持断点下载
- Support configuration automatic generation - 支持配置自动生成
- Support small file automatic merge (reduce inode occupancy) - 支持小文件自动合并(减少inode占用)
- Support for second pass - 支持秒传
- Support for cross-domain access - 支持跨域访问
- Support one-click migration - 支持一键迁移
- Support for parallel experience - 支持并行体验
- Support for breakpoint resuming ([tus](https://tus.io/)) - 支持断点续传([tus](https://tus.io/))
- Support for docker deployment - 支持docker部署
- Support self-monitoring alarm - 支持自监控告警
- Support image zoom - 支持图片缩放
- Support google authentication code - 支持google认证码
- Support for custom authentication - 支持自定义认证
- Support cluster file information viewing - 支持集群文件信息查看
- Use the universal HTTP protocol - 使用通用HTTP协议
- No need for a dedicated client (support wget, curl, etc.) - 无需专用客户端支持wget,curl等工具
- class fastdfs - fastdfs
- High performance (using leveldb as a kv library) - 高性能 使用leveldb作为kv库
- High reliability (design is extremely simple, using mature components) - 高可靠(设计极其简单,使用成熟组件)
- No center design (all nodes can read and write at the same time) - 无中心设计(所有节点都可以同时读写)
# advantage # 优点
- No dependencies (single file) - 无依赖(单一文件)
- Automatic synchronization - 自动同步
- Failure automatic repair - 失败自动修复
- Convenient maintenance by talent directory - 按天分目录方便维护
- Support different scenarios - 支持不同的场景
- Automatic file deduplication - 文件自动去重
- Support for directory customization - 支持目录自定义
- Support to retain the original file name - 支持保留原文件名
- Support for automatic generation of unique file names - 支持自动生成唯一文件名
- Support browser upload - 支持浏览器上传
- Support for viewing cluster file information - 支持查看集群文件信息
- Support cluster monitoring email alarm - 支持集群监控邮件告警
- Support small file automatic merge (reduce inode occupancy) - 支持小文件自动合并(减少inode占用)
- Support for second pass - 支持秒传
- Support image zoom - 支持图片缩放
- Support google authentication code - 支持google认证码
- Support for custom authentication - 支持自定义认证
- Support for cross-domain access - 支持跨域访问
- Very low resource overhead - 极低资源开销
- Support for breakpoint resuming ([tus](https://tus.io/)) - 支持断点续传([tus](https://tus.io/))
- Support for docker deployment - 支持docker部署
- Support for one-click migration (migrated from other system file systems) - 支持一键迁移(从其他系统文件系统迁移过来)
- Support for parallel experience (parallel experience with existing file system, confirm OK and then one-click migration) - 支持并行体验与现有的文件系统并行体验确认OK再一键迁移
- Support token download token=md5(file_md5+timestamp) - 支持token下载 token=md5(file_md5+timestamp)
- Easy operation and maintenance, only one role (unlike fastdfs has three roles Tracker Server, Storage Server, Client), the configuration is automatically generated - 运维简单只有一个角色不像fastdfs有三个角色Tracker Server,Storage Server,Client配置自动生成
- Peer-to-peer (simplified operation and maintenance) - 每个节点对等(简化运维)
- All nodes can read and write simultaneously - 所有节点都可以同时读写
#Start the server (compiled, [download](https://github.com/sjqzhang/fastdfs/releases) experience) # 启动服务器(已编译,[下载](https://github.com/sjqzhang/fastdfs/releases)极速体验,只需一分钟)
``` 一键安装请将以下命令复制到linux console中执行
./fileserver ```shell
wget --no-check-certificate https://github.com/sjqzhang/go-fastdfs/releases/download/v1.2.6/fileserver -O fileserver && chmod +x fileserver && ./fileserver
``` ```
(注意下载时要注意链接的版本号windows下直接运行fileserver.exe执行文件在这里[下载](https://github.com/sjqzhang/fastdfs/releases))
# 命令上传
#Command upload
`curl -F file=@http-index-fs http://10.1.xx.60:8080/upload` `curl -F file=@http-index-fs http://10.1.xx.60:8080/upload`
# WEB upload (browser open) # WEB上传(浏览器打开)
`http://127.0.0.1:8080` `http://yourserver ip:8080/upload.html` 注意不要使用127.0.0.1上传
#Code upload (options see browser upload) # 代码上传(选项参阅浏览器上传)
## python
## python版本:
```python ```python
import requests import requests
url = 'http://127.0.0.1:8080/upload' url = 'http://10.1.5.9:8080/upload'
files = {'file': open('report.xls', 'rb')} files = {'file': open('report.xls', 'rb')}
options={'output':'json','path':'','scene':''} #See browser upload options options={'output':'json','path':'','scene':''} #参阅浏览器上传的选项
r = requests.post(url, files=files) r = requests.post(url,data=options, files=files)
print(r.text) print(r.text)
``` ```
## golang ## golang版本
```go ```go
package main package main
@ -103,17 +106,16 @@ import (
func main() { func main() {
var obj interface{} var obj interface{}
req:=httplib.Post("http://10.1.5.9:8080/upload") req:=httplib.Post("http://10.1.5.9:8080/upload")
req.PostFile("file","path/to/file") req.PostFile("file","filename")//注意不是全路径
req.Param("output","json") req.Param("output","json")
req.Param("scene","") req.Param("scene","")
req.Param("path","") req.Param("path","")
req.ToJSON(&obj) req.ToJSON(&obj)
fmt.Print(obj) fmt.Print(obj)
} }
```` ```
## java版本
## java 依赖(这里使用了hutool工具包,更简便)
```xml ```xml
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
@ -121,22 +123,32 @@ func main() {
<version>4.4.3</version> <version>4.4.3</version>
</dependency> </dependency>
``` ```
上传代码
```java ```java
public static void main(String[] args) { public static void main(String[] args) {
//文件地址
File file = new File("D:\\git\\2.jpg"); File file = new File("D:\\git\\2.jpg");
//声明参数集合
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
//文件
paramMap.put("file", file); paramMap.put("file", file);
//输出
paramMap.put("output","json"); paramMap.put("output","json");
//自定义路径
paramMap.put("path","image"); paramMap.put("path","image");
//场景
paramMap.put("scene","image"); paramMap.put("scene","image");
//上传
String result= HttpUtil.post("http://xxxxx:xxxx/upload", paramMap); String result= HttpUtil.post("http://xxxxx:xxxx/upload", paramMap);
//输出json结果
System.out.println(result); System.out.println(result);
} }
``` ```
[更多语言请参考](doc/upload.md)
# Breakpoint resume example # 断点续传示例
## golang
## golang版本
```go ```go
package main package main
@ -165,149 +177,364 @@ func main() {
fmt.Println( uploader.Upload()) fmt.Println( uploader.Upload())
} }
```` ````
[more langue](doc/upload.md) [更多客户端请参考](https://github.com/tus)
![deploy](doc/go-fastdfs-deploy.png)
Universal file authentication timing diagram
![Universal file authentication timing diagram](doc/authentication2.png)
File google authentication timing diagram
![File google authentication timing diagram](doc/authentication.png)
# Please click [Feedback](https://github.com/sjqzhang/go-fastdfs/issues/new)
# Q&A
- Best practice? 部署图
![部署图](doc/go-fastdfs-deploy.png)
通用文件认证时序图
![通用文件认证时序图](doc/authentication2.png)
文件google认证时序图
![文件认证时序图](doc/authentication.png)
# 有问题请[点击反馈](https://github.com/sjqzhang/go-fastdfs/issues/new)
# 重要说明
## 在issue中有很多实际使用的问题及回答很多已关闭请查看已关闭的issue
## 项目从v1.1.8开始进入稳定状态
# 更新说明
## 从低版升给到高版本可能存在配置项变动的情况一定要注意使用新的版本时的配置项。如何获得新版本的配置项及说明先备份旧的配置项文件名不能为cfg.json再运行新的版本配置项就自动生成。然后再修改相应的配置项。
- v1.1.9 增加文件自动迁移功能,支持同名文件重复覆盖选项。
# <span id="qa">Q&A</span>
- 最佳实战?
``` ```
First, if it is mass storage, do not open the file token authentication function to reduce performance. 一、如果是海量存储不要开启文件token认证功能减少性能开消。
Second, try to use the standard upload, upload the business to save the path, and then connect the domain name when the business is used (convenient migration extension, etc.). 二、尽量用标准上传上传后业务保存path在业务用的时候再并接上域名方便迁移扩展等
Third, if you use breakpoints to continue transmission, you must use the file id to replace the path storage after uploading (how to replace the QA/API document), to reduce performance for subsequent access. 三、如果使用断点续传上传后一定要用文件id置换成path存储如何置换看/API文档为后面访问减少性能开消。
Fourth, try to use physical server deployment, because the main pressure or performance comes from IO 四、尽量使用物理服务器部署,因为主要压力或性能来自于IO
Fifth, the online business should use the nginx+gofastdfs deployment architecture (the equalization algorithm uses ip_hash) to meet the later functional scalability (nginx+lua). 五、线上业务尽量使用nginx+gofastdfs部署架构(均衡算法使用ip_hash),以满足后面的功能扩展性(nginx+lua)。
Sixth, the online environment is best not to use container deployment, the container is suitable for testing and functional verification. 六、线上环境最好不要使用容器部署,容器适用于测试和功能验证。
Summary: The path of the file saved by the business reduces the conversion of the later access path, and the file access permission is completed by the service, so that the performance is the best and the versatility is strong (can be directly connected to other web servers). 总结业务保存的文件的path,减少后期访问路径转换带来开消,文件访问权限由业务来完成这样性能最好通用性强可直接其它web服务器
Important reminder: If the small file merge function is enabled, it is impossible to delete small files later. 重要提醒:如果开启小文件合并功能,后期是无法删除小文件的。
Upload result description 上传结果说明
Please use md5, path, scene field, others are added to be compatible with the old online system, and may be removed in the future. 请使用md5,path,scene字段其它是为了兼容老的线上系统添加的以后有可能去掉。
``` ```
- In the WeChat discussion group, everyone asked about the performance of go-fastdfs?
- 有API文档么
[API文档](doc/api.md)
- 有管理后台么?
``` ```
Because there are too many people asking, answer here in unison. https://github.com/perfree/go-fastdfs-web
The file location of de-fastdfs is different from other distributed systems. Its addressing is directly located without any components, so the approximate time complexity is O(1)[file path location] ```
There is basically no performance loss. The project also has a pressure test script. You can carry out the pressure test yourself. Dont discuss the problem too much in the group. People reply to the same question every time. - 断点上传有使用说明么?
Everyone will also feel that this group is boring. ```
https://github.com/tus
```
- 在微信讨论群中大家都问到go-fastdfs性能怎样
```
由于问的人太多,在这里统一回答。
go-fastdfs的文件定位与其它分布式系统不同它的寻址是直接定位不经过任何组件所以可以近似时间复杂度为o(1)[文件路径定位]
基本没有性能损耗,项目中也附有压测脚本,大家可以自已进行压测,群里就不要太多讨论问题了,人多每次回复同样的问题
大家也会觉得这群无聊。
``` ```
- Can files already stored using fastdfs be migrated to go fastdfs? - 已经使用fastdfs存储的文件可以迁移到go fastdfs下么其它迁移情况可按类似的方式处理极速体验也用类似的方式
``` ```
The answer is yes, the problem you are worried about is the path change, go fastdfs considers this for you. 答案是可以的,你担心的问题是路径改变,go fastdfs为你考虑了这一点
步骤:
一、下载最新版的go-fastdfs
二、将原来的fastdfs文件目录复制到go-fastdfs的 files目录下(如果文件很多可以逆向过来将fileserver复制过去但要保留fileserver的目录结构
三、将配置enable_migrate设为true
注意迁移过程中会扫描整下files目录下的所有文件
速度较慢迁移完成后请将enable_migrate设为false
Curl -F file =@data/00/00/_78HAFwyvN2AK6ChAAHg8gw80FQ213.jpg -F path = M00 / 00/00 / http://127.0.0.1:8080/upload 说明go-fastdfs的目录是不能变动的与同步机制相关很多同学在群里问题我的files目录能不能自定义答案是否定的。
至于能不能用软链接的方式本人没有测试过,可以自行测试。
Similarly, all files can be migrated with one line of command.
Cd fastdfs / data && find -type f | xargs -n 1 -I {} curl -F file = @ data / {} -F path = M00 / 00/00 / http://127.0.0.1:8080/
The above commands can be moved rough
Can write some simple scripts for migration
``` ```
- What is a cluster, how to manage multiple clusters with Nginx? - 什么是集群如何用Nginx管理多集群
``` ```
1, in the go-fastdfs, a cluster is a group. 1、在go-fastdfs中一个集群就是一个group。
2, please refer to the deployment diagram 2、请参阅部署图
Note: When the support_group_manage parameter in the configuration is set to true, group information is automatically added to all urls. 注意:配置中的 support_group_manage 参数设为true时所有的url中都自动添加组信息。
For example: HTTP://10.1.5.9:8080/group/status 例如http://10.1.5.9:8080/group/status
Default: HTTP://10.1.5.9:8080/status 默认http://10.1.5.9:8080/status
The difference: more group, corresponding to the group parameter in the configuration, so mainly to solve a Nginx reverse proxy multiple groups (cluster) 区别多了group,对应配置中的 group 参数,这样主要是为了解决一个Nginx反向代理多个group(集群)
Please refer to the deployment diagram for details. 具体请参阅部署图
``` ```
- How to build a cluster? - 如何搭建集群?
``` ```
First, download the compiled executable file (with the latest version) 一、先下载已编译的可执行文件(用最新版本)
Second, run the executable file (generate configuration) 二、运行可执行文件(生成配置)
Third, modify the configuration 三、修改配置
Peer: increase the peer's HTTP address peers增加对端的http地址
an examination: 检查:
Moderator: Is the automatic generation correct? host:自动生成是否正确
Peer_id: Is it unique within the cluster? peer_id:集群内是否唯一
Fourth, re-run the server 四、重新运行服器
Five, verify that the service is OK 五、验证服务是否OK
``` ```
- Is it suitable for mass storage? - 适合海量存储吗?
``` ```
Answer: Suitable for mass storage 答案:适合海量存储
Special Note: ```
Need to use LevelDB as metadata storage, but not relying on lazy LevelDB,
And carry out more than 100 million documents for pressure measurement (you can use the script provided by the project to perform pressure measurement, and have problems and feedback to the problem in time). - 如何上传文件夹?
100 million file metadata size is about 5G, export metadata text size 22G ```
DIR=log && ls $DIR |xargs -n 1 -I {} curl -s -F path=$DIR -F file=@$DIR/{} http://10.1.50.90:8080/upload
上面命令的log为要上传的目录如果代码上传就是简单的循环上传就
```
- 如何缩放图片?
```
在下载url中加入width各height参数
例如http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0&width=100&height=100
特明说明是如果要等比例缩放请将width或height设为
```
- 如何在浏览器中直接显示图片?
```
在下载url中加入download=0参数
例如http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0
```
- 如何实现自定义认证上传下载?
```
一、使用1.2.6版本以后的go-fastdfs
二、设auth_url参数应用提供
三、应用实现验证权限接口即第二步的url,参数为 auth_toke 返回 ok 表示认证通过,其它为不通过
四、认证通过后,可以上传或下载
```
- 还需要安装nginx么
```
go-fastdfs本身是一个高性能的web服务器在开发或测试时可以不用安装nginx
但go-fastdfs的功能单一如需要缓存或重定向或其它扩展nginx都有成熟的组件
所以建议线上还是加一层nginx再借助nginx+lua解决扩展性问题。
```
- 能动态加载配置么?
```
答案:是可以的,但要更新到最新版本
步骤:
1修改 conf/cfg.json 文件
2访问 http://10.1.xx.60:8080/reload
3 注意:每个节点都需要进行同样的操作
```
- 如何查看集群文件信息?
```
http://10.1.xx.60:8080/stat
如果出现文件统计出错怎么办?
请删除 data目录下的 stat.json文件 重启服务,请系统自动重新计算文件数。
或者调用
http://10.1.xx.60:8080/repair_stat
```
- 可靠性怎样,能用于生产环境么?
```
本项目已大规模用于生产环境,如担心不能满足
可以在使用前对其各项特性进行压力测试,有任何
问题可以直接提issue
```
- 如何后台运行程序?
```
请使用control 对程序进行后面运行,具体操作如下:
一、 chmod +x control
二、 确保control与fileserver在同一个目录
三、 ./control start|stop|status #对和序进行启动,停止,查看状态等。
```
- 能不能在一台机器部置多个服务端?
```
不能在设计之初就已考虑到集群的高可用问题为了保证集群的真正可用必须为不同的ip,ip 不能用 127.0.0.1
错误 "peers": ["http://127.0.0.1:8080","http://127.0.0.1:8081","http://127.0.0.1:8082"]
正确 "peers": ["http://10.0.0.3:8080","http://10.0.0.4:8080","http://10.0.0.5:8080"]
```
- 文件不同步了怎么办?
```
正常情况下,集群会每小时自动同步修复文件。(性能较差,在海量情况下建议关闭自动修复)
那异常情况下怎么?
答案:手动同步(最好在低峰执行)
http://172.16.70.123:7080/sync?date=20190117&force=1 (说明:要在文件多的服务器上执行,相关于推送到别的服务器)
参数说明date 表示同步那一天的数据 force 1.表示是否强制同步当天所有(性能差)0.表示只同步失败的文件
不同步的情况:
1) 原来运行N台现在突然加入一台变成N+1台
2原来运行N台某一台机器出现问题变成N-1台
如果出现多天数据不一致怎么办?能一次同步所有吗?
答案是可以:(最好在低峰执行)
http://172.16.70.123:7080/repair?force=1
```
- 文件不同步会影响访问吗?
```
答案:不会影响,会在访问不到时,自动修复不同步的文件。
```
- 如何查看系统状态及说明?
```
http://172.16.70.123:7080/status
注意:Fs.Peers是不带本机的如果带有可能出问题
本机为 Fs.Local
sts["Fs.ErrorSetSize"] = this.errorset.Cardinality() 这个会导致内存增加
```
- 如何编译(go1.9.2+)
```
git clone https://github.com/sjqzhang/go-fastdfs.git
cd go-fastdfs
mv vendor src
pwd=`pwd`
GOPATH=$pwd go build -o fileserver fileserver.go
```
- 如何跑单元测试 (尽量在linux下进行)
```
git clone https://github.com/sjqzhang/go-fastdfs.git
cd go-fastdfs
mv vendor src
pwd=`pwd`
GOPATH=$pwd go test -v fileserver.go fileserver_test.go
``` ```
- Need to install nginx yet? - 如何压测?
``` ```
Can not be installed, you can also choose to install 步骤:
Go fastdfs itself is a high performance web file server. 一、创建files文件夹
二、将gen_file.py复制到files文件夹中通过python gen_file.py 生成大量文件
三、将benchmark.py放到 files目录外即与files目录同一级通过python benchmark.py进行压测注意对benchmark.py中的ip进行修改
先用gen_file.py产生大量文件注意如果要生成大文件自已在内容中乘上一个大的数即可
例如:
# -*- coding: utf-8 -*-
import os
j=0
for i in range(0,1000000):
if i%1000==0:
j=i
os.system('mkdir %s'%(i))
with open('%s/%s.txt'%(j,i),'w+') as f:
f.write(str(i)*1024)
接着用benchmark.py进行压测
也可以多机同时进行压测,所有节点都是可以同时读写的
``` ```
- Can I dynamically load the configuration? - 代码为什么写在一个文件中?
``` ```
Answer: Yes, but update to the latest version 一、目前的代码还非常简单,没必要弄得太复杂。
step: 二、个人理解模块化不是分开多个文件就表示模块化大家可以用IDE去看一下代码结构其实是已经模块化的。
1) Modify the conf / cfg.json file
2) Visit http://10.1.xx.60:8080 / reload
3) Note: each node needs to do the same operation
``` ```
- 支持断点下载?
- What is the memory usage high?
``` ```
Under normal circumstances, the memory should be lower than 2G, unless more than one million files are uploaded every day. 答案:支持
The memory is abnormal, mainly because the files of the cluster are not synchronized, and the automatic repair function is enabled. curl wget 如何
Solution, delete the errors.md5 file on the day of the data directory, close the automatic repair, restart the service wget -c http://10.1.5.9:8080/group1/default/20190128/16/10/2G
See system status description culr -C - http://10.1.5.9:8080/group1/default/20190128/16/10/2G
```
- Docker如何部署
```
步骤:
方式一、
一、构建镜像
docker build . -t fastdfs
二、运行容器(使用环境变量 GO_FASTDFS_DIR 指向存储目录。)
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
方式二、
一、拉取镜像
docker pull sjqzhang/go-fastdfs
二、运行容器
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
``` ```
- How to view cluster file information? - 大文件如何分块上传或断点续传?
``` ```
HTTP://10.1.xx.60:8080/stat 一般的分块上传都要客户端支持,而语言的多样性,客户端难以维护,但分块上传的功能又有必要,为此提供一个简单的实现思路。
方案一、
What should I do if there is a file error? 借助linux split cat 实现分割与合并,具体查看 split 与 cat 帮助。
Please delete the stat.json file in the data directory to restart the service. Please recalculate the number of files automatically. 分割: split -b 1M filename #按每个文1M
合并: cat x* > filename #合并
Or call 方案二、
HTTP://10.1.xx.60:8080/repair_stat 借助hjsplit
http://www.hjsplit.org/
``` 具体自行实现
- How reliable can it be used in a production environment? 方案三、
``` 建议用go实现hjsplit分割合并功这样具有跨平台功能。未实现等你来....
This project has been used on a large scale in the production environment, such as fear of not meeting 方案四、
You can stress test its features before use, any 使用内置的继点续传功能使用protocol for resumable uploads协议[详情](https://tus.io/)
The problem can directly ask the question 注意方案四、只能指定一个上传服务器不支持同时写并且上传的url有变化
原上传url http://10.1.5.9:8080/<group>/upload
断点上传url http://10.1.5.9:8080/<group>/big/upload/
上传完成,再通过秒传接口,获取文件信息
``` ```
- Can I have multiple servers on one machine? - 如何秒传文件?
``` ```
No, the high availability of the cluster has been considered at the beginning of the design. In order to ensure the true availability of the cluster, it must be different for ip, ip cannot use 127.0.0.1. 通过http get的方式访问上传接口
Error "peer": ["http://127.0.0.1:8080","http:// 127.0.0.1:8081","http:// 12.7.0.0.1:8082"] http://10.0.5.9:8080/upload?md5=filesum&output=json
Correct "peer": ["http://10.0.0.3:8080","http://10.0.0.4:8080","http://10.0.0.:8080"] 参数说明:
md5=sum(file) 文件的摘要算法要与文件务器的算法一致算法支持md5|sha1如果是断点续传可以使用文件的id也就是urlolad后的id
output=json|text 返回的格式
- If you have any questions, please click [Reply](https://github.com/sjqzhang/go-fastdfs/issues/new) ```
![wechat](doc/wechat.jpg) - 集群如何规划及如何进行扩容?
```
建议在前期规划时,尽量采购大容量的机器作为存储服务器,如果要两个副本就用两台组成一个集群,如果要三个副本
就三台组成一个集群。注意每台服务器最好配置保持一样并且使用raid5磁盘阵列
如果提高可用性只要在现在的集群peers中加入新的机器再对集群进行修复即可。
修复办法 http://172.16.70.123:7080/repair?force=1 (建议低峰变更)
如何扩容?
为简单可靠起见,直接搭建一个新集群即可(搭建就是启动./fileserver进程设置一下peers的IP地址三五分钟的事
issue中chengyuansen同学向我提议使用增加扩容特性我觉得对代码逻辑及运维都增加复杂度暂时没有加入这特性。
```
- 访问限制问题
```
出于安全考虑,管理API只能在群集内部调用或者用127.0.0.1调用.
```
- 有问题请[点击反馈](https://github.com/sjqzhang/go-fastdfs/issues/new)
## 有问题请加群
![二维码](doc/wechat.jpg)
#### 进群请改昵称,昵称格式:城市-公司-昵称,如果你喜欢这项目,请关注(star)此项目,关注是对项目的肯定,也是作者创新的动力。
#### [捐赠](doc/pay.png)

588
README.md
View File

@ -1,100 +1,97 @@
# [中文](README-en.md) [English](README.md)
# [中文](README.md) [English](README-en.md)
![logo](doc/logo.png) ![logo](doc/logo.png)
# go-fastdfs是一个基于http协议的分布式文件系统它基于大道至简的设计理念一切从简设计使得它的运维及扩展变得更加简单它具有高性能、高可靠、无中心、免维护等优点。 # go-fastdfs is a distributed file system based on http protocol. It is based on the design concept of avenue to simple. All the simple design makes its operation and expansion more simple. It has high performance, high reliability and no center. , maintenance-free and so on.
### 大家担心的是这么简单的文件系统,靠不靠谱,可不可以用于生产环境?答案是肯定的,正因为简单所以高效,因为简单所以稳定。如果你担心功能,那就跑单元测试,如果担心性能,那就跑压力测试,项目都自带了,跑一跑更放心^_^。 ### Everyone is worried about such a simple file system. Is it not reliable, can it be used in a production environment? The answer is yes, it is efficient because it is simple, and it is stable because it is simple. If you are worried about the function, then run the unit test, if you are worried about the performance, then run the stress test, the project comes with it, run more confident ^_^.
注意:使用前请认真阅读完本文,特别是[wiki](https://github.com/sjqzhang/go-fastdfs/wiki) Note: Please read this article carefully before using it, especially [wiki](https://github.com/sjqzhang/go-fastdfs/wiki)
- 支持curl命令上传 - Support curl command upload
- 支持浏览器上传 - Support browser upload
- 支持HTTP下载 - Support HTTP download
- 支持多机自动同步 - Support multi-machine automatic synchronization
- 支持断点下载 - Support breakpoint download
- 支持配置自动生成 - Support configuration automatic generation
- 支持小文件自动合并(减少inode占用) - Support small file automatic merge (reduce inode occupancy)
- 支持秒传 - Support for second pass
- 支持跨域访问 - Support for cross-domain access
- 支持一键迁移 - Support one-click migration
- 支持并行体验 - Support for parallel experience
- 支持断点续传([tus](https://tus.io/)) - Support for breakpoint resuming ([tus](https://tus.io/))
- 支持docker部署 - Support for docker deployment
- 支持自监控告警 - Support self-monitoring alarm
- 支持图片缩放 - Support image zoom
- 支持google认证码 - Support google authentication code
- 支持自定义认证 - Support for custom authentication
- 支持集群文件信息查看 - Support cluster file information viewing
- 使用通用HTTP协议 - Use the universal HTTP protocol
- 无需专用客户端支持wget,curl等工具 - No need for a dedicated client (support wget, curl, etc.)
- fastdfs - class fastdfs
- 高性能 使用leveldb作为kv库 - High performance (using leveldb as a kv library)
- 高可靠(设计极其简单,使用成熟组件) - High reliability (design is extremely simple, using mature components)
- 无中心设计(所有节点都可以同时读写) - No center design (all nodes can read and write at the same time)
# 优点 # advantage
- 无依赖(单一文件) - No dependencies (single file)
- 自动同步 - Automatic synchronization
- 失败自动修复 - Failure automatic repair
- 按天分目录方便维护 - Convenient maintenance by talent directory
- 支持不同的场景 - Support different scenarios
- 文件自动去重 - Automatic file deduplication
- 支持目录自定义 - Support for directory customization
- 支持保留原文件名 - Support to retain the original file name
- 支持自动生成唯一文件名 - Support for automatic generation of unique file names
- 支持浏览器上传 - Support browser upload
- 支持查看集群文件信息 - Support for viewing cluster file information
- 支持集群监控邮件告警 - Support cluster monitoring email alarm
- 支持小文件自动合并(减少inode占用) - Support small file automatic merge (reduce inode occupancy)
- 支持秒传 - Support for second pass
- 支持图片缩放 - Support image zoom
- 支持google认证码 - Support google authentication code
- 支持自定义认证 - Support for custom authentication
- 支持跨域访问 - Support for cross-domain access
- 极低资源开销 - Very low resource overhead
- 支持断点续传([tus](https://tus.io/)) - Support for breakpoint resuming ([tus](https://tus.io/))
- 支持docker部署 - Support for docker deployment
- 支持一键迁移(从其他系统文件系统迁移过来) - Support for one-click migration (migrated from other system file systems)
- 支持并行体验与现有的文件系统并行体验确认OK再一键迁移 - Support for parallel experience (parallel experience with existing file system, confirm OK and then one-click migration)
- 支持token下载 token=md5(file_md5+timestamp) - Support token download token=md5(file_md5+timestamp)
- 运维简单只有一个角色不像fastdfs有三个角色Tracker Server,Storage Server,Client配置自动生成 - Easy operation and maintenance, only one role (unlike fastdfs has three roles Tracker Server, Storage Server, Client), the configuration is automatically generated
- 每个节点对等(简化运维) - Peer-to-peer (simplified operation and maintenance)
- 所有节点都可以同时读写 - All nodes can read and write simultaneously
# 启动服务器(已编译,[下载](https://github.com/sjqzhang/fastdfs/releases)极速体验,只需一分钟) #Start the server (compiled, [download](https://github.com/sjqzhang/fastdfs/releases) experience)
一键安装请将以下命令复制到linux console中执行 ```
```shell ./fileserver
wget --no-check-certificate https://github.com/sjqzhang/go-fastdfs/releases/download/v1.2.6/fileserver -O fileserver && chmod +x fileserver && ./fileserver
``` ```
(注意下载时要注意链接的版本号windows下直接运行fileserver.exe执行文件在这里[下载](https://github.com/sjqzhang/fastdfs/releases))
# 命令上传
#Command upload
`curl -F file=@http-index-fs http://10.1.xx.60:8080/upload` `curl -F file=@http-index-fs http://10.1.xx.60:8080/upload`
# WEB上传(浏览器打开) # WEB upload (browser open)
`http://yourserver ip:8080/upload.html` 注意不要使用127.0.0.1上传 `http://127.0.0.1:8080`
# 代码上传(选项参阅浏览器上传) #Code upload (options see browser upload)
## python
## python版本:
```python ```python
import requests import requests
url = 'http://10.1.5.9:8080/upload' url = 'http://127.0.0.1:8080/upload'
files = {'file': open('report.xls', 'rb')} files = {'file': open('report.xls', 'rb')}
options={'output':'json','path':'','scene':''} #参阅浏览器上传的选项 options={'output':'json','path':'','scene':''} #See browser upload options
r = requests.post(url,data=options, files=files) r = requests.post(url, files=files)
print(r.text) print(r.text)
``` ```
## golang版本 ## golang
```go ```go
package main package main
@ -106,16 +103,17 @@ import (
func main() { func main() {
var obj interface{} var obj interface{}
req:=httplib.Post("http://10.1.5.9:8080/upload") req:=httplib.Post("http://10.1.5.9:8080/upload")
req.PostFile("file","filename")//注意不是全路径 req.PostFile("file","path/to/file")
req.Param("output","json") req.Param("output","json")
req.Param("scene","") req.Param("scene","")
req.Param("path","") req.Param("path","")
req.ToJSON(&obj) req.ToJSON(&obj)
fmt.Print(obj) fmt.Print(obj)
} }
``` ````
## java版本
依赖(这里使用了hutool工具包,更简便) ## java
```xml ```xml
<dependency> <dependency>
<groupId>cn.hutool</groupId> <groupId>cn.hutool</groupId>
@ -123,32 +121,22 @@ func main() {
<version>4.4.3</version> <version>4.4.3</version>
</dependency> </dependency>
``` ```
上传代码
```java ```java
public static void main(String[] args) { public static void main(String[] args) {
//文件地址
File file = new File("D:\\git\\2.jpg"); File file = new File("D:\\git\\2.jpg");
//声明参数集合
HashMap<String, Object> paramMap = new HashMap<>(); HashMap<String, Object> paramMap = new HashMap<>();
//文件
paramMap.put("file", file); paramMap.put("file", file);
//输出
paramMap.put("output","json"); paramMap.put("output","json");
//自定义路径
paramMap.put("path","image"); paramMap.put("path","image");
//场景
paramMap.put("scene","image"); paramMap.put("scene","image");
//上传
String result= HttpUtil.post("http://xxxxx:xxxx/upload", paramMap); String result= HttpUtil.post("http://xxxxx:xxxx/upload", paramMap);
//输出json结果
System.out.println(result); System.out.println(result);
} }
``` ```
[更多语言请参考](doc/upload.md)
# 断点续传示例 # Breakpoint resume example
## golang
## golang版本
```go ```go
package main package main
@ -177,364 +165,350 @@ func main() {
fmt.Println( uploader.Upload()) fmt.Println( uploader.Upload())
} }
```` ````
[更多客户端请参考](https://github.com/tus) [more langue](doc/upload.md)
![deploy](doc/go-fastdfs-deploy.png)
Universal file authentication timing diagram
![Universal file authentication timing diagram](doc/authentication2.png)
部署图 File google authentication timing diagram
![部署图](doc/go-fastdfs-deploy.png) ![File google authentication timing diagram](doc/authentication.png)
通用文件认证时序图 # Please click [Feedback](https://github.com/sjqzhang/go-fastdfs/issues/new)
![通用文件认证时序图](doc/authentication2.png)
文件google认证时序图
![文件认证时序图](doc/authentication.png)
# 有问题请[点击反馈](https://github.com/sjqzhang/go-fastdfs/issues/new)
# 重要说明
## 在issue中有很多实际使用的问题及回答很多已关闭请查看已关闭的issue
## 项目从v1.1.8开始进入稳定状态
# 更新说明
## 从低版升给到高版本可能存在配置项变动的情况一定要注意使用新的版本时的配置项。如何获得新版本的配置项及说明先备份旧的配置项文件名不能为cfg.json再运行新的版本配置项就自动生成。然后再修改相应的配置项。
- v1.1.9 增加文件自动迁移功能,支持同名文件重复覆盖选项。
# <span id="qa">Q&A</span> # <span id="qa">Q&A</span>
- 最佳实战? - Best practice?
``` ```
一、如果是海量存储不要开启文件token认证功能减少性能开消。 First, if it is mass storage, do not open the file token authentication function to reduce performance.
二、尽量用标准上传上传后业务保存path在业务用的时候再并接上域名方便迁移扩展等 Second, try to use the standard upload, upload the business to save the path, and then connect the domain name when the business is used (convenient migration extension, etc.).
三、如果使用断点续传上传后一定要用文件id置换成path存储如何置换看/API文档为后面访问减少性能开消。 Third, if you use breakpoints to continue transmission, you must use the file id to replace the path storage after uploading (how to replace the QA/API document), to reduce performance for subsequent access.
四、尽量使用物理服务器部署,因为主要压力或性能来自于IO Fourth, try to use physical server deployment, because the main pressure or performance comes from IO
五、线上业务尽量使用nginx+gofastdfs部署架构(均衡算法使用ip_hash),以满足后面的功能扩展性(nginx+lua)。 Fifth, the online business should use the nginx+gofastdfs deployment architecture (the equalization algorithm uses ip_hash) to meet the later functional scalability (nginx+lua).
六、线上环境最好不要使用容器部署,容器适用于测试和功能验证。 Sixth, the online environment is best not to use container deployment, the container is suitable for testing and functional verification.
总结业务保存的文件的path,减少后期访问路径转换带来开消,文件访问权限由业务来完成这样性能最好通用性强可直接其它web服务器 Summary: The path of the file saved by the business reduces the conversion of the later access path, and the file access permission is completed by the service, so that the performance is the best and the versatility is strong (can be directly connected to other web servers).
重要提醒:如果开启小文件合并功能,后期是无法删除小文件的。 Important reminder: If the small file merge function is enabled, it is impossible to delete small files later.
上传结果说明 Upload result description
请使用md5,path,scene字段其它是为了兼容老的线上系统添加的以后有可能去掉。 Please use md5, path, scene field, others are added to be compatible with the old online system, and may be removed in the future.
``` ```
- 有API文档么 - Is there an API document?
[API文档](doc/api.md) [API documentation] (doc/api.md)
- 有管理后台么? - Is there a management background?
``` ```
https://github.com/perfree/go-fastdfs-web Https://github.com/perfree/go-fastdfs-web
``` ```
- 断点上传有使用说明么? - Is there any instructions for using the breakpoint upload?
``` ```
https://github.com/tus Https://github.com/tus
``` ```
- 在微信讨论群中大家都问到go-fastdfs性能怎样 - In the WeChat discussion group, everyone asked about the performance of go-fastdfs?
``` ```
由于问的人太多,在这里统一回答。 Because there are too many people asking, answer here in unison.
go-fastdfs的文件定位与其它分布式系统不同它的寻址是直接定位不经过任何组件所以可以近似时间复杂度为o(1)[文件路径定位] The file location of go-fastdfs is different from other distributed systems. Its addressing is directly located without any components, so the approximate time complexity is o(1)[file path location]
基本没有性能损耗,项目中也附有压测脚本,大家可以自已进行压测,群里就不要太多讨论问题了,人多每次回复同样的问题 There is basically no performance loss. The project also has a pressure test script. You can carry out the pressure test yourself. Dont discuss the problem too much in the group. People reply to the same question every time.
大家也会觉得这群无聊。 Everyone will also feel that this group is boring.
``` ```
- 已经使用fastdfs存储的文件可以迁移到go fastdfs下么其它迁移情况可按类似的方式处理极速体验也用类似的方式 - Files that have been stored using fastdfs can be migrated to go fastdfs (other migrations can be handled in a similar manner, and the speed experience is similar)?
``` ```
答案是可以的,你担心的问题是路径改变,go fastdfs为你考虑了这一点 The answer is yes, the problem you are worried about is the path change, go fastdfs considers this for you.
步骤: step:
一、下载最新版的go-fastdfs First, download the latest version of go-fastdfs
二、将原来的fastdfs文件目录复制到go-fastdfs的 files目录下(如果文件很多可以逆向过来将fileserver复制过去但要保留fileserver的目录结构 Second, copy the original fastdfs file directory to the files directory of go-fastdfs (if there are a lot of files, you can reverse it, copy the fileserver, but keep the fileserver directory structure)
三、将配置enable_migrate设为true Third, set the enable_migrate to true
注意迁移过程中会扫描整下files目录下的所有文件 Note: All files in the files directory will be scanned during the migration process.
速度较慢迁移完成后请将enable_migrate设为false Slower, set enable_migrate to false after migration is complete
说明go-fastdfs的目录是不能变动的与同步机制相关很多同学在群里问题我的files目录能不能自定义答案是否定的。 Note: The directory of go-fastdfs can not be changed, related to the synchronization mechanism, many students in the group, my files directory can not be customized, the answer is no.
至于能不能用软链接的方式本人没有测试过,可以自行测试。 As for whether or not I can use the soft link, I have not tested it and can test it myself.
``` ```
- 什么是集群如何用Nginx管理多集群 - What is a cluster, how to manage multiple clusters with Nginx?
``` ```
1、在go-fastdfs中一个集群就是一个group。 1. In go-fastdfs, a cluster is a group.
2、请参阅部署图 2, please refer to the deployment diagram
注意:配置中的 support_group_manage 参数设为true时所有的url中都自动添加组信息。 Note: When the support_group_manage parameter in the configuration is set to true, group information is automatically added to all urls.
例如:http://10.1.5.9:8080/group/status For example: http://10.1.5.9:8080/group/status
默认:http://10.1.5.9:8080/status Default: http://10.1.5.9:8080/status
区别多了group,对应配置中的 group 参数,这样主要是为了解决一个Nginx反向代理多个group(集群) The difference: more group, corresponding to the group parameter in the configuration, so mainly to solve a Nginx reverse proxy multiple groups (cluster)
具体请参阅部署图 Please refer to the deployment diagram for details.
``` ```
- 如何搭建集群? - How to build a cluster?
``` ```
一、先下载已编译的可执行文件(用最新版本) First, download the compiled executable file (with the latest version)
二、运行可执行文件(生成配置) Second, run the executable file (generate configuration)
三、修改配置 Third, modify the configuration
peers增加对端的http地址 Peers: increase the peer's http address
检查: an examination:
host:自动生成是否正确 Host: Is the automatic generation correct?
peer_id:集群内是否唯一 Peer_id: Is it unique within the cluster?
四、重新运行服器 Fourth, re-run the server
五、验证服务是否OK 5. Is the verification service OK?
``` ```
- 适合海量存储吗? - Is it suitable for mass storage?
``` ```
答案:适合海量存储 Answer: Suitable for mass storage
``` ```
- 如何上传文件夹? - How to upload a folder?
``` ```
DIR=log && ls $DIR |xargs -n 1 -I {} curl -s -F path=$DIR -F file=@$DIR/{} http://10.1.50.90:8080/upload DIR=log && ls $DIR |xargs -n 1 -I {} curl -s -F path=$DIR -F file=@$DIR/{} http://10.1.50.90:8080/upload
上面命令的log为要上传的目录如果代码上传就是简单的循环上传就 The log of the above command is the directory to be uploaded. If the code upload is a simple loop upload, it will be OK.
``` ```
- 如何缩放图片? - How to scale the picture?
``` ```
在下载url中加入width各height参数 Add width parameter in the download url
例如:http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0&width=100&height=100 For example: http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0&width=100&height=100
特明说明是如果要等比例缩放请将width或height设为 The special explanation is: if you want to scale, please set the width or height to 0.
``` ```
- 如何在浏览器中直接显示图片? - How to display images directly in the browser?
``` ```
在下载url中加入download=0参数 Add the download=0 parameter to the download url.
例如:http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0 For example: http://127.0.0.1:8080/group1/haystack/5/124,0,27344,.jpg?download=0
``` ```
- 如何实现自定义认证上传下载? - How to implement custom authentication upload and download?
``` ```
一、使用1.2.6版本以后的go-fastdfs First, the use of the 1.2.6 version of the go-fastdfs
二、设auth_url参数应用提供 Second, set the auth_url parameter (provided by the application)
三、应用实现验证权限接口即第二步的url,参数为 auth_toke 返回 ok 表示认证通过,其它为不通过 Third, the application implements the authentication permission interface (that is, the url of the second step), the parameter is auth_toke, ok, the authentication is passed, and the others are not passed.
四、认证通过后,可以上传或下载 Fourth, after the certification is passed, you can upload or download
``` ```
- 还需要安装nginx么 - Need to install nginx yet?
``` ```
go-fastdfs本身是一个高性能的web服务器在开发或测试时可以不用安装nginx Go-fastdfs itself is a high-performance web server, you don't need to install nginx when developing or testing.
但go-fastdfs的功能单一如需要缓存或重定向或其它扩展nginx都有成熟的组件 But go-fastdfs has a single function, such as caching or redirection or other extensions, nginx has mature components
所以建议线上还是加一层nginx再借助nginx+lua解决扩展性问题。 Therefore, it is recommended to add a layer of nginx on the line, and then use nginx+lua to solve the scalability problem.
``` ```
- 能动态加载配置么? - Can I dynamically load the configuration?
``` ```
答案:是可以的,但要更新到最新版本 Answer: Yes, but update to the latest version
步骤: step:
1)修改 conf/cfg.json 文件 1) Modify the conf/cfg.json file
2)访问 http://10.1.xx.60:8080/reload 2) Visit http://10.1.xx.60:8080/reload
3 注意:每个节点都需要进行同样的操作 3) Note: Every node needs to do the same thing
``` ```
- 如何查看集群文件信息? - How to view cluster file information?
``` ```
http://10.1.xx.60:8080/stat Http://10.1.xx.60:8080/stat
如果出现文件统计出错怎么办? What should I do if there is a file error?
请删除 data目录下的 stat.json文件 重启服务,请系统自动重新计算文件数。 Please delete the stat.json file in the data directory. Restart the service, please recalculate the number of files automatically.
或者调用 Or call
http://10.1.xx.60:8080/repair_stat Http://10.1.xx.60:8080/repair_stat
``` ```
- 可靠性怎样,能用于生产环境么? - How reliable can it be used in a production environment?
``` ```
本项目已大规模用于生产环境,如担心不能满足 This project has been used on a large scale in the production environment, such as fear of not meeting
可以在使用前对其各项特性进行压力测试,有任何 You can stress test its features before use, any
问题可以直接提issue The problem can be directly mentioned
``` ```
- 如何后台运行程序? - How to run the program in the background?
``` ```
请使用control 对程序进行后面运行,具体操作如下: Please use control to run the program later, as follows:
一、 chmod +x control First, chmod +x control
二、 确保control与fileserver在同一个目录 Second, make sure the control and fileserver are in the same directory
三、 ./control start|stop|status #对和序进行启动,停止,查看状态等。 Third, ./control start|stop|status #Start and start the sequence, stop, view the status, and so on.
``` ```
- 能不能在一台机器部置多个服务端? - Can I have multiple servers on one machine?
``` ```
不能在设计之初就已考虑到集群的高可用问题为了保证集群的真正可用必须为不同的ip,ip 不能用 127.0.0.1 No, the high availability of the cluster has been considered at the beginning of the design. In order to ensure the true availability of the cluster, it must be different for ip, ip can not use 127.0.0.1
错误 "peers": ["http://127.0.0.1:8080","http://127.0.0.1:8081","http://127.0.0.1:8082"] Error "peers": ["http://127.0.0.1:8080","http://127.0.0.1:8081","http://127.0.0.1:8082"]
正确 "peers": ["http://10.0.0.3:8080","http://10.0.0.4:8080","http://10.0.0.5:8080"] Correct "peers": ["http://10.0.0.3:8080","http://10.0.0.4:8080","http://10.0.0.5:8080"]
``` ```
- 文件不同步了怎么办? - What should I do if the files are not synchronized?
``` ```
正常情况下,集群会每小时自动同步修复文件。(性能较差,在海量情况下建议关闭自动修复) Under normal circumstances, the cluster automatically synchronizes the repair files every hour. (The performance is poor, it is recommended to turn off automatic repair in case of massive)
那异常情况下怎么? What about the abnormal situation?
答案:手动同步(最好在低峰执行) Answer: Manual synchronization (preferably at low peaks)
http://172.16.70.123:7080/sync?date=20190117&force=1 (说明:要在文件多的服务器上执行,相关于推送到别的服务器) Http://172.16.70.123:7080/sync?date=20190117&force=1 (Note: To be executed on a server with many files, related to pushing to another server)
参数说明date 表示同步那一天的数据 force 1.表示是否强制同步当天所有(性能差)0.表示只同步失败的文件 Parameter description: date indicates the data of the day of synchronization. force 1. indicates whether to force synchronization of all the day (poor performance), 0. means that only failed files are synchronized.
不同步的情况: Unsynchronized situation:
1) 原来运行N台现在突然加入一台变成N+1台 1) Originally running N sets, now suddenly join one to become N+1
2原来运行N台某一台机器出现问题变成N-1台 2) Originally running N sets, one machine has a problem and becomes N-1
如果出现多天数据不一致怎么办?能一次同步所有吗? What if there is a multi-day data inconsistency? Can I synchronize all at once?
答案是可以:(最好在低峰执行) The answer is yes: (preferably at low peaks)
http://172.16.70.123:7080/repair?force=1 Http://172.16.70.123:7080/repair?force=1
``` ```
- 文件不同步会影响访问吗? - Does the file out of sync affect access?
``` ```
答案:不会影响,会在访问不到时,自动修复不同步的文件。 Answer: It will not affect, it will automatically repair the files that are not synchronized when the access is not available.
``` ```
- 如何查看系统状态及说明? - How do I check the system status and description?
``` ```
http://172.16.70.123:7080/status Http://172.16.70.123:7080/status
注意:Fs.Peers是不带本机的如果带有可能出问题 Note: (Fs.Peers is not equipped with this unit, if there is a problem with the problem)
本机为 Fs.Local This machine is Fs.Local
sts["Fs.ErrorSetSize"] = this.errorset.Cardinality() 这个会导致内存增加 Sts["Fs.ErrorSetSize"] = this.errorset.Cardinality() This will cause memory to increase
``` ```
- 如何编译(go1.9.2+) - How to compile (go1.9.2+)?
``` ```
git clone https://github.com/sjqzhang/go-fastdfs.git Git clone https://github.com/sjqzhang/go-fastdfs.git
cd go-fastdfs Cd go-fastdfs
mv vendor src Mv vendor src
pwd=`pwd` Pwd=`pwd`
GOPATH=$pwd go build -o fileserver fileserver.go GOPATH=$pwd go build -o fileserver fileserver.go
``` ```
- 如何跑单元测试 (尽量在linux下进行) - How to run a unit test (try to do it under linux)?
``` ```
git clone https://github.com/sjqzhang/go-fastdfs.git Git clone https://github.com/sjqzhang/go-fastdfs.git
cd go-fastdfs Cd go-fastdfs
mv vendor src Mv vendor src
pwd=`pwd` Pwd=`pwd`
GOPATH=$pwd go test -v fileserver.go fileserver_test.go GOPATH=$pwd go test -v fileserver.go fileserver_test.go
``` ```
- 如何压测? - How to test?
``` ```
步骤: step:
一、创建files文件夹 First, create a files folder
二、将gen_file.py复制到files文件夹中通过python gen_file.py 生成大量文件 Second, copy gen_file.py to the files folder, generate a large number of files through python gen_file.py
三、将benchmark.py放到 files目录外即与files目录同一级通过python benchmark.py进行压测注意对benchmark.py中的ip进行修改 Third, put benchmark.py outside the files directory (that is, the same level as the files directory), press the python benchmark.py (note the ip in the benchmark.py)
先用gen_file.py产生大量文件注意如果要生成大文件自已在内容中乘上一个大的数即可 First use gen_file.py to generate a large number of files (note that if you want to generate large files, you can multiply the content by a large number)
例如: E.g:
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
import os Import os
j=0 j=0
for i in range(0,1000000): For i in range(0,1000000):
if i%1000==0: If i%1000==0:
j=i j=i
os.system('mkdir %s'%(i)) Os.system('mkdir %s'%(i))
with open('%s/%s.txt'%(j,i),'w+') as f: With open('%s/%s.txt'%(j,i),'w+') as f:
f.write(str(i)*1024) F.write(str(i)*1024)
接着用benchmark.py进行压测 Then use benchmark.py for pressure measurement
也可以多机同时进行压测,所有节点都是可以同时读写的 It is also possible to perform pressure measurement simultaneously in multiple machines, and all nodes can be read and written simultaneously.
``` ```
- 代码为什么写在一个文件中? - Why is the code written in a file?
``` ```
一、目前的代码还非常简单,没必要弄得太复杂。 First, the current code is still very simple, no need to make it too complicated.
二、个人理解模块化不是分开多个文件就表示模块化大家可以用IDE去看一下代码结构其实是已经模块化的。 Second, the individual understands that modularity is not modular when multiple files are separated. You can use the IDE to look at the code structure, which is actually modular.
``` ```
- 支持断点下载? - Support for breakpoint downloads?
``` ```
答案:支持 Answer: Support
curl wget 如何 Curl wget how
wget -c http://10.1.5.9:8080/group1/default/20190128/16/10/2G Wget -c http://10.1.5.9:8080/group1/default/20190128/16/10/2G
culr -C - http://10.1.5.9:8080/group1/default/20190128/16/10/2G Culr -C - http://10.1.5.9:8080/group1/default/20190128/16/10/2G
``` ```
- Docker如何部署 - How is Docker deployed?
``` ```
步骤: step:
方式一、 method one,
一、构建镜像 First, build a mirror
docker build . -t fastdfs Docker build . -t fastdfs
二、运行容器(使用环境变量 GO_FASTDFS_DIR 指向存储目录。) Second, run the container (use the environment variable GO_FASTDFS_DIR to point to the storage directory.)
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs Docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
方式二、 Method 2,
一、拉取镜像 First, pull the mirror
docker pull sjqzhang/go-fastdfs Docker pull sjqzhang/go-fastdfs
二、运行容器 Second, run the container
docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs Docker run --name fastdfs -v /data/fastdfs_data:/data -e GO_FASTDFS_DIR=/data fastdfs
``` ```
- 大文件如何分块上传或断点续传? - How to upload large files or breakpoints?
``` ```
一般的分块上传都要客户端支持,而语言的多样性,客户端难以维护,但分块上传的功能又有必要,为此提供一个简单的实现思路。 The general block uploading must be supported by the client, and the diversity of the language is difficult for the client to maintain, but the function of the block uploading is necessary, and a simple implementation idea is provided for this.
方案一、 Option One,
借助linux split cat 实现分割与合并,具体查看 split 与 cat 帮助。 Split and merge with linux split cat, see the split and cat help.
分割: split -b 1M filename #按每个文1M Split: split -b 1M filename #1M per text
合并: cat x* > filename #合并 Merge: cat x* > filename #merge
方案二、 Option II,
借助hjsplit With hjsplit
http://www.hjsplit.org/ Http://www.hjsplit.org/
具体自行实现 Specific self-realization
方案三、 third solution,
建议用go实现hjsplit分割合并功这样具有跨平台功能。未实现等你来.... It is recommended to implement the hjsplit split merge function with go, which has cross-platform capabilities. (Unrealized, waiting for you to come....)
方案四、 Option 4
使用内置的继点续传功能使用protocol for resumable uploads协议[详情](https://tus.io/) Use the built-in relay function (using the protocol for resumable uploads protocol, [Details] (https://tus.io/))
注意方案四、只能指定一个上传服务器不支持同时写并且上传的url有变化 Note: Option 4, you can only specify one upload server, do not support simultaneous writes, and the uploaded url has changed.
原上传url http://10.1.5.9:8080/<group>/upload Original upload url: http://10.1.5.9:8080/<group>/upload
断点上传url http://10.1.5.9:8080/<group>/big/upload/ Breakpoint upload url: http://10.1.5.9:8080/<group>/big/upload/
上传完成,再通过秒传接口,获取文件信息 The upload is completed, and then the second pass interface is used to obtain the file information.
``` ```
- 如何秒传文件? - How to pass files in seconds?
``` ```
通过http get的方式访问上传接口 Access the upload interface by means of http get
http://10.0.5.9:8080/upload?md5=filesum&output=json Http://10.0.5.9:8080/upload?md5=filesum&output=json
参数说明: Parameter Description:
md5=sum(file) 文件的摘要算法要与文件务器的算法一致算法支持md5|sha1如果是断点续传可以使用文件的id也就是urlolad后的id Md5=sum(file) The digest algorithm of the file should be consistent with the algorithm of the server (the algorithm supports md5|sha1). If it is a breakpoint, you can use the id of the file, which is the id after urlolad.
output=json|text 返回的格式 Output=json|text The format returned
``` ```
- 集群如何规划及如何进行扩容? - How is the cluster planned and how is it expanded?
``` ```
建议在前期规划时,尽量采购大容量的机器作为存储服务器,如果要两个副本就用两台组成一个集群,如果要三个副本 It is recommended that in the early planning, try to purchase a large-capacity machine as a storage server. If you want two copies, use two to form a cluster. If you want three copies.
就三台组成一个集群。注意每台服务器最好配置保持一样并且使用raid5磁盘阵列 Let the three units form a cluster. (Note that the best configuration for each server remains the same and uses raid5 disk arrays)
如果提高可用性只要在现在的集群peers中加入新的机器再对集群进行修复即可。 If you increase the availability, just add a new machine to the current cluster peers and fix the cluster.
修复办法 http://172.16.70.123:7080/repair?force=1 (建议低峰变更) Repair method http://172.16.70.123:7080/repair?force=1 (recommended low peak change)
如何扩容? How to expand?
为简单可靠起见,直接搭建一个新集群即可(搭建就是启动./fileserver进程设置一下peers的IP地址三五分钟的事 For the sake of simplicity and reliability, you can directly build a new cluster (build is to start the ./fileserver process, set the IP address of the peers, three or five minutes)
issue中chengyuansen同学向我提议使用增加扩容特性我觉得对代码逻辑及运维都增加复杂度暂时没有加入这特性。 In the issue, chengyuansen suggested to me to use the increased capacity expansion feature. I feel that the complexity of the code logic and operation and maintenance is increased. I have not added this feature for the time being.
``` ```
- 访问限制问题 - Access restriction issues
``` ```
出于安全考虑,管理API只能在群集内部调用或者用127.0.0.1调用. For security reasons, the management API can only be called inside the cluster or with 127.0.0.1.
``` ```
- 有问题请[点击反馈](https://github.com/sjqzhang/go-fastdfs/issues/new) - If you have any questions, please click [Reply] (https://github.com/sjqzhang/go-fastdfs/issues/new)
## 有问题请加群 ## Have questions?
![二维码](doc/wechat.jpg) ![QR code](doc/wechat.jpg)
#### 进群请改昵称,昵称格式:城市-公司-昵称,如果你喜欢这项目,请关注(star)此项目,关注是对项目的肯定,也是作者创新的动力。
#### [捐赠](doc/pay.png) #### [donation] (doc/pay.png)