FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等

FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的 metadata进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key valuepair)方式表示,如:width=1024,其中的key为width,value为1024。文件metadata是文件属性列表,可以包含多个键值对。
跟踪器和存储节点都可以由一台或多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或减少。
为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。
在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。
当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。

192.168.12.22(tracker)操作
unzip libfastcommon-master.zip
cd libfastcommon-master
./make.sh
./make.sh install

tar zxvf FastDFS_v5.07.tar.gz
cd FastDFS
./make.sh
./make.sh install
cd /cacti/FastDFS/conf
mkdir -p /home/yuqing/fastdfs
ln -s /cacti/FastDFS/conf/tracker.conf /etc/fdfs/
egrep -v "#" /etc/fdfs/tracker.conf

disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/fastdfs
max_connections=256
accept_threads=1
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 10%
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
sync_log_buff_interval = 10
check_active_interval = 120
thread_stack_size = 64KB
storage_ip_changed_auto_adjust = true
storage_sync_file_max_delay = 86400
storage_sync_file_max_time = 300
use_trunk_file = false
slot_min_size = 256
slot_max_size = 16MB
trunk_file_size = 64MB
trunk_create_file_advance = false
trunk_create_file_time_base = 02:00
trunk_create_file_interval = 86400
trunk_create_file_space_threshold = 20G
trunk_init_check_occupying = false
trunk_init_reload_from_binlog = false
trunk_compress_binlog_min_interval = 0
use_storage_id = false
storage_ids_filename = storage_ids.conf
id_type_in_filename = ip
store_slave_file_use_link = false
rotate_error_log = false
error_log_rotate_time=00:00
rotate_error_log_size = 0
log_file_keep_days = 0
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.server_port=8080
http.check_alive_interval=30
http.check_alive_type=tcp
http.check_alive_uri=/status.html

/etc/init.d/fdfs_trackerd start

------------以上操作在另一台服务器上操作--192.168.12.25(storaged)-------------------------------

ln -s /cacti/FastDFS/conf/storage.conf /etc/fdfs/
vi storage.conf
tracker_server=192.168.12.22:22122(改成你tracker服务器的ip)
egrep -v "#" /etc/fdfs/storage.conf
disabled=false
group_name=group1
bind_addr=
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/fastdfs
max_connections=256
buff_size = 256KB
accept_threads=1
work_threads=4
disk_rw_separated = true
disk_reader_threads = 1
disk_writer_threads = 1
sync_wait_msec=50
sync_interval=0
sync_start_time=00:00
sync_end_time=23:59
write_mark_file_freq=500
store_path_count=1
store_path0=/fastdfs
subdir_count_per_path=256
tracker_server=192.168.12.22:22122
log_level=info
run_by_group=
run_by_user=
allow_hosts=*
file_distribute_path_mode=0
file_distribute_rotate_count=100
fsync_after_written_bytes=0
sync_log_buff_interval=10
sync_binlog_buff_interval=10
sync_stat_file_interval=300
thread_stack_size=512KB
upload_priority=10
if_alias_prefix=
check_file_duplicate=0
file_signature_method=hash
key_namespace=FastDFS
keep_alive=0
use_access_log = false
rotate_access_log = false
access_log_rotate_time=00:00
rotate_error_log = false
error_log_rotate_time=00:00
rotate_access_log_size = 0
rotate_error_log_size = 0
log_file_keep_days = 0
file_sync_skip_invalid_record=false
use_connection_pool = false
connection_pool_max_idle_time = 3600
http.domain_name=
http.server_port=8888
/etc/init.d/fdfs_storaged start

测试上传12.22操作

ln -s /cacti/FastDFS/conf/client.conf /etc/fdfs/
egrep -v "#" /etc/fdfs/client.conf

connect_timeout=30
network_timeout=60
base_path=/home/yuqing/fastdfs
tracker_server=192.168.12.22:22122
log_level=info
use_connection_pool = false
connection_pool_max_idle_time = 3600
load_fdfs_parameters_from_tracker=false
use_storage_id = false
storage_ids_filename = storage_ids.conf
http.tracker_server_port=80

/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.jpg
This is FastDFS client test program v5.07

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.

[2015-12-05 22:46:22] DEBUG - base_path=/fastdfs, 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.12.25, port=23000

group_name=group1, ip_addr=192.168.12.25, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
source ip address: 192.168.12.25
file timestamp=2015-12-05 22:46:22
file size=1354
file crc32=1635612871
example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg
source ip address: 192.168.12.25
file timestamp=2015-12-05 22:46:22
file size=1354
file crc32=1635612871
example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg

查看原图
ls /fastdfs/data/00/00
wKgMGVZi9umANr4BAAAFSmF9eMc486.jpg        wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg
wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg    wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg-m
wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg-m

fastdfs命令
#上传文件:/usr/bin/fdfs_upload_file  <config_file> <local_filename>

#下载文件:/usr/bin/fdfs_download_file <config_file> <file_id> [local_filename]

#删除文件:/usr/bin/fdfs_delete_file <config_file> <file_id>

推荐的FastDFS部署方案
文件上传和删除等操作:使用FastDFS client API,目前提供了C、PHP extension和Java的client API
文件下载采用HTTP方式:使用nginx或者apache扩展模块,不推荐使用FastDFS内置的web server
不要做RAID,直接挂载单盘,每个硬盘作为一个mount point

最大并发连接数设置
参数名:max_connections
缺省值:256
说明:FastDFS采用预先分配好buffer队列的做法,分配的内存大小为: max_connections * buff_size,因此配置的连接数越大,消耗的内存越多。不建议配置得过大,以避免无谓的内存开销

工作线程数设置
参数名: work_threads
缺省值:4
说明:为了避免CPU上下文切换的开销,以及不必要的资源消耗,不建议将本参数设置得过大。为了发挥出多个CPU的效能,系统中的线程数总和,应等于CPU总数。
对于tracker server,公式为:
     work_threads + 1 = CPU数
对于storage,公式为:
    work_threads + 1 + (disk_reader_threads  + disk_writer_threads) * store_path_count  = CPU数

storage目录数设置
参数名:subdir_count_per_path
缺省值:256
说明:FastDFS采用二级目录的做法,目录会在FastDFS初始化时自动创建。存储海量小文件,打开了trunk存储方式的情况下,建议将本参数适当改小,比如设置为32,此时存放文件的目录数为 32 * 32 = 1024。假如trunk文件大小采用缺省值64MB,磁盘空间为2TB,那么每个目录下存放的trunk文件数均值为:2TB / (1024 * 64MB) = 32个

storage磁盘读写线程设置
disk_rw_separated:磁盘读写是否分离
disk_reader_threads:单个磁盘读线程数
disk_writer_threads:单个磁盘写线程数
如果磁盘读写混合,单个磁盘读写线程数为读线程数和写线程数之后
对于单盘挂载方式,磁盘读写线程分别设置为1即可
如果磁盘做了RAID,那么需要酌情加大读写线程数,这样才能最大程度地发挥磁盘性能

storage同步延迟相关设置
sync_binlog_buff_interval:将binlog buffer写入磁盘的时间间隔,取值大于0,缺省值为60s
sync_wait_msec:如果没有需要同步的文件,对binlog进行轮询的时间间隔,取值大于0,缺省值为100ms
sync_interval:同步完一个文件后,休眠的毫秒数,缺省值为0
为了缩短文件同步时间,可以将上述3个参数适当调小即可

fastdfs安装与配置的更多相关文章

  1. FastDFS安装、配置、部署(一)-安装和部署 (转)

    FastDFS是一个开源的,高性能的的分布式文件系统,他主要的功能包括:文件存储,同步和访问,设计基于高可用和负载均衡,FastDFS非常适用于基于文件服务的站点,例如图片分享和视频分享网站 Fast ...

  2. FastDFS安装、配置、部署

    FastDFS是一个开源的,高性能的的分布式文件系统,他主要的功能包括:文件存储,同步和访问,设计基于高可用和负载均衡,FastDFS非常适用于基于文件服务的站点,例如图片分享和视频分享网站. Fas ...

  3. 分布式文件系统FastDFS安装与配置(单机)

    安装包如下:fastdfs-nginx-module_v1.16.tar.gzFastDFS_v5.05.tar.gzlibfastcommon-master.zipnginx-1.8.0.tar.g ...

  4. FastDFS安装和配置,整合Nginx-1.13.3

    目录: 一:下载FastDFS  二:安装FastDFS 三:配置 四:整合Nginx和FastDFS FastDFS is an open source high performance distr ...

  5. django-文件上传和下载--fastDFS安装和配置

    5.1 安装fastdfs依赖包 一:下载安装FDFS依赖: libfastcommon 下载地址:https://codeload.github.com/happyfish100/libfastco ...

  6. FastDFS安装、配置、部署(三)-Storage配置具体解释

    1.基本配置 # is this config file disabled # false for enabled # true for disabled disabled=false # the n ...

  7. [转]Centos7 fastdfs/nginx 安装与配置

    https://blog.csdn.net/alex_bean/article/details/78625131 参考文章 分布式文件系统-FastDFS 使用FastDFS搭建图片服务器单实例篇 C ...

  8. FastDFS安装配置

    FastDFS FastDFS为互联网量身定制,充分考虑了冗余备份.负载均衡.线性扩容等机制,并注重高可用.高性能等指标,使用FastDFS很容易搭建一套高性能的文件服务器集群提供文件上传.下载等服务 ...

  9. FastDFS安装配置手册

    文件服务器分布式系统安装手册 本文档详细的介绍了FastDFS的最小集群安装过程.集群环境如下: tracker:20.2.64.133 .用于调度工作,在访问上起负载均衡的作用. group1: s ...

随机推荐

  1. Location 对象的assign()和replace()有什么区别?

    window.location.assign(url) : 加载 URL 指定的新的 HTML 文档. 就相当于一个链接,跳转到指定的url,当前页面会转为新页面内容,可以点击后退返回上一个页面. w ...

  2. 160606、springmvc中使用Spring Mobile

    springmobile特点: 1.客户端设备识别:识别结果只有3种类型:NORMAL(非手机设备).MOBILE(手机设备).TABLET(平板电脑). 2.网站偏好设置:Spring 通过设备识别 ...

  3. java开源模板引擎

      Velocity  Velocity是一个基于java的模板引擎(template engine).它允许任何人仅仅简单的使用模板语言(template language)来引用由java代码定义 ...

  4. poj3233—Matrix Power Series

    题目链接:http://poj.org/problem?id=3233 题目意思:给一个矩阵n*n的矩阵A和一个k,求一个式子 S = A + A2 + A3 + … + Ak. 这个需要用到等比数列 ...

  5. Quick UDP Internet Connections 让互联网更快的协议,QUIC在腾讯的实践及性能优化

    https://mp.weixin.qq.com/s/44ysXnVBUq_nJByMyX9n5A 让互联网更快:通往QUIC之路 原创: 史天 翻译 云技术实践 8月15日 QUIC(Quick U ...

  6. CentOS安装python-2.7+安装pip-10.0.0

    注:以下所有操作均在CentOS 6.8 x86_64位系统下完成. 首先查看当前系统预装的python版本: # whereis python python2: /usr/bin/python2 / ...

  7. IBM DEVOPS IN CLOUD--chaos monkey

  8. Buy a home in AU

    澳洲留学生买房的几点注意事项: 1. 新房.楼花.或者买地建房,完全不受限制,国民待遇,是政府鼓励的. 2. 留学生签证剩余超12个月,可以购买二手房,但是只能自住不能出租. 3. 银行可以提供50% ...

  9. 出现unmapped spring configuration files found

    intell idea启动出现unmapped spring configuration files found提示. 把spring里面的内容都打勾.

  10. SpringBoot 与 Web开发

    1. SpringBoot 静态资源映射规则 webjars:以JAR包的方式引入静态资源; 所有/webjars/**,都去classpath:/META-INF/resources/webjars ...