分布式文件系统FastDFS部署搭建

文章目录
  1. 1. 简介
  2. 2. FastDFS的架构
  3. 3. 文件上传和下载的交互过程
  4. 4. 搭建Fastdfs环境
    1. 4.1. 安装libfastcommon
    2. 4.2. 安装Fastdfs
    3. 4.3. 修改配置文件
    4. 4.4. 启动Tracker和Storage
    5. 4.5. 上传、删除测试
    6. 4.6. 在121上部署 Storage
  5. 5. 部署Nginx+fastDFS
    1. 5.1. 下载fastdfs-nginx-module
    2. 5.2. 安装和编译Nginx 并添加fastDFS模块
    3. 5.3. 在121上配置nginx
    4. 5.4. 120 上配置nginx
    5. 5.5. 启动Nginx
    6. 5.6. 测试
  6. 6. 配置第二个group
    1. 6.1. 配置Storage
    2. 6.2. 配置Nginx
    3. 6.3. 配置访问120上的Nginx
  7. 7. 后记
  8. 8. 常见问题
    1. 8.1. Storage WAIT_SYNC 问题
  9. 9. 参考资料
简介

FastDFS是一款类Google FS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount使用。准确地讲,Google FS以及FastDFS、mogileFS、HDFS、TFS等类Google FS都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。

FastDFS的架构

下图显示的是FastDFS的系统架构。

图1 FastDFS的系统架构

从图1可以看出,Tracker server之间相互独立,不存在直接联系。客户端和Storage server 主动 连接Tracker server。包括磁盘剩余空间、文件同步状况、文件上传下载次数等统计信息。Storage server会连接集群中所有的Tracker server,向他们报告自己的状态。Storage server启动一个单独的线程来完成对一台Tracker server的连接和定时报告。需要说明的是,一个组包含的Storage server不是通过配置文件设定的,而是通过Tracker server获取到的。
不同组的Storage server之间不会相互通信,同组内的Storage server之间会相互连接进行文件同步。

Storage server采用binlog文件记录文件上传、删除等更新操作。binlog中只记录文件名,不记录文件内容。

文件同步只在同组内的Storage server之间进行,采用push方式,即源头服务器同步给目标服务器。只有源头数据才需要同步,备份数据并不需要再次同步,否则就构成环路了。有个例外,就是新增加一台Storage server时,由已有的一台Storage server将已有的所有数据(包括源头数据和备份数据)同步给该新增服务器。

Storage server中由专门的线程根据binlog进行文件同步。为了最大程度地避免相互影响以及出于系统简洁性考虑,Storage server对组内除自己以外的每台服务器都会启动一个线程来进行文件同步。

文件同步采用增量同步方式,系统记录已同步的位置(binlog文件偏移量)到标识文件中。标识文件名格式:{dest storage IP}_{port}.mark,例如:192.168.1.14_23000.mark。

文件上传和下载的交互过程

接下来我们一起看一下文件上传和下载的交互过程。文件上传和下载流程分别如图2、图3所示。文件上传流程的步骤如下:




使用fastdfs上传文件
  1. Client询问Tracker server上传到的Storage server;

  2. Tracker server返回一台可用的Storage server,返回的数据为该Storage server的IP地址和端口;

  3. Client直接和该Storage server建立连接,进行文件上传,Storage server返回新生成的文件ID,文件上传结束。



使用Fastdfs下载文件

  1. Client询问Tracker server可以下载指定文件的Storage server,参数为文件ID(包含组名和文件名);

  2. Tracker server返回一台可用的Storage server;

  3. Client直接和该Storage server建立连接,完成文件下载。

搭建Fastdfs环境

这里默认关闭了防火墙,并且开启了tracker和storage所需要的端口。tracker默认端口为22122,Storage默认端口为23000

这里我用了两台机器进行搭建192.168.1.120和192.168.1.121,用与搭建1个tracker和2个storage。其中tracker在120上,Storage搭建在120和121上,并且为同一分组。

  1. 192.168.1.120 nginx + Tracker + Storage1
  2. 192.168.1.121 Nginx + Storage2

下面开始搭建:

首先在120机器上进行安装(Tracker Server)

安装libfastcommon

git下载地址:https://github.com/happyfish100/fastdfs.git
解压缩到/data/libfastcommon-master,进入libfastcommon-master,执行

1
2
./make.sh
./make.sh install

确认make没有错误后,执行安装,64位系统默认会复制到/usr/lib64下。
这时候检查/usr/lib/libfastcommon.so是否存在,如果不存在需要设置环境变量或者创建软链接

1
ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

安装Fastdfs

下载 FastDFS 源程序,git下载地址:https://github.com/happyfish100/fastdfs.git
下载之后解压缩到/data/fastdfs-master,然后进入此目录,执行

1
2
3
./make.sh

./make.sh install

确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。

修改配置文件

默认的配置文件安装到/etc/fdfs目录中,如下:

  1. storage.conf.sample Storage的配置文件样例
  2. tracker.conf.sample Tracker的配置文件样例
  3. client.conf.sample Fastdfs客户端的配置文件样例。
  • tracker.conf修改
    首先重命名tracker.conf.sample为tracker.conf,修改其中如下:
    1
    base_path=/data/fastdfs/tracker #用于存放日志。

注意:确保/data/fastdfs/tracker目录存在

  • storage.conf修改
    首先重命名storage.conf.sample为storage.conf,修改其中如下:
    1
    2
    3
    base_path=/data/fastdfs/storage #用于存放日志。
    store_path0=/data/fastdfs/storage #存放数据,若不设置默认为前面那个。
    tracker_server=192.168.1.120:22122 #指定tracker服务器地址。不能是127.0.0.1

注意:确保/data/fastdfs/storage目录存在

  • client.conf修改
    首先重命名storage.conf.sample为storage.conf,修改其中如下:
    1
    2
    base_path=/data/fastdfs/client #用于存放日志。
    tracker_server=192.168.1.120:22122 #指定tracker服务器地址。
启动Tracker和Storage
1
2
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

检查进程,确认是否启动

1
2
3
4
# ps -ef | grep fdfs
root 5980 1 0 19:24 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 6011 1 12 19:24 ? 00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 6021 5958 0 19:24 pts/0 00:00:00 grep --color=auto fdfs

表示启动ok了,若有错误,可以在/usr/fastdfs/tracker/logs 目录下检查日志。

上传、删除测试
  • 上传文件
    使用自带的fdfs_test来测试,使用格式如下:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # fdfs_test

    This is FastDFS client test program v5.12

    Copyright (C) 2008, Happy Fish / YuQing

    FastDFS may be copied only under the terms of the GNU General
    Public License V3, which may be found in the FastDFS source kit.
    Please visit the FastDFS Home Page http://www.csource.org/
    for more detail.

    Usage: fdfs_test <config_file> <operation>
    operation: upload, download, getmeta, setmeta, delete and query_servers

使用以下命令上传文件

1
fdfs_test /etc/fdfs/client.conf upload /data/test.jpeg

输入结果如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
This is FastDFS client test program v5.12

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2018-04-13 22:07:03] DEBUG - base_path=/data/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.1.120, port=23000

group_name=group1, ip_addr=192.168.1.120, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeFrQuYeAATHaAAKE3TYxPy085.jpeg
source ip address: 192.168.1.120
file timestamp=2018-04-13 22:07:03
file size=165085
file crc32=909197101
example file url: http://192.168.1.120/group1/M00/00/00/wKgBeFrQuYeAATHaAAKE3TYxPy085.jpeg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeFrQuYeAATHaAAKE3TYxPy085_big.jpeg
source ip address: 192.168.1.120
file timestamp=2018-04-13 22:07:03
file size=165085
file crc32=909197101
example file url: http://192.168.1.120/group1/M00/00/00/wKgBeFrQuYeAATHaAAKE3TYxPy085_big.jpeg

可以看到,上传ok了,这里会生成两个文件,这是fastdfs的主/从文件特性,以后再介绍。example file url是不能在浏览器中直接打开的,除非配合nginx使用,以后再介绍。

  • 删除文件
    1
    fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgBeFrQuYeAATHaAAKE3TYxPy085.jpeg

至此,我们就已经配置好了120上的 Tracker 和 Storage。

在121上部署 Storage

同样的在121服务器上,按照以上步骤进行fastdfs安装,配置,启动。在121上只需要配置和启动 Storage 就行。其中121上的 Storage 配置文件 /etc/fastdfs/storage.conf 中的 group_name设为group1,于120上的 Storage 相同。

在启动之后使用一下命令查看两个 Storage 是否启动成功,显示以下表示同一个group的两个 Storage 都已经启动成功,并且注册到了 Tracker 服务器上。。

1
2
3
4
# fdfs_monitor /etc/fdfs/client.conf | grep ip_addr

ip_addr = 192.168.1.120 ACTIVE
ip_addr = 192.168.1.121 ACTIVE

这时候我们再使用以下命令上传一个文件,会发现有两个 Storage 可用。

1
fdfs_test /etc/fdfs/client.conf upload /data/1.png

显示如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
This is FastDFS client test program v5.12

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2018-04-16 17:04:59] DEBUG - base_path=/data/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group:
<font color='red'>server 1. group_name=, ip_addr=192.168.1.120, port=23000</font>
server 2. group_name=, ip_addr=192.168.1.121, port=23000

group_name=group1, ip_addr=192.168.1.121, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeVrUZzqAcggmAAAIRpdONjU014.png
source ip address: 192.168.1.121
file timestamp=2018-04-16 17:04:58
file size=2118
file crc32=2538485301
example file url: http://192.168.1.121/group1/M00/00/00/wKgBeVrUZzqAcggmAAAIRpdONjU014.png
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeVrUZzqAcggmAAAIRpdONjU014_big.png
source ip address: 192.168.1.121
file timestamp=2018-04-16 17:04:58
file size=2118
file crc32=2538485301
example file url: http://192.168.1.121/group1/M00/00/00/wKgBeVrUZzqAcggmAAAIRpdONjU014_big.png

默认fastdfs会选择一台机器作为存储,文件上传完毕后,会自动同步到别的 Storage.

到此位置,我们部署了两台位于同一 group的 Storage。

部署Nginx+fastDFS

上面我们已经完成了 Tracker 和 Storage 的部署和配置,但是上传到 Storage 的文件还没办法访问,并且文件在同步的过程中,也会出现未同步完成的情况,所以需要配置Nginx。

Nginx安装fastDFS模块,主要是安装在fastDFS,storage存储服务器上,而不是tracker和client上。 这里主要是安装到120,121上。

目的实际是为了,当输入类似
http://192.168.1.120/group1/M00/00/00/wKgCbFem0l2ALSbFAAEYXfRAMkc536.png
URL地址,其中192.168.1.120 是一个storage服务器。
能够通过nginx的web服务功能,直接返回图片。

注意:全部安装条件在确保之前的fastDFS 的Tracker和storage和client可以正常使用

下载fastdfs-nginx-module

下载地址:https://github.com/happyfish100/fastdfs-nginx-module

1
2
unzip fastdfs-nginx-module-master.zip
cd fastdfs-nginx-module-master

会发现里面有个INSTALL 和 src目录。这个不需要make而是需要重新编译一下storage的Nginx模块

安装和编译Nginx 并添加fastDFS模块
1
2
3
4
cd nginx-1.10.1/
./configure --prefix=/usr/local/nginx --add-module=/data/fastdfs-nginx-module-master/src/
make
make install

其中fastdfs-nginx-module-master是刚才解压的fastdfs模块的绝对路径,就是在编译nginx时候,连同这个模块一起编译。
如果在编译安装的时候报一下错误,说明需要安装相应的library

1
2
3
4
./configure: error: the HTTP rewrite module requires the PCRE library.
You can either disable the module by using --without-http_rewrite_module
option, or install the PCRE library into the system, or build the PCRE library
statically from the source with nginx by using --with-pcre=<path> option.

执行以下命令进行安装:

1
yum -y install pcre-devel openssl openssl-devel

然后重新编译安装。

  • fastdfs-nginx-module 配置文件
    将fastdfs-nginx-module/src/mod_fastdfs.conf 拷贝到/etc/fdfs/下
    1
    cp /data/fastdfs-nginx-module-master/src/mod_fastdfs.conf /etc/fdfs/

修改mod_fastdfs.conf,为如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 保存日志目录,跟storage.conf一致即可
base_path=/data/fastdfs/storage/
tracker_server=192.168.1.120:22122 #tracker服务器的IP地址以及端口号,确保跟storage.conf一致即可
storage_server_port=23000 #storage服务器的端口号,确保跟storage.conf一致即可
group_name=group1 #当前服务器的group名,确保跟storage.conf一致即可
url_have_group_name = true #文件url中是否有group名,这个最好设置为true,这样方便nginx服务器解析
store_path_count=1 #存储路径个数,需要和store_path个数匹配
store_path0=/usr/fastdfs/fastdfs0 #存储路径,跟storage.conf一致即可

group_count = 1 #设置组的个数

[group1]
group_name=group1
storage_server_port=23000
store_path_count=1
store_path0=/usr/fastdfs/fastdfs0

#如果group_count =2 ,那就再配置一个

在121上配置nginx

这里把120作为负载均衡点,所有的文件访问都是访问120上,然后通过nginx 转发。

1
vim /usr/local/nginx/conf/nginx.conf

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

server {
listen 80;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location ~ /group1/M00 {
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}

location / {
root html;
index index.html index.htm;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
120 上配置nginx
1
vim /usr/local/nginx/conf/nginx.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#user  nobody;
worker_processes 1;

#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;

#pid logs/nginx.pid;


events {
worker_connections 1024;
}


http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

upstream fdfs_group1 {
server 192.168.1.120:8080 weight=1 max_fails=2 fail_timeout=30s;
#server 192.168.1.121 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location /group1/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group1;
expires 30d;
}
#其他配置
location / {
root html;
index index.html index.htm;
}
}
server {
listen 8080;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location /group1/M00{
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
启动Nginx
1
# /usr/local/nginx/bin/nginx

观察/usr/local/nginx/logs/errors.log 是否有ERROR存在,如果有类似如下错误:

1
2
3
4
ERROR - file: ini_file_reader.c, line: 315, include file "http.conf" not exists, line: "#include http.conf"

ERROR - file: /root/Open_Package/fastdfs-nginx-module/src/common.c, line: 155, load conf file "/etc/fdfs/mod_fastdfs.conf" fail, ret code: 2
2016/08/06 23:51:13 [alert] 12734#0: worker process 12735 exited with fatal code 2 and cannot be respawned

类似这种错误会导致nginx-worker启动失败,致使nginx无法提供web服务。
表示/etc/fdfs/下缺少http.conf 和mime.types文件
从fastdfs-master/conf/http.conf 拷贝到/etc/fdfs/下 从nginx-1.12.2/conf/mime.types 拷贝到/etc/fdfs/下。

1
2
cp /data/fastdfs-master/conf/http.conf /etc/fdfs/
cp /data/nginx-1.12.2/conf/mime.types /etc/fdfs/

测试

最后通过上传文件完成测试,如下:

1
fdfs_test /etc/fdfs/client.conf upload /data/test.jpeg

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
This is FastDFS client test program v5.12

Copyright (C) 2008, Happy Fish / YuQing

FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/
for more detail.

[2018-04-16 18:30:45] DEBUG - base_path=/data/fastdfs/client, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.1.120, port=23000
server 2. group_name=, ip_addr=192.168.1.121, port=23000

group_name=group1, ip_addr=192.168.1.120, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeFrUe1WAc3GuAAEyOqIsuc852.jpeg
source ip address: 192.168.1.120
file timestamp=2018-04-16 18:30:45
file size=78394
file crc32=2720840143
example file url: http://192.168.1.120/group1/M00/00/00/wKgBeFrUe1WAc3GuAAEyOqIsuc852.jpeg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBeFrUe1WAc3GuAAEyOqIsuc852_big.jpeg
source ip address: 192.168.1.120
file timestamp=2018-04-16 18:30:45
file size=78394
file crc32=2720840143
example file url: http://192.168.1.120/group1/M00/00/00/wKgBeFrUe1WAc3GuAAEyOqIsuc852_big.jpeg

表示文件上传成功,通过浏览器访问
http://192.168.1.120/group1/M00/00/00/wKgBeFrUe1WAc3GuAAEyOqIsuc852.jpeg
看到图片显示出来,表示storage已经成功配置nginx服务。
如图所示:

完成搭建。

配置第二个group

新增一台机器,ip为192.168.1.122,按照以上步骤在122机器上安装 libfastcommon, Storage,fastdfs-nginx-module-master,Nginx。

配置Storage

按照第一台Storage配置文件配置/etc/fdfs/storage.conf

1
vim /etc/fdfs/storage.conf

修改group_name为group2

1
group_name=group2

然后启动Storage。
在120上查看是否已经连接到tracker上。

1
2
3
4
5
# fdfs_monitor /etc/fdfs/client.conf | grep ip_addr

ip_addr = 192.168.1.120 ACTIVE
ip_addr = 192.168.1.121 ACTIVE
ip_addr = 192.168.1.122 ACTIVE

配置Nginx

参照121机器的nginx配置

配置访问120上的Nginx

如下,添加group2的访问

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
http {
include mime.types;
default_type application/octet-stream;

#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';

#access_log logs/access.log main;

sendfile on;
#tcp_nopush on;

#keepalive_timeout 0;
keepalive_timeout 65;

#gzip on;

upstream fdfs_group2 {
server 192.168.1.122 weight=1 max_fails=2 fail_timeout=30s;
}
upstream fdfs_group1 {
server 192.168.1.120:8080 weight=1 max_fails=2 fail_timeout=30s;
server 192.168.1.121 weight=1 max_fails=2 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;


location /group2/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group2;
expires 30d;
}
location /group1/M00 {
proxy_next_upstream http_502 http_504 error timeout invalid_header;
proxy_pass http://fdfs_group1;
expires 30d;
}
#其他配置
location / {
root html;
index index.html index.htm;
}
}
server {
listen 8080;
server_name localhost;

#charset koi8-r;

#access_log logs/host.access.log main;

location /group1/M00{
root /data/fastdfs/storage/data;
ngx_fastdfs_module;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}

通过上传文件测试以及通过nginx访问进行测试。

完成多group配置。

后记

后来发现有篇博文写的也是很仔细,推荐大家也看一下:

分布式文件系统FastDFS实践 https://t.hao0.me/storage/2016/05/10/fastdfs-practice.html

常见问题
Storage WAIT_SYNC 问题

正常状态的 Storage 为ACTIVE状态,但有时 Storage 会变为WAIT_SYNC,状态,并且一直不再变化。网上一般是这样处理的,

1
2
3
4
5
6
#从集群中删除
fdfs_monitor /etc/fdfs/client.conf delete group1 10.120.151.114
#在114服务器中,删除数据文件夹
rm -rf /home/storage1/fastdfs/data
#重启114节点
fdfs_storaged /etc/fdfs/storage.conf

但是如果同步的文件很多,这样会耗时,一般只需要从集群中删除,然后在重启被删除的 Storage 即可。

参考资料

https://aceld.gitbooks.io/project-d-storage/content/12_fastdfsan_zhuang.html
https://blog.csdn.net/pzw_0612/article/details/52610328
https://t.hao0.me/storage/2016/05/10/fastdfs-practice.html

分享到