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.zipcd libfastcommon-master./make.sh./make.sh installtar zxvf FastDFS_v5.07.tar.gzcd FastDFS./make.sh./make.sh installcd /cacti/FastDFS/confmkdir -p /home/yuqing/fastdfsln -s /cacti/FastDFS/conf/tracker.conf /etc/fdfs/egrep -v "#" /etc/fdfs/tracker.confdisabled=falsebind_addr=port=22122connect_timeout=30network_timeout=60base_path=/fastdfsmax_connections=256accept_threads=1work_threads=4store_lookup=2store_group=group2store_server=0store_path=0download_server=0reserved_storage_space = 10%log_level=inforun_by_group=run_by_user=allow_hosts=*sync_log_buff_interval = 10check_active_interval = 120thread_stack_size = 64KBstorage_ip_changed_auto_adjust = truestorage_sync_file_max_delay = 86400storage_sync_file_max_time = 300use_trunk_file = false slot_min_size = 256slot_max_size = 16MBtrunk_file_size = 64MBtrunk_create_file_advance = falsetrunk_create_file_time_base = 02:00trunk_create_file_interval = 86400trunk_create_file_space_threshold = 20Gtrunk_init_check_occupying = falsetrunk_init_reload_from_binlog = falsetrunk_compress_binlog_min_interval = 0use_storage_id = falsestorage_ids_filename = storage_ids.confid_type_in_filename = ipstore_slave_file_use_link = falserotate_error_log = falseerror_log_rotate_time=00:00rotate_error_log_size = 0log_file_keep_days = 0use_connection_pool = falseconnection_pool_max_idle_time = 3600http.server_port=8080http.check_alive_interval=30http.check_alive_type=tcphttp.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.conftracker_server=192.168.12.22:22122(改成你tracker服务器的ip)egrep -v "#" /etc/fdfs/storage.confdisabled=falsegroup_name=group1bind_addr=client_bind=trueport=23000connect_timeout=30network_timeout=60heart_beat_interval=30stat_report_interval=60base_path=/fastdfsmax_connections=256buff_size = 256KBaccept_threads=1work_threads=4disk_rw_separated = truedisk_reader_threads = 1disk_writer_threads = 1sync_wait_msec=50sync_interval=0sync_start_time=00:00sync_end_time=23:59write_mark_file_freq=500store_path_count=1store_path0=/fastdfssubdir_count_per_path=256tracker_server=192.168.12.22:22122log_level=inforun_by_group=run_by_user=allow_hosts=*file_distribute_path_mode=0file_distribute_rotate_count=100fsync_after_written_bytes=0sync_log_buff_interval=10sync_binlog_buff_interval=10sync_stat_file_interval=300thread_stack_size=512KBupload_priority=10if_alias_prefix=check_file_duplicate=0file_signature_method=hashkey_namespace=FastDFSkeep_alive=0use_access_log = falserotate_access_log = falseaccess_log_rotate_time=00:00rotate_error_log = falseerror_log_rotate_time=00:00rotate_access_log_size = 0rotate_error_log_size = 0log_file_keep_days = 0file_sync_skip_invalid_record=falseuse_connection_pool = falseconnection_pool_max_idle_time = 3600http.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.confconnect_timeout=30network_timeout=60base_path=/home/yuqing/fastdfstracker_server=192.168.12.22:22122log_level=infouse_connection_pool = falseconnection_pool_max_idle_time = 3600load_fdfs_parameters_from_tracker=falseuse_storage_id = falsestorage_ids_filename = storage_ids.confhttp.tracker_server_port=80/usr/bin/fdfs_test /etc/fdfs/client.conf upload test.jpg This is FastDFS client test program v5.07Copyright (C) 2008, Happy Fish / YuQingFastDFS may be copied only under the terms of the GNU GeneralPublic 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: 0tracker_query_storage_store_list_without_group: server 1. group_name=, ip_addr=192.168.12.25, port=23000group_name=group1, ip_addr=192.168.12.25, port=23000storage_upload_by_filenamegroup_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpgsource ip address: 192.168.12.25file timestamp=2015-12-05 22:46:22file size=1354file crc32=1635612871example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpgstorage_upload_slave_by_filenamegroup_name=group1, remote_filename=M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpgsource ip address: 192.168.12.25file timestamp=2015-12-05 22:46:22file size=1354file crc32=1635612871example file url: http://192.168.12.25/group1/M00/00/00/wKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg查看原图ls /fastdfs/data/00/00wKgMGVZi9umANr4BAAAFSmF9eMc486.jpg wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpgwKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg wKgMGVZi-L6AAOW6AAAFSmF9eMc904.jpg-mwKgMGVZi-L6AAOW6AAAFSmF9eMc904_big.jpg-mfastdfs命令#上传文件:/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,缺省值为60ssync_wait_msec:如果没有需要同步的文件,对binlog进行轮询的时间间隔,取值大于0,缺省值为100mssync_interval:同步完一个文件后,休眠的毫秒数,缺省值为0为了缩短文件同步时间,可以将上述3个参数适当调小即可
转载于:https://www.cnblogs.com/zclzhao/p/5025229.html
相关资源:JAVA上百实例源码以及开源项目