分佈式文件系統(Distributed File System)是指文件系統管理的物理存儲資源不必定直接鏈接在本地節點上,而是經過計算機網絡與節點相連。分佈式文件系統的設計基於客戶機/服務器模式。一個典型的網絡可能包括多個供多用戶訪問的服務器。另外,對等特性容許一些系統扮演客戶機和服務器的雙重角色。 html
FastDFS是一個開源的輕量級分佈式文件系統,它對文件進行管理,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負載均衡的問題。特別適合以文件爲載體的在線服務,如相冊網站、視頻網站等等。 vim
一:安裝FastDFS 瀏覽器
一、首先安裝libevent。 服務器
- wget http://monkey.org/~provos/libevent-2.0.11-stable.tar.gz
- tar -zxvf libevent-2.0.11-stable.tar.gz
- cd libevent-2.0.11-stable
- ./configure --prefix=/usr
- make clean
- make
- make install
二、安裝FastDFS的步驟 網絡
- wget http://fastdfs.googlecode.com/files/FastDFS_v3.03.tar.gz
- tar -zxvf FastDFS_v3.03.tar.gz
- cd FastDFS
- vim make.sh 將#WITH_HTTPD=1 修改爲WITH_HTTPD=1 以支持 http
- ./make.sh
- ./make.sh install
二:FastDFS的配置 app
一、配置及啓動Tracker Server: 負載均衡
- mkdir /home/fastdfs
- vi /etc/fdfs/tracker.conf
- base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs
- http.server_port=8080 -> http.server_port=9090
- ##include http.conf -> #include http.conf
- reserved_storage_space = 4GB -> reserved_storage_space = 1GB
- cd /usr/local/bin
- fdfs_trackerd /etc/fdfs/tracker.conf
檢查tracker是否啓動成功,能夠查看以下文件/home/fastdfs/logs/trackerd.log: dom
- [2011-10-21 14:29:44] INFO - FastDFS v3.03, base_path=/home/fastdfs, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=1024MB, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB
- [2011-10-21 14:29:44] INFO - HTTP supported: server_port=9090, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0, check_active_interval=30, check_active_type=tcp, check_active_uri=/status.html
二、配置及啓動Storage Server: tcp
- mkdir /home/fastdfs/fdfs_storage
- cd /etc/fdfs
- vi storage.conf
- base_path=/home/yuqing/fastdfs -> /home/fastdfs/fdfs_storage
- store_path0=/home/yuqing/fastdfs -> store_path0=/home/fastdfs/fdfs_storage
- group_name=group1
- tracker_server=192.168.209.121:22122 -> tracker_server=173.252.200.228:22122
- ##include http.conf ->#include http.conf
接下來會出現不少mkdir data path,這是系統在建立數據目錄。 分佈式
- [2011-10-21 14:49:20] INFO - FastDFS v3.03, base_path=/home/fastdfs/fdfs_storage, store_path_count=1, subdir_count_per_path=256, group_name=group1, run_by_group=, run_by_user=, connect_timeout=30s, network_timeout=60s, port=23000, bind_addr=, client_bind=1, max_connections=256, work_threads=4, disk_rw_separated=1, disk_reader_threads=1, disk_writer_threads=1, disk_rw_direct=0, buff_size=256KB, heart_beat_interval=30s, stat_report_interval=60s, tracker_server_count=1, sync_wait_msec=50ms, sync_interval=0ms, sync_start_time=00:00, sync_end_time=23:59, write_mark_file_freq=500, allow_ip_count=-1, file_distribute_path_mode=0, file_distribute_rotate_count=100, fsync_after_written_bytes=0, sync_log_buff_interval=10s, sync_binlog_buff_interval=10s, sync_stat_file_interval=300s, thread_stack_size=512 KB, upload_priority=10, if_alias_prefix=, check_file_duplicate=0, FDHT group count=0, FDHT server count=0, FDHT key_namespace=, FDHT keep_alive=0, HTTP server port=8888, domain name=
- [2011-10-21 14:49:20] INFO - HTTP supported: server_port=8888, http_trunk_size=262144, default_content_type=application/octet-stream, anti_steal_token=0, token_ttl=0s, anti_steal_secret_key length=0, token_check_fail content_type=, token_check_fail buff length=0
- [2011-10-21 14:49:42] INFO - file: storage_param_getter.c, line: 97, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=1024 MB, use_trunk_file=0, slot_min_size=0, slot_max_size=16 MB, trunk_file_size=64 MB
- [2011-10-21 14:49:44] INFO - file: tracker_client_thread.c, line: 304, successfully connect to tracker server 173.252.200.228:22122, as a tracker client, my ip is 173.252.200.228
- [2011-10-21 14:50:14] INFO - file: tracker_client_thread.c, line: 1100, tracker server 173.252.200.228:22122, set tracker leader: 173.252.200.228:22122
三:測試及使用FastDFS
一、FastDFS之配置client:
- vi /etc/fdfs/client.conf
- base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs
- tracker_server=192.168.209.121:22122 -> tracker_server=173.252.200.228:22122
- http.tracker_server_port=8080 ->http.tracker_server_port=9090
- ##include http.conf ->#include http.conf
二、測試上傳文件:
- cd ~
- fdfs_test /etc/fdfs/client.conf upload FastDFS_v3.03.tar.gz
執行成功後會出現以下提示:
- This is FastDFS client test program v3.03
- 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.
- [2011-10-21 15:14:59] INFO - base_path=/home/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=173.252.200.228, port=23000
- group_name=group1, ip_addr=173.252.200.228, port=23000
- storage_upload_by_filename
- group_name=group1, remote_filename=M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc.tar.gz
- source ip address: 173.252.200.228
- file timestamp=2011-10-21 15:14:59
- file size=344179
- file crc32=3182613655
- file url: http://173.252.200.228:9090/group1/M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc.tar.gz
- storage_upload_slave_by_filename
- group_name=group1, remote_filename=M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc_big.tar.gz
- source ip address: 173.252.200.228
- file timestamp=2011-10-21 15:14:59
- file size=344179
- file crc32=3182613655
- file url: http://173.252.200.228:9090/group1/M00/00/00/rfzI5E6hG_O5wNKxAAVAc72y1Jc_big.tar.gz
三、測試下載文件
在瀏覽器中,輸入上圖中的url地址,tracker server會自動重定向到存儲文件的storage server,文件下載成功。至此,已經成功搭建了FastDFS,編寫你本身的client來進行訪問吧!