Fastdfs architecture

1, Fastdfs introduce
a lightweight open source distributed file system Fastdfs is c language, its document process management functions including: file storage, file synchronization, file access (file upload, file download) etc., to solve imbalance in the mass storage and load, particularly suitable for the carrier to file online services, such as photo album sites, video sites, and more
Fastdfs tailor-made for the Internet, full account of redundancy, load balancing, linear expansion, etc., and pay attention high availability, high performance and other indicators, it is easy to use fastdfs to build a high-performance file server clusters to provide file upload and download service
2, fastdfs architecture
fastdfs architecture includes Tracker server and Storage server
client requests Tracker server for file upload, download, the final completion scheduled by Tracker server Storage server by the file upload and download
Tracker server role is load balancing and scheduling can be found Storage server to provide file upload service to Tracker server when the file is uploaded, according to some policies, you can say tracker track to become a server or scheduling Service is
Storage server as a file stored on the storage server, Storage server does not implement its own file system client upload the final file storage but to use the operating system's file system to manage files, you can speak storage storage servers become
Fastdfs architecture

3, FastDFS system has three roles: Tracking server (Tracker Server), Storage Server (Storage Server) and client (Client).
• Tracker Server: tracking server, the main job of scheduling work, play a balancing role; responsible for managing all of the storage server and the group, each storage after starting connects Tracker, inform the group they belong to other information, and to maintain a periodic heartbeat.
• Storage Server: storage servers, mainly to provide capacity and back-up services; to group as a unit, each group can have more than one storage server, data back up each other.
• Client: client, server upload download data, that is, our own servers deployed in the project.
4, Fastdfs principle
for Module: tracking server and the storage nodes may be constituted by one or more servers, tracking server and storage nodes can be increased without affecting the online or offline service at any time, wherein all servers in the tracking server is etc., can be increased according to the pressure on the server at any time or reduce
5, file upload process
Storage server will be connected to the cluster all the Tracker server, regular reporting their status to them, including disk space, file synchronization status, file upload times and other download statistics information.
Upload About
Fastdfs architecture**
file index information includes: group name, virtual disk paths, two data directory, file name.
n Group Name: storage group after the name of the file upload, file upload after the successful return has storage server, the client needs to save itself.
n virtual disk path: *storage configuration of the virtual path, and disk options store_path correspondence. If you configure store_path0 is M00, if you configure store_path1 is M01, and so on.
n data two directories: Storage server creates a virtual disk in each of the two directory paths for storing data files.
n File name: different upload the file. Is based on specific information generated by the storage server, the file name contains: source IP address of the storage server, file creation time stamp, file size, the random number and filename extension and other information.


Fastdfs architecture

client sends a download request to the tracker, must bring the file name information, Tracker parsed file group from the file name, size, creation time and other information, and a storage request to service a read request for selection, since the group in the background file synchronization is asynchronous, there may be read when the file has not been synchronized to a certain storage Server, in order to avoid access to such storage, Tracker readable storage selected in the group follows rule
file -storage creation timestamp is synchronized to the time stamp and - after (the current time of the file creation timestamp)> file synchronization maximum time (five minutes), indicating that the file is created that after a maximum synchronization time, must have been synchronized to the other storage

6, mounting fastdfs
192.168.1.10 Nginx Proxy
192.168.1.20 Tracker server1
192.168.1.30 Tracker Server2
192.168.1.40 Storage Server named group1
192.168.1.50 group2 Storage Server
data storage location / storage / fastdfs

一.部署安装traker server

Fastdfs architecture
1.安装编译环境,安装libfastcommon和fastdfs(所有节点)
Libfastcommon 包含了fastdfs运行所需的要的一些基础库
17 mkdir /storage/fastdfs -p (创建数据存储位置)
20 tar zxf libfastcommon.tar.gz (解压lib)
21 cd libfastcommon/
22 ./make.sh && ./make.sh install (编译安装lib)
23 cd
24 tar zxf fastdfs.tar.gz (解压fas)
25 cd fastdfs/
26 ./make.sh && ./make.sh install (编译安装 fastdfs)
27 ls /etc/init.d/
Fastdfs architecture
28 cp conf/mime.types conf/http.conf /etc/fdfs/
(复制nginx拓展文件到fdfs)

2.第一台编写一个脚本 (方便部署traker)
vim install-fastdfs.sh
#!/bin/bash
mkdir /storage/fastdfs -p
cd /root
tar zxf libfastcommon.tar.gz
tar zxf fastdfs.tar.gz
cd /root/libfastcommon/
./make.sh && ./make.sh install
cd /root/fastdfs/
./make.sh && ./make.sh install
cd /root/fastdfs/
cp conf/mime.types conf/http.conf /etc/fdfs/
ls /etc/fdfs
#/etc/fdfs/ 配置文件路径

3.把脚本和软件包复制到其他四台主机
scp root fastdfs.tar.gz libfastcommon.tar.gz install-fastdfs.sh [email protected]:/root
4.四台执行一下脚本,查看一下脚本是否执行成功
sh install-fastdfs.sh
Fastdfs architecture

5.配置track(两台都是)
29 cd /etc/fdfs/
30 ls
31 cp tracker.conf.sample tracker.conf
32 vim tracker.conf 修改tracker配置文件
bind_addr=192.168.1.20 #监听本机地址 8
base_path=/storage/fastdfs #这里写刚刚创建的数据存放的路径 22
34 /etc/init.d/fdfs_trackerd start 启动trackerd
35 netstat -anpt | grep 22122
Fastdfs architecture

6.安装nginx(第一台)
Fastdfs architecture
36 yum -y install pcre-devel openssl-devel zlib-devel #安装nginx依赖包
35 tar zxf nginx-1.14.0.tar.gz #解压nginx tar包
37 cd nginx-1.14.0/
38 ./configure && make && make install #编译安装

二.配置storage server服务器(两台都是)

Fastdfs architecture
1.安装nginx (两台都要)
30 yum -y install pcre-devel openssl-devel 安装依赖包
31 tar zxf nginx-1.14.0.tar.gz 解压nginx包
32 tar zxf fastdfs-nginx-module.tar.gz 解压nginx拓展包
33 cd nginx-1.14.0/
36 ./configure --add-module=../fastdfs-nginx-module/src && make && make install 编译安装
2.配置storage
38 cd /etc/fdfs/
39 cp storage.conf.sample storage.conf
40 vim storage.conf 修改storage配置文件
group name=group1第一台storage为group1 第二台storage为group2 11
bind
addr=192.168.1.40
port=23000 #默认端口,不做修改
base path=/storage/fastdfs/ #数据和日志存放的目录地址 41
store
path0=/storage/fastdfs/ #第一个存储目录和basrpath路径相同 110
tracker
server=192. 168.1.20:22122 119
tracker server=192.168.1.30:22122 120
http. server
port=8888 #http访问文件的端口 末尾

3.配置nginx拓展配置文件
43 cd /fastdfs-nginx-module/src/
44 cp mod_fastdfs.conf /etc/fdfs/
45 vim /etc/fdfs/mod_fastdfs.conf

base_path=/storage/fastdfs/ #数据和日志存放的目录地址 10
tracker_server=192.168.1.20:22122 #40
tracker_server=192.168.1.30:22122 #41
storage_server_port=23000 44
group_name=group1 #第二台storage组名为group2 47
url_have_group_name = true #当group有多个的时候需要改为true,以组名去访问 53
store_path0=/storage/fastdfs #第一个存储目录和basr_path路径相同 62

[group1] #119去注释修改或直接添加
group_name=group1
storage_server_port=23000
store_path_count=2
store_path0=/storage/fastdfs
[group2]
group_name=group2
storage_server_port=23000
store_path_count=2
store_path0=/storage/fastdfs
****4.拷贝nginx拓展软件的配置文件,storage的配置文件,nginx安装包和nginx拓展包到第二台storage主机(拷贝完之后,按照上面2,3步骤来一遍)
48 cd /etc/fdfs/
49 scp mod_fastdfs.conf storage.conf [email protected]:/etc/fdfs/
50 cd
52 scp fastdfs-nginx-module.tar.gz nginx-1.14.0.tar.gz [email protected]:/root/

5.Nginx主配置文件修改 (两台都改)
[root@localhost ~]# vim /usr/local/nginx/conf/nginx.conf
在原来的server上添加
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/M00/ {
ngx_fastdfs_module; #nginx拓展模块
}
}

6、启动服务
启动storaged server(两台都要启动)
[root@localhost fdfs]# /etc/init.d/fdfs_storaged start
Fastdfs architecture
启动nginx(两台都启动)
[root@localhost ~]# /usr/local/nginx/sbin/nginx
Fastdfs architecture

在track上看一下日志
[root@localhost fdfs]# cd /storage/fastdfs/logs/
[root@localhost logs]# cat trackerd.log
Fastdfs architecture

测试一下
Fastdfs architecture
修改第一台的client.conf.sample配置文件
[root@localhost ~]# cd /etc/fdfs/
[root@localhost fdfs]# vim client.conf.sample
base_path=/storage/fastdfs #10
tracker_server=192.168.1.20:22122 #14
tracker_server=192.168.1.30:22122 #15
上传一张图片到storage (第一台)
[root@localhost ~]# fdfs_upload_file /etc/fdfs/client.conf.sample 鲸鱼.png (这个id最好放在一个文件里方便查找)
Fastdfs architecture
在storage上查看一下
[root@localhost data]# cd /storage/fastdfs/data/00/00
[root@localhost 00]# ls
Fastdfs architecture
浏览器访问一下
http://192.168.1.50:8888/group2/M00/00/00/wKgBMl3cpCWAZGQIADuP0gQAyTs723.png
Fastdfs architecture
下载并改名刚刚传上去的图片
[root@localhost ~]# fdfs_download_file /etc/fdfs/client.conf.sample group2/M00/00/00/wKgBMl3coGKACR1RADuP0gQAyTs874.png xgp.png
Fastdfs architecture

删除刚刚上传的图片
[root@localhost ~]# fdfs_delete_file /etc/fdfs/client.conf.sample group2/M00/00/00/wKgBMl3coGKACR1RADuP0gQAyTs874.png

三,配置nginx反向代理服务器 (第一台)
在http模块中添加
[root@localhost nginx-1.15.4]# vim /usr/local/nginx/conf/nginx.conf
upstream fdfs_group1 { #设置group1的服务器 20
server 192.168.1.40:8888 weight=1 max_fails=2 fail_timeout=30s;
}
upstream fdfs_group2 {
server 192.168.1.50:8888 weight=1 max_fails=2 fail_timeout=30s;
}
#下边添加两个location
location ~ /group1(/) { #48
proxy_pass http://fdfs_group1;
}
location ~ /group2(/
) {
proxy_pass http://fdfs_group2;
}
启动nginx
[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# netstat -anpt | grep 80

浏览器查看一下,还是用刚刚那个id(需要重新上传一下)

[root @ localhost ~] # fdfs_upload_file /etc/fdfs/client.conf.sample Whale .png
group2 / M00 / 00/00 / wKgBMl3cpCWAZGQIADuP0gQAyTs723.png
browser to visit : http://192.168.1.10/group2/M00/00/ 00 / wKgBMl3cpCWAZGQIADuP0gQAyTs723.png
Fastdfs architecture
Fastdfs architecture

Experiment completed

Guess you like

Origin blog.51cto.com/14320361/2453670