centos7 下的 FastDFS5.11 的安装与使用

本贴最后更新于 2026 天前,其中的信息可能已经斗转星移

centos7.4 下的 FastDFS5.11 和 tengine2.2.2(nginx1.8.1)的安装与使用

FastDFS 是一款开源的轻量级分布式文件系统,纯 C 实现,支持 Linux、FreeBSD 等 Unix 系统。

类 google FS,不是通用的文件系统,只能通过专有 API 访问。

FastDFS 服务端有两种角色:跟踪器(tracker)和存储节点(storage)。

tracker 主要做调度工作,在访问上起负载均衡的作用,在内存中记录集群中 group 和 storage 的状态信息,是连接 client 和 storage 的枢纽。

storage 存储服务器,文件和文件属性都保存到存储服务器上。

1. 安装 fastdfs

- 下载 libfastcommon 包

https://github.com/happyfish100/libfastcommon/releases

- 下载 fastdfs 源码包

https://github.com/happyfish100/fastdfs/releases

- 安装 libfastcommon

> tar xf libfastcommon-1.0.36.tar.gz
> cd libfastcommon-1.0.36
> ./make.sh
> ./make.sh install

- 安装 fastdfs

> tar xf fastdfs-5.11.tar.gz
> cd fastdfs-5.11
> ./make.sh
> ./make.sh install

如果出现 ioevent.h:82:2: #error port me 这样的错误,请下载最新版的 libfastcommon 并安装。

2. 环境说明

创建两台虚拟主机,IP 分别为 192.168.1.222 和 192.168.1.233,分别安装 fastdfs。

3. fastdfs 的配置文件

配置文件默认在/etc/fdfs 下
默认脚本在/etc/init.d 下

创建两个目录,用来存放数据

> mkdir -p /data/fdfs_tracker
> mkdir -p /data/fdfs_storage

复制配置文件

> cd /etc/fdfs
> cp storage.conf.sample storage.conf
> cp tracker.conf.sample tracker.conf

跟踪器的配置文件 tracker.conf

#绑定IP
bind_addr=
#端口
port=22122
#连接超时时间
connect_timeout=30
#日志数据路径
base_path=/data/fdfs_tracker
#上传文件时选择group的方法
#0:轮询,1:指定组,2:选择剩余空间最大
store_lookup=2
#如果上面的配置是1,那么这里必须指定组名
store_group=group2
#上传文件时选择server的方法
#0:轮询,1:按IP地址排序,2:通过权重排序
store_server=0
#storage上预留空间
reserved_storage_space = 10%

存储节点的配置文件 storage.conf

#storage server所属组名
group_name=group1
#绑定IP
bind_addr=
#storage server的端口
port=23000
#连接超时时间
connect_timeout=30
#日志数据路径
base_path=/data/fdfs_storage/base
#storage path的个数
store_path_count=2
#根据store_path_count的值,就要有storage0到storage(N-1)个
store_path0=/data/fdfs_storage/storage0
store_path1=/data/fdfs_storage/storage1
#跟踪服务器
tracker_server=192.168.1.222:22122
tracker_server=192.168.1.233:22122

创建目录,不然会出错

> mkdir -p /data/fdfs_storage/base
> mkdir -p /data/fdfs_storage/storage0
> mkdir -p /data/fdfs_storage/storage1

启动服务

> /etc/init.d/fdfs_trackerd start
> /etc/init.d/fdfs_storaged start

查看服务是否启动

> ps -ef|grep fdfs
> netstat -nltp

4. 测试 fastdfs

配置 client 文件

> cd /etc/fdfs
> cp client.conf.sample client.conf
> vi client.conf
#存放日志目录
base_path=/data/client
#跟踪服务器
tracker_server=192.168.1.222:22122
tracker_server=192.168.1.233:22122

创建 client 目录

> mkdir -p /data/client

通过 fdfs_upload_file 来测试(如果发生错误,请查看防火墙)

> echo "12345678" >> /data/1.txt
> fdfs_upload_file /etc/fdfs/client.conf /data/1.txt

通过 fdfs_download_file 下载我们刚上传的文件

> fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt

查看文件信息

> fdfs_file_info /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt

追加文件

> echo "hello" >> /data/2.txt
> fdfs_upload_appender /etc/fdfs/client.conf /data/1.txt
> fdfs_append_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3bxCEAcqhAAAAAIk0NhY869.txt /data/2.txt

删除文件

> fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgB3li3a2mAejYPAAAADok0NhY177.txt

查看集群

> fdfs_monitor /etc/fdfs/client.conf

5. 安装 tengine2.2.2 支持 fastdfs

下载 fastdfs-nginx-module:

 http://jaist.dl.sourceforge.net/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz

解压到:

[root@localhost modules]# ll
总用量 20
drwxrwxr-x. 3    500   500    47 5月   4 2014 fastdfs-nginx-module
-rw-r--r--. 1 root   root  17510 5月   5 2014 fastdfs-nginx-module_v1.16.tar.gz
drwxr-xr-x. 3 128966 users   127 1月  26 15:32 ngx_debug_pool
drwxr-xr-x. 9 128966 users   203 1月  26 15:32 ngx_http_lua_module
drwxr-xr-x. 2 128966 users   134 1月  26 15:32 ngx_http_upstream_keepalive_module
drwxr-xr-x. 3 128966 users   121 1月  26 15:32 ngx_slab_stat
[root@localhost modules]# pwd
/usr/local/src/tengine-2.2.2/modules
[root@localhost modules]# 

参考:CentOS 7.1 编译安装 Tengine

需要注意的是:

  • 安装 libfastcommon,fastdfs 后需要 copy 头文件到 fastdfs-nginx-module 里面
cp -r /usr/include/fastdfs/ /usr/local/src/tengine-2.2.2/modules/fastdfs-nginx-module/src/

cp -r /usr/include/fastcommon/* /usr/local/src/tengine-2.2.2/modules/fastdfs-nginx-module/src/

  • 编译命令,增加 ipv6
./configure --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.39 --with-openssl=/usr/local/src/openssl-1.0.2j --with-jemalloc=/usr/local/src/jemalloc-4.4.0 --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_concat_module --with-zlib=/usr/local/src/zlib-1.2.11 --with-ipv6 --add-module=/usr/local/src/tengine-2.2.2/modules/fastdfs-nginx-module/src

make -j8

make install
  • 查看 tengine 安装模块
[root@localhost nginx]# ./sbin/nginx -V
Tengine version: Tengine/2.2.2 (nginx/1.8.1)
built by gcc 4.8.5 20150623 (Red Hat 4.8.5-16) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=www --group=www --with-pcre=/usr/local/src/pcre-8.39 --with-openssl=/usr/local/src/openssl-1.0.2j --with-jemalloc=/usr/local/src/jemalloc-4.4.0 --with-http_gzip_static_module --with-http_realip_module --with-http_stub_status_module --with-http_concat_module --with-zlib=/usr/local/src/zlib-1.2.11 --with-ipv6 --add-module=/usr/local/src/tengine-2.2.2/modules/fastdfs-nginx-module/src
nginx: loaded modules:
nginx:     ngx_core_module (static)
nginx:     ngx_errlog_module (static)
nginx:     ngx_conf_module (static)
nginx:     ngx_dso_module (static)
nginx:     ngx_events_module (static)
nginx:     ngx_event_core_module (static)
nginx:     ngx_epoll_module (static)
nginx:     ngx_procs_module (static)
nginx:     ngx_proc_core_module (static)
nginx:     ngx_openssl_module (static)
nginx:     ngx_regex_module (static)
nginx:     ngx_http_module (static)
nginx:     ngx_http_core_module (static)
nginx:     ngx_http_log_module (static)
nginx:     ngx_http_upstream_module (static)
nginx:     ngx_http_static_module (static)
nginx:     ngx_http_gzip_static_module (static)
nginx:     ngx_http_autoindex_module (static)
nginx:     ngx_http_index_module (static)
nginx:     ngx_http_concat_module (static)
nginx:     ngx_http_auth_request_module (static)
nginx:     ngx_http_auth_basic_module (static)
nginx:     ngx_http_access_module (static)
nginx:     ngx_http_limit_conn_module (static)
nginx:     ngx_http_limit_req_module (static)
nginx:     ngx_http_realip_module (static)
nginx:     ngx_http_geo_module (static)
nginx:     ngx_http_map_module (static)
nginx:     ngx_http_split_clients_module (static)
nginx:     ngx_http_referer_module (static)
nginx:     ngx_http_rewrite_module (static)
nginx:     ngx_http_ssl_module (static)
nginx:     ngx_http_proxy_module (static)
nginx:     ngx_http_fastcgi_module (static)
nginx:     ngx_http_uwsgi_module (static)
nginx:     ngx_http_scgi_module (static)
nginx:     ngx_http_memcached_module (static)
nginx:     ngx_http_empty_gif_module (static)
nginx:     ngx_http_browser_module (static)
nginx:     ngx_http_user_agent_module (static)
nginx:     ngx_http_upstream_hash_module (static)
nginx:     ngx_http_upstream_ip_hash_module (static)
nginx:     ngx_http_upstream_consistent_hash_module (static)
nginx:     ngx_http_upstream_check_module (static)
nginx:     ngx_http_upstream_least_conn_module (static)
nginx:     ngx_http_upstream_keepalive_module (static)
nginx:     ngx_http_upstream_dynamic_module (static)
nginx:     ngx_http_stub_status_module (static)
nginx:     ngx_http_fastdfs_module (static)
nginx:     ngx_http_write_filter_module (static)
nginx:     ngx_http_header_filter_module (static)
nginx:     ngx_http_chunked_filter_module (static)
nginx:     ngx_http_range_header_filter_module (static)
nginx:     ngx_http_gzip_filter_module (static)
nginx:     ngx_http_postpone_filter_module (static)
nginx:     ngx_http_ssi_filter_module (static)
nginx:     ngx_http_charset_filter_module (static)
nginx:     ngx_http_userid_filter_module (static)
nginx:     ngx_http_footer_filter_module (static)
nginx:     ngx_http_trim_filter_module (static)
nginx:     ngx_http_headers_filter_module (static)
nginx:     ngx_http_upstream_session_sticky_module (static)
nginx:     ngx_http_reqstat_module (static)
nginx:     ngx_http_copy_filter_module (static)
nginx:     ngx_http_range_body_filter_module (static)
nginx:     ngx_http_not_modified_filter_module (static)
[root@localhost nginx]# 

  • CentOS

    CentOS(Community Enterprise Operating System)是 Linux 发行版之一,它是来自于 Red Hat Enterprise Linux 依照开放源代码规定释出的源代码所编译而成。由于出自同样的源代码,因此有些要求高度稳定的服务器以 CentOS 替代商业版的 Red Hat Enterprise Linux 使用。两者的不同在于 CentOS 并不包含封闭源代码软件。

    238 引用 • 224 回帖 • 1 关注
  • FastDFS

    FastDFS 是用 C 语言编写的一款开源分布式文件系统。FastDFS 为互联网量身定制,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标,使用 FastDFS 很容易搭建一套高性能的文件服务器集群提供文件上传、下载等服务。

    17 引用 • 10 回帖 • 1 关注

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...