FastDFS前奏
在开始之前,这篇文章并不是初级入门的文章,在该文章发布之前已经有两篇文章讲述了FastDFS和SpringBoot相关的知识,请参阅:
-
《Java高级架构之FastDFS分布式文件集群》:https://blog.51cto.com/xvjunjie/2377669
- 《SpringBoot集成FastDFS+Nginx整合基于Token的防盗链》:https://blog.51cto.com/xvjunjie/2381361
如果需要在FastDFS中实现HTTPS功能,请参阅:
- 《Vue、SprinBoot开发运维的一些坑和知识集锦》:https://blog.51cto.com/xvjunjie/2440933
在下图中,任何一个节点都支持水平横向无限扩展。当在某一个Group中添加新的Storage服务器的时候,新加入该Group的服务器会自动同步所有数据。当新添加Group的时候,只需要修改处于前端的Nginx服务器即可。要实现主备自动切换还可以加入KeepAlived中间件。
- FastDFS服务器通过HTTP提供服务,但是HTTP的性能太弱,所以在V4.05之后的版本中删除了内置的HTTP服务。
- FastDFS的Group之间的Storage需要复制数据,如果请求的数据正在复制,由于不是源服务器,那么fastdfs-nginx-module将进行重定向源服务器。
- fastdfs-nginx-module支持配置多个组,一个服务器可以配置多个Group不同的Storage。同一个Group的Storage必须端口相同。
- Nginx会为FastDFS提供负载均衡和数据缓存的功能。
- FastDFS集群的总容量等于全部Group容量之和。一个Group的容量等于最小的Storage服务器容量。
- 组一般用于隔离不同的数据。
FastDFS分布式文件集群HA架构图
集群中具体机器配置
安装软件 | 机器主机名 | 应用IP地址 | 管理IP地址 |
---|---|---|---|
fastdfs+fastdfs-nginx-module | fastdfs-storage1-group1 | 192.168.80.11 | 192.168.10.11 |
fastdfs+fastdfs-nginx-module | fastdfs-storage2-group1 | 192.168.80.12 | 192.168.10.12 |
fastdfs+fastdfs-nginx-module | fastdfs-storage3-group1 | 192.168.80.13 | 192.168.10.13 |
fastdfs+fastdfs-nginx-module | fastdfs-storage4-group2 | 192.168.80.14 | 192.168.10.14 |
fastdfs+fastdfs-nginx-module | fastdfs-storage5-group2 | 192.168.80.15 | 192.168.10.15 |
fastdfs+fastdfs-nginx-module | fastdfs-storage6-group2 | 192.168.80.16 | 192.168.10.16 |
fastdfs+fastdfs-nginx-module | fastdfs-storage7-group3 | 192.168.80.17 | 192.168.10.17 |
fastdfs+fastdfs-nginx-module | fastdfs-storage8-group3 | 192.168.80.18 | 192.168.10.18 |
fastdfs+fastdfs-nginx-module | fastdfs-storage9-group3 | 192.168.80.19 | 192.168.10.19 |
fastdfs+fastdfs-nginx-module | fastdfs-storage10-group1-new | 192.168.80.20 | 192.168.10.20 |
fastdfs | fastdfs-tracker1 | 192.168.80.21 | 192.168.10.21 |
fastdfs | fastdfs-tracker2 | 192.168.80.22 | 192.168.10.22 |
fastdfs | fastdfs-tracker3 | 192.168.80.23 | 192.168.10.23 |
nginx | fastdfs-nginx0 | 192.168.80.50 | 192.168.10.50 |
nginx | fastdfs-nginx1 | 192.168.80.51 | 192.168.10.51 |
(1)在所有服务器上部署FastDFS服务
yum update
mkdir /source
cd /source
yum install -y gcc gcc-c++ make cmake wget libevent
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.35.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.10.tar.gz
tar -zxvf V1.0.35.tar.gz
tar -zxvf V5.10.tar.gz
cd libfastcommon-1.0.35
./make.sh
./make.sh install
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
cd ../
cd fastdfs-5.10/
./make.sh
./make.sh install
cd ../
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
mkdir -p /data/fdfs/tracker
mkdir -p /data/fdfs/storage
mkdir -p /data/fdfs/client
mkdir -p /data/fdfs/disks/volume0
mkdir -p /data/fdfs/disks/volume1
mkdir -p /data/fdfs/disks/volume2
mkdir -p /data/fdfs/disks/volume3
mkdir -p /data/fdfs/disks/volume4
mkdir -p /data/fdfs/disks/volume5