
1.FastDFS介紹
FastDFS是一款開源的輕量級分布式文件系統,
-純C實現,支持Linux,FreeBSD等UNIX系統,
-類goolge FS,不是通用的文件系統,只能通過專有API訪問,目前提供了C,java和PHP API
-為互聯網應用量身定做,追求高性能和高擴展
-FastDFS可以看做是基於文件的key value pair存儲系統,稱作為分布式文件存儲服務更合適
2.FastDFS github地址
https://github.com/happyfish100/
3.FastDFS上傳原理
- storage定時向tracker上傳狀態信息
- client上傳連接請求到tracker
- tracker查詢可用的storage,並返回storage的ip和端口
- 上傳文件fIlecontent和meta data
- 生成file_id,將上傳的內容寫入磁盤,並返回file_id路徑和文件名
4.安裝FastDFS依賴lib包
cd /usr/local/src/ git clone https://github.com/happyfish100/libfastcommon.git cd libfastcommon/ ./make.sh ./make.sh install
5.安裝FastDFS--v5.08
cd /usr/local/src wget http://nchc.dl.sourceforge.net/project/fastdfs/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.08/FastDFS_v5.08.tar.gz tar -zxvf FastDFS_v5.08.tar.gz cd FastDFS ./make.sh ./make.sh install
6.tracker配置
sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_trackerd mkdir -p /data/fastdfs/tracker cd /etc/fdfs/ cp tracker.conf.sample tracker.conf vim tracker.conf disabled=false #啟用配置文件 port=22122 #設置 tracker 的端口號 base_path=/data/fastdfs/tracker #設置 tracker 的數據文件和日志目錄(需預先創建) http.server_port=8888 #設置 http 端口號 http.server_port=8888 #指的是在tracker服務器上啟動http服務進程,如:apache或者nginx 啟動時所監聽的端口
/etc/init.d/fdfs_trackerd start
7.storage配置
sed -i 's#/usr/local/bin/#/usr/bin/#g' /etc/init.d/fdfs_storaged mkdir -p /data/fastdfs/base mkdir -p /data/fastdfs/data cd /etc/fdfs/ cp storage.conf.sample storage.conf vim storage.conf disabled=false #啟用配置文件 group_name=group1 #組名,根據實際情況修改 port=23000 #設置 storage 的端口號 base_path=/data/fastdfs/base #設置 storage 的日志目錄(需預先創建) store_path_count=1 #存儲路徑個數,需要和 store_path 個數匹配 store_path0=/data/fastdfs/date #存儲路徑 tracker_server=10.10.10.81:22122 #tracker 服務器的 IP 地址和端口號 http.server_port=8888 #設置storage上啟動的http服務的端口號,如安裝的nginx的端口號
/etc/init.d/fdfs_storage start
12.客戶端文件配置
[root@localhost fdfs]# cp client.conf.sample cilent.conf [root@img01 fdfs]# grep -Ev '^$|^#' /etc/fdfs/client.conf connect_timeout=30 network_timeout=60 base_path=/data/fastdfs/fdfs_client # 日志路徑 tracker_server=172.16.1.40:22122 # 追蹤服務器的IP,有多個服務器可以另一行 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
# 上傳文件
[root@img01 fdfs]# fdfs_upload_file /etc/fdfs/client.conf /etc/passwd G1/M00/00/00/rBABKVe79c-ATItLAAAETQvMt7M7741798
# 下載文件
[root@img01 fdfs]# fdfs_download_file /etc/fdfs/client.conf G1/M00/00/00/rBABKVe79c-ATItLAAAETQvMt7M7741798
# 查看文件信息
[root@img01 fdfs]# fdfs_file_info /etc/fdfs/client.conf G1/M00/00/00/rBABKVe79c-ATItLAAAETQvMt7M7741798 source storage id: 0 source ip address: 172.16.1.41 file create timestamp: 2016-08-23 15:05:51 file size: 1101 file crc32: 197965747 (0x0BCCB7B3)
# 查看客戶端信息
[root@localhost ~]# fdfs_monitor /etc/fdfs/client.conf
[root@img01 fdfs]# fdfs_monitor /etc/fdfs/client.conf
[2016-08-23 15:09:29] DEBUG - base_path=/data/fdfs/fdfs_client, 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
server_count=1, server_index=0
tracker server is 172.16.1.40:22122
group count: 1
Group 1:
group name = G1
disk total space = 17944 MB
disk free space = 14902 MB
trunk free space = 0 MB
storage server count = 1
active server count = 1
storage server port = 23000
storage HTTP port = 8888
store path count = 1
subdir count per path = 256
current write server index = 0
current trunk file id = 0
Storage 1:
id = 172.16.1.41
ip_addr = 172.16.1.41 ACTIVE
http domain =
version = 5.05
join time = 2016-08-19 21:28:08
up time = 2016-08-19 21:37:31
total storage = 17944 MB
free storage = 14902 MB
upload priority = 10
store_path_count = 1
subdir_count_per_path = 256
storage_port = 23000
storage_http_port = 8888
current_write_path = 0
source storage id =
if_trunk_server = 0
connection.alloc_count = 256
connection.current_count = 1
connection.max_count = 2
total_upload_count = 27
success_upload_count = 27
total_append_count = 0
success_append_count = 0
total_modify_count = 0
success_modify_count = 0
total_truncate_count = 0
success_truncate_count = 0
total_set_meta_count = 8
success_set_meta_count = 8
total_delete_count = 16
success_delete_count = 16
total_download_count = 9
success_download_count = 9
total_get_meta_count = 4
success_get_meta_count = 4
total_create_link_count = 0
success_create_link_count = 0
total_delete_link_count = 0
success_delete_link_count = 0
total_upload_bytes = 471624
success_upload_bytes = 471624
total_append_bytes = 0
success_append_bytes = 0
total_modify_bytes = 0
success_modify_bytes = 0
stotal_download_bytes = 1191
success_download_bytes = 1191
total_sync_in_bytes = 0
success_sync_in_bytes = 0
total_sync_out_bytes = 0
success_sync_out_bytes = 0
total_file_open_count = 40
success_file_open_count = 40
total_file_read_count = 13
success_file_read_count = 13
total_file_write_count = 27
success_file_write_count = 27
last_heart_beat_time = 2016-08-23 15:09:28
last_source_update = 2016-08-23 15:05:50
last_sync_update = 1970-01-01 08:00:00
last_synced_timestamp = 1970-01-01 08:00:00
[root@img01 fdfs]#
參考文檔:
http://www.cnblogs.com/Yin-BloodMage/p/5433629.html
http://blog.csdn.net/xifeijian/article/details/38567839
http://www.open-open.com/lib/view/open1435468300700.html
