设为首页 收藏本站
查看: 818|回复: 0

[经验分享] 分布式文件系统FastDFS介绍安装配置

[复制链接]

尚未签到

发表于 2019-1-31 14:06:15 | 显示全部楼层 |阅读模式
  分布式文件系统FastDFS介绍安装配置 引自:http://www.ttlsa.com/archives/301
一.介绍
FastDFS是一个开源的轻量级分布式文件系统,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。
FastDFS有两个角色:跟踪器(tracker)和存储节点(storage)。
跟踪器主要做调度工作,在访问上起负载均衡的作用。
存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,同时对文件的metadata进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key valuepair)方式表示,如:width=1024,其中的key为width,value为1024。文件metadata是文件属性列表,可以包含多个键值对。
FastDFS架构图如下:

  跟踪器和存储节点都可以由一台或多台服务器构成。跟踪器和存储节点中的服务器均可以随时增加或下线而不会影响线上服务。其中跟踪器中的所有服务器都是对等的,可以根据服务器的压力情况随时增加或减少。
为了支持大容量,存储节点(服务器)采用了分卷(或分组)的组织方式。存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。
FastDFS中的文件标识分为两个部分:卷名和文件名,二者缺一不可。
  上传文件交互过程:

  1. client询问tracker上传到的storage,不需要附加参数;
 2. tracker返回一台可用的storage;
 3. client直接和storage通讯完成文件上传。
  下载文件交互过程:

  1. client询问tracker下载文件的storage,参数为文件标识(卷名和文件名);
 2. tracker返回一台可用的storage;
 3. client直接和storage通讯完成文件下载。
  同步机制
同一组内的storage server之间是对等的,文件上传、删除等操作可以在任意一台storage server上进行;
文件同步只在同组内的storage server之间进行,采用push方式,即源服务器同步给目标服务器;
源头数据才需要同步,备份数据不需要再次同步,否则就构成环路了;
上述第二条规则有个例外,就是新增加一台storage server时,由已有的一台storage server将已有的所有数据(包括源头数据和备份数据)同步给该新增服务器。
  二.安装
# wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.14-stable.tar.gz
# tar zxvf libevent-2.0.14-stable.tar.gz -C ../software/
# ./configure --prefix=/usr/local/libevent-2.0.14
# make
# make install
  # wget http://fastdfs.googlecode.com/files/FastDFS_v3.02.tar.gz
# tar zxvf FastDFS_v3.02.tar.gz -C ../software/
# ./make.sh C_INCLUDE_PATH=/usr/local/libevent-2.0.14/include LIBRARY_PATH=/usr/local/libevent-2.0.14/lib
# ./make.sh install
【注意:】
如果要使fastdfs支持web和开机自动脚本(默认是不支持的),需要修改make.sh文件
#WITH_HTTPD=1
#WITH_LINUX_SERVICE=1
  配置文件说明
【tracker.conf】
# is this config file disabled
# false for enabled
# true for disabled
disabled=false  //配置文件是否生效,false生效,true不生效
  # bind an address of this host
# empty for bind all addresses of this host
bind_addr=  //绑定ip
  # the tracker server port
port=22122  //指定端口
  # connect timeout in seconds
# default value is 30s
connect_timeout=30  //连接超时时间,针对socket套接字
  # network timeout in seconds
# default value is 30s
network_timeout=60  //tracker server网络超时时间
  # the base path to store data and log files
base_path=/data/fastdfs  //目录地址,目录结构如下:
${base_path}
|__data
| |__storage_groups.dat:存储分组信息
| |__storage_servers.dat:存储服务器列表
|__logs
|__trackerd.log:tracker server日志文件
数据文件storage_groups.dat和storage_servers.dat中的记录之间以换行符(\n)分隔,字段之间以西文逗号(,)分隔。
storage_groups.dat中的字段依次为:
1. group_name:组名
2. storage_port:storage server端口号
  storage_servers.dat中记录storage server相关信息,字段依次为:
1. group_name:所属组名
2. ip_addr:ip地址
3. status:状态
4. sync_src_ip_addr:向该storage server同步已有数据文件的源服务器
5. sync_until_timestamp:同步已有数据文件的截至时间(UNIX时间戳)
6. stat.total_upload_count:上传文件次数
7. stat.success_upload_count:成功上传文件次数
8. stat.total_set_meta_count:更改meta data次数
9. stat.success_set_meta_count:成功更改meta data次数
10. stat.total_delete_count:删除文件次数
11. stat.success_delete_count:成功删除文件次数
12. stat.total_download_count:下载文件次数
13. stat.success_download_count:成功下载文件次数
14. stat.total_get_meta_count:获取meta data次数
15. stat.success_get_meta_count:成功获取meta data次数
16. stat.last_source_update:最近一次源头更新时间(更新操作来自客户端)
17. stat.last_sync_update:最近一次同步更新时间(更新操作来自其他storage server的同步)
  # max concurrent connections this server supported
max_connections=256  //最大连接数量
  # work thread count, should = this bytes
# default value is 0 (never call fsync)
fsync_after_written_bytes=0  //当写入大文件时,每写入N个字节,调用一次系统函数fsync将内容强制同步到磁盘。0表示不调用fsync
  # sync log buff to disk every interval seconds
# default value is 10 seconds
sync_log_buff_interval=10  //同步日志到磁盘的时间间隔
  # sync binlog buff / cache to disk every interval seconds
# this parameter is valid when write_to_binlog set to 1
# default value is 60 seconds
sync_binlog_buff_interval=10  //同步binlog到磁盘的时间间隔
  # sync storage stat info to disk every interval seconds
# default value is 300 seconds
sync_stat_file_interval=300  //把storage的状态信息同步到磁盘的时间间隔
  # thread stack size, should >= 512KB
# default value is 512KB
thread_stack_size=512KB  //线程堆大小
  # the priority as a source server for uploading file.
# the lower this value, the higher its uploading priority.
# default value is 10
upload_priority=10  //上传优先级,值越小优先级越高
  # the NIC alias prefix, such as eth in Linux, you can see it by ifconfig -a
# multi aliases split by comma. empty value means auto set by OS type
# default values is empty
if_alias_prefix=
  # if check file duplicate, when set to true, use FastDHT to store file indexes
# 1 or yes: need check
# 0 or no: do not check
# default value is 0
check_file_duplicate=0  //是否检测上传文件已经存在。如果设置为true需要使用fastdht。如果已经存在,则建立一个符号链接以节省磁盘空间
  # namespace for storing file indexes (key-value pairs)
# this item must be set when check_file_duplicate is true / on
key_namespace=FastDFS  //当check_file_duplicate=1时,在fastdht中的命名空间
  # set keep_alive to 1 to enable persistent connection with FastDHT servers
# default value is 0 (short connection)
keep_alive=0  //与fastdht server的连接方式。0短连接,1长连接
  # you can use "#include filename" (not include double quotes) directive to
# load FastDHT server list, when the filename is a relative path such as
# pure filename, the base path is the base path of current/this config file.
# must set FastDHT server list when check_file_duplicate is true / on
# please see INSTALL of FastDHT for detail
##include /home/yuqing/fastdht/conf/fdht_servers.conf
  
#HTTP settings
http.disabled=false
  # use the ip address of this storage server if domain_name is empty,
# else this domain name will ocur in the url redirected by the tracker server
http.domain_name=
  # the port of the web server on this storage server
http.server_port=8888
  http.trunk_size=256KB
  # if need find content type from file extension name
http.need_find_content_type=true
  #use "#include" directive to include HTTP other settings
##include http.conf
  配置实例
【tracker server】
disabled=false
bind_addr=
port=22122
connect_timeout=30
network_timeout=60
base_path=/data/fastdfs
max_connections=256
work_threads=4
store_lookup=2
store_group=group2
store_server=0
store_path=0
download_server=0
reserved_storage_space = 4GB
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
  【storage server】
disabled=false
group_name=group1
bind_addr=192.168.1.101
client_bind=true
port=23000
connect_timeout=30
network_timeout=60
heart_beat_interval=30
stat_report_interval=60
base_path=/data/fastdfs
max_connections=256
buff_size = 256KB
work_threads=4
disk_rw_separated = true
disk_rw_direct = false
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=/data/fastdfs
subdir_count_per_path=256
tracker_server=192.168.1.114: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
key_namespace=FastDFS
keep_alive=0
  启动
【tracker server】
# /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
【storage server】
# /usr/local/bin/fdfs_storaged  /etc/fdfs/storage.conf
  安装nginx的fastdfs-nginx-module模块
# wget http://nginx.org/download/nginx-1.0.8.tar.gz
# tar zxvf nginx-1.0.8.tar.gz -C ../software/
# wget http://fastdfs-nginx-module.googlecode.com/files/fastdfs-nginx-module_v1.08.tar.gz
# tar zxvf fastdfs-nginx-module_v1.08.tar.gz -C ../software/
# apt-get install libpcre3 libpcre3-dev openssl libssl-dev
# ./configure --prefix=/usr/local/nginx-1.0.8 --user=nginx --group=nginx --add-module=/usr/local/src/software/fastdfs-nginx-module/src/
# make
# make install
# cp mod_fastdfs.conf /etc/fdfs/
# vi nginx.conf添加如下内容
location /M00 {
            root /data/fastdfs/data;
            ngx_fastdfs_module;
        }
# ln -s /data/fastdfs/data /data/fastdfs/data/M00
# vim mod_fastdfs.conf
connect_timeout=2
network_timeout=30
base_path=/data/fastdfs
tracker_server=192.168.1.114:22122
storage_server_port=23000
group_name=group1
url_have_group_name = false
store_path_count=1
store_path0=/data/fastdfs
log_level=debug
log_filename=
response_mode=redirect
if_alias_prefix=
http.need_find_content_type=false
# /usr/local/nginx-1.0.8/sbin/nginx -c /usr/local/nginx-1.0.8/conf/nginx.conf
ngx_http_fastdfs_set pid=28525
[2011-10-22 16:39:53] INFO - fastdfs apache / nginx module v1.08, response_mode=redirect, base_path=/data/fastdfs, path_count=1, connect_timeout=2, network_timeout=30, tracker_server_count=1, storage_server_port=23000, group_name=group1, if_alias_prefix=, local_host_ip_count=2, need_find_content_type=0, default_content_type=, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, storage_sync_file_max_delay=86400s
  上传文件
# vim client.conf
connect_timeout=30
network_timeout=60
base_path=/data/fastdfs
tracker_server=192.168.1.114:22122
log_level=info
  # /usr/local/bin/fdfs_test /etc/fdfs/client.conf upload .bashrc
  [2011-10-22 17:24:49] INFO - base_path=/data/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0
  tracker_query_storage_store_list_without_group:
        server 1. group_name=group1, ip_addr=192.168.1.101, port=23000
  group_name=group1, ip_addr=192.168.1.101, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBZU6ii-GamB5eAAALcAZ5KwI.bashrc
source ip address: 192.168.1.101
file timestamp=2011-10-22 17:24:49
file size=2928
file crc32=108604162
file url: http://192.168.1.114/group1/M00/00/00/wKgBZU6ii-GamB5eAAALcAZ5KwI.bashrc
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBZU6ii-GamB5eAAALcAZ5KwI_big.bashrc
source ip address: 192.168.1.101
file timestamp=2011-10-22 17:24:49
file size=2928
file crc32=108604162
file url: http://192.168.1.114/group1/M00/00/00/wKgBZU6ii-GamB5eAAALcAZ5KwI_big.bashrc
  用浏览器访问
http://192.168.1.101/M00/00/00/wKgBZU6ii-GamB5eAAALcAZ5KwI_big.bashrc




运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-670119-1-1.html 上篇帖子: Fastdfs 无法上传文件问题描述及解决方案 下篇帖子: FastDFs 开源的轻量级分布式文件系统部署
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表