1。前言FastDFS是一个管理文件的开源轻量级分布式文件系统。其功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适用于以文件为载体的在线服务,如相册网站、视频网站等。FastDFS为互联网量身打造,充分考虑冗余备份、负载均衡、线性扩展等机制,注重高可用、高性能等指标。使用FastDFS很容易搭建一套高性能的文件服务器集群,提供文件上传下载等服务。2、FastDFS简介是一个开源的轻量级分布式文件系统,纯C语言实现,支持linux、freeBSD等Unix系统。这种分布式存储更适合大小在4kb到500MB之间的文件存储。三个角色:1)client2)trackertrackingserver3)storagestorageserver客户端请求-trackingserver-分配一个group给client-最终client写入数据到storagegrouptrackingserver:主要负责调度工作,起到作用访问时的负载均衡,在内存中记录集群中的组和存储服务器的状态信息,并将客户端与组和存储中心连接存储服务器:存储服务器,文件和文件属性存储在存储FastDFS上传服务器上机制:FastDFS下载机制:3.FastDFS安装准备使用两台虚拟机模拟环境fastdfs-1-1192.168.1.128fastdfs-1-1192.168.1.129yuminstallgit-y下载官网:https://github.com/happyfish100下载并安装依赖包libfastcommon.git[root@fastdfs-1-1src]#gitclonehttps://github.com/happyfish100/libfastcommon.git[root@fastdfs-1-1src]#cdlibfastcommon/[root@fastdfs-1-1libfastcommon]#lltotal36drwxr-xr-x2rootroot4096Mar607:13doc-rw-r--r--1rootroot7939Mar607:13HISTORY-rw-r--r--1rootroot566Mar607:13INSTALL-rw-r--r--1rootroot1494Mar607:13libfastcommon.spec-rwxr-xr-x1root根3099Mar607:13make.shdrwxr-xr-x2rootroot4096Mar607:13php-fastcommon-rw-r--r--1root2763Mar607:13READMEdrwxr-xr-x3rootroot4096Mar607:13src[root@fastdfs-1-1libfastcommon]#./make.sh[root@fastdfs-1-1libfastcommon]#./make.shinstall4、FastDFS安装发布下载安装fastdfs服务[root@fastdfs-1-1src]#wgethttps://github.com/happyfish100/fastdfs/archive/V5.09.tar.gz[root@fastdfs-1-1src]#lltotal336-rw-r--r--1rootroot335132Mar607:30fastdfs-5.09.tar.gzdrwxr-xr-x6rootroot4096Mar607:23libfastcommon[root@fastdfs-1-1src]#tarzxffastdfs-5.09.tar.gz[root@fastdfs-1-1src]#cdfastdfs-5.09[root@fastdfs-1-1fastdfs-5.09]#./make.sh[root@fastdfs-1-1fastdfs-5.09]#./make.shinstall[root@fastdfs-1-1src]#ll/etc/fdfs/total24-rw-r--r--1rootroot1461Mar607:32client.conf.sample-rw-r--r--1rootroot7927Mar607:32storage.conf.sample-rw-r--r--1rootroot105Mar607:32storage_ids.conf.sample-rw-r--r--1rootroot7318Mar607:32tracker.conf.sample[root@fastdfs-1-1src]#ll/usr/bin/fdfs_fdfs_appender_testfdfs_download_filefdfs_test1fdfs_appender_test1fdfs_file_infofdfs_trackerdfdfs_append_filefdfs_monitorfdfs_upload_appenderfdfs_crc32fdfs_storagedfdfs_upload_filefdfs_delete_filefdfs_test修改默认路径[root@fastdfs-1-1src]#sed-i's#/usr/local/bin#/usr/bindf#ind_fit.@fastdfs-1-1src]#sed-i's#/usr/local/bin#/usr/bin#g'/etc/init.d/fdfs_trackerd创建数据目录[root@fastdfs-1-1fdfs]#mkdir/fdfs/{tracker,storage}-p[root@fastdfs-1-1fdfs]#mkdir/fdfs/storage/base-p[root@fastdfs-1-1fdfs]#mkdir/fdfs/storage/store-p[root@fastdfs-1-1fdfs]#ll/fdfs/total8drwxr-xr-x2rootroot4096Mar607:42storagedrwxr-xr-x2rootroot4096Mar607:42tracker修改配置文件[root@fastdfs-1-1fdfs]#egrep-v"^#|^$"tracker.confdisabled=falsebind_addr=#绑定IPport=22122#端口connect_timeout=30network_timeout=60base_path=/fdfs/tracker#存储路径max_connections=256accept_threads=1work_threads=4min_buff_size=8KBmax_buff_size=128KBstore_lookup=2#存储方式store_group=group2#上传哪个组filestore_server=0#哪个storageservertouploadfilestore_path=0????download_server=0??#whichstorageservertodownloadfilereserved_storage_space=10%??#agroup<=reserved_storage_space,保留的空间大小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=falseslot_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[root@fastdfs-1-2fdfs]#/etc/init.d/fdfs_trackerdstartStartingFastDFStrackerserver:[root@fastdfs-1-2fdfs]#lsof-i:22122COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEfdfs_trac5913root5uIPv4307010t0TCP*:22122(LISTEN)[root@fastdfs-1-1fdfs]#egrep-v"^#|^$"storage.confdisabled=falsegroup_name=group1bind_addr=client_bind=trueport=23000connect_timeout=30network_timeout=60heart_beat_interval=30stat_report_interval=60base_path=/fdfs/storage/basemax_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=/fdfs/storage/storesubdir_count_per_path=256tracker_server=192.168.1.128:22122tracker_server=192.168.1.129: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#注:两台服务器保持一致即可[root@fastdfs-1-1fdfs]#/etc/init.d/fdfs_storagedstartStartingFastDFS存储服务器:查看端口[root@fastdfs-1-1fdfs]#lsof-i:22122COMMANDPIDUSERFDTYPEDEVICESIZE/OFFNODENAMEfdfs_trac3622根5UIPV4323950T0TCP*:22122(听)FDFS_TRAC3622根18WIPV41000790T0TCP192.168.1.128:38516-192.192.168.1.168.1.129:22222222222222222222222222222222222.>192.168.1.129:40755(成立)FDFS_TRAC3622根22UIPV41000190T0TCP192.168.1.1.128:221221222-192.192.168.1.1.128:46962(建立)1000.1100.120.100.111ipvs_stor36440ip.stor3640ipper3640ipper3640ipp:22122(ESTABLISHED)fdfs_stor3640root21uIPv41000430t0TCP192.168.1.128:46962->192.168.1.128:22122(ESTABLISHED)[root@fastdfs-1-1fdfs]#lsof-i:23000PIDCOMMANDICEDEVICEUSMANDIZE/offnodenamefdfs_stor3640根5UIPV41000240T0TCP*:inovaport1(listing)FDFS_STOR3640root19UIPV41000400T0TCP192.168.1.1.1.128:Iinovaport1-1-1-192.168.1.168.1.168.1.1.1129:364forterintyterfor1.128:50933->192.168.1.129:inovaport1(已建立)5文件修改如下[root@fastdfs-1-1~]#egrep-v"^#|^$"/etc/fdfs/client.confconnect_timeout=30network_timeout=60base_path=/tmptracker_server=192.168.1.128:22122tracker_server=192.168.1.129: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测试上传文件[root@fastdfs-1-1~]#fdfs_upload_fileUsage:fdfs_upload_file
