FastDFS服務端有兩個角色:跟蹤器(tracker)和存儲節點(storage)。跟蹤器主要作調度工做,在訪問上起負載均衡的做用。nginx
存儲節點存儲文件,完成文件管理的全部功能:就是這樣的存儲、同步和提供存取接口,FastDFS同時對文件的metadata進行管理。所謂文件的meta data就是文件的相關屬性,以鍵值對(key valuepair)方式表示,如:width=1024,其中的key爲width,value爲1024。文件metadata是文件屬性列表,能夠包含多個鍵值對。git
跟蹤器和存儲節點均可以由一臺或多臺服務器構成。跟蹤器和存儲節點中的服務器都可以隨時增長或下線而不會影響線上服務。其中跟蹤器中的全部服務器都是對等的,能夠根據服務器的壓力狀況隨時增長或減小。github
爲了支持大容量,存儲節點(服務器)採用了分卷(或分組)的組織方式。存儲系統由一個或多個卷組成,卷與卷之間的文件是相互獨立的,全部卷的文件容量累加就是整個存儲系統中的文件容量。一個卷能夠由一臺或多臺存儲服務器組成,一個卷下的存儲服務器中的文件都是相同的,卷中的多臺存儲服務器起到了冗餘備份和負載均衡的做用。vim
在卷中增長服務器時,同步已有的文件由系統自動完成,同步完成後,系統自動將新增服務器切換到線上提供服務。服務器
當存儲空間不足或即將耗盡時,能夠動態添加捲。只須要增長一臺或多臺服務器,並將它們配置爲一個新的卷,這樣就擴大了存儲系統的容量。app
FastDFS中的文件標識分爲兩個部分:卷名和文件名,兩者缺一不可。負載均衡
1. client詢問tracker上傳到的storage,不須要附加參數;dom
2. tracker返回一臺可用的storage;測試
3. client直接和storage通信完成文件上傳。google
FastDFS file download
1. client詢問tracker下載文件的storage,參數爲文件標識(卷名和文件名);
2. tracker返回一臺可用的storage;
3. client直接和storage通信完成文件下載。
須要說明的是,client爲使用FastDFS服務的調用方,client也應該是一臺服務器,它對tracker和storage的調用均爲服務器間的調用。
下面開始部署配置,所需安裝包以下:
fastdfs-nginx-module_v1.16.tar.gz
FastDFS_v5.08.tar.gz
libfastcommon-master.zip
FastDFS 5.08版本再也不依賴libevent,而依賴於libfastcommon,所以須要先安裝libfastcommon。
軟件包下載地址:https://github.com/happyfish100/libfastcommon
# unzip libfastcommon-master.zip # cd libfastcommon-master # ./make.sh # ./make.sh install
libfastcommon.so 默認安裝到了/usr/lib64/libfastcommon.so,而FastDFS主程序設置的lib目錄是/usr/local/lib,所以須要設置軟連接(若是已存在,能夠忽略)。
# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so # ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so
軟件包下載地址:
一、https://sourceforge.net/projects/fastdfs/files/
二、https://code.google.com/archive/p/fastdfs/downloads
三、https://github.com/happyfish100/fastdfs
# tar zxf FastDFS_v5.05.tar.gz # cd FastDFS # ./make.sh # ./make.sh install
安裝完成後能夠看到/etc/fdfs目錄下生成了3個文件:
[root@localhost FastDFS]# cd /etc/fdfs/ [root@localhost fdfs]# ll total 20 -rw-r--r--. 1 root root 1461 Sep 7 07:45 client.conf.sample -rw-r--r--. 1 root root 7927 Sep 7 07:45 storage.conf.sample -rw-r--r--. 1 root root 7200 Sep 7 07:45 tracker.conf.sample [root@localhost fdfs]#
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf vim /etc/fdfs/tracker.conf # 修改的內容以下: disabled=false # 啓用配置文件 port=22122 # tracker服務器端口(默認22122) base_path=/fastdfs/tracker # 存儲日誌和數據的根目錄
建立目錄 mkdir -p /fastdfs/tracker
啓動tracker服務 [root@localhost /]# /etc/init.d/fdfs_trackerd start Starting FastDFS tracker server: 初次啓動tracker服務後會在配置的目錄下生成logs,data文件目錄 [root@localhost /]# cd /fastdfs/tracker/ [root@localhost tracker]# ll total 8 drwxr-xr-x. 2 root root 4096 Sep 7 07:59 data drwxr-xr-x. 2 root root 4096 Sep 7 07:59 logs 驗證查看tracker是否啓動成功 [root@localhost tracker]# ps -ef|grep tracker root 3160 1 0 07:59 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf root 3186 2475 0 08:00 pts/1 00:00:00 grep tracker
[root@localhost tracker]# cd /etc/fdfs/ [root@localhost fdfs]# ll total 28 -rw-r--r--. 1 root root 1461 Sep 7 07:45 client.conf.sample -rw-r--r--. 1 root root 7927 Sep 7 07:45 storage.conf.sample -rw-r--r--. 1 root root 7196 Sep 7 07:54 tracker.conf -rw-r--r--. 1 root root 7200 Sep 7 07:45 tracker.conf.sample [root@localhost fdfs]# cp storage.conf.sample ./storage.conf # 修改的內容以下: disabled=false # 啓用配置文件 port=23000 # storage服務端口 group_name=group1 # 組名(第一組爲group1,第二組爲group2,依次類推...) base_path=/fastdfs/storage # 數據和日誌文件存儲根目錄 store_path0=/fastdfs/storage # 第一個存儲目錄,第二個存儲目錄起名爲:store_path1=xxx,其它存儲目錄名依次類推... store_path_count=1 # 存儲路徑個數,須要和store_path個數匹配 tracker_server=192.168.184.132:22122 # tracker服務器IP和端口 http.server_port=8888 # http訪問文件的端口
建立數據目錄 mkdir -p /fastdfs/storage
啓動storage服務 /etc/init.d/fdfs_storaged start
初次啓動storage服務會生成data和logs目錄 [root@localhost fdfs]# cd /fastdfs/storage/ [root@localhost storage]# ll total 8 drwxr-xr-x. 259 root root 4096 Sep 7 08:08 data drwxr-xr-x. 2 root root 4096 Sep 7 08:08 logs
生成的data目錄內容 [root@localhost storage]# ll total 8 drwxr-xr-x. 259 root root 4096 Sep 7 08:08 data drwxr-xr-x. 2 root root 4096 Sep 7 08:08 logs [root@localhost storage]# cd data/ [root@localhost data]# ls 00 06 0C 12 18 1E 24 2A 30 36 3C 42 48 4E 54 5A 60 66 6C 72 78 7E 84 8A 90 96 9C A2 A8 AE B4 BA C0 C6 CC D2 D8 DE E4 EA F0 F6 FC sync 01 07 0D 13 19 1F 25 2B 31 37 3D 43 49 4F 55 5B 61 67 6D 73 79 7F 85 8B 91 97 9D A3 A9 AF B5 BB C1 C7 CD D3 D9 DF E5 EB F1 F7 FD 02 08 0E 14 1A 20 26 2C 32 38 3E 44 4A 50 56 5C 62 68 6E 74 7A 80 86 8C 92 98 9E A4 AA B0 B6 BC C2 C8 CE D4 DA E0 E6 EC F2 F8 fdfs_storaged.pid 03 09 0F 15 1B 21 27 2D 33 39 3F 45 4B 51 57 5D 63 69 6F 75 7B 81 87 8D 93 99 9F A5 AB B1 B7 BD C3 C9 CF D5 DB E1 E7 ED F3 F9 FE 04 0A 10 16 1C 22 28 2E 34 3A 40 46 4C 52 58 5E 64 6A 70 76 7C 82 88 8E 94 9A A0 A6 AC B2 B8 BE C4 CA D0 D6 DC E2 E8 EE F4 FA FF 05 0B 11 17 1D 23 29 2F 35 3B 41 47 4D 53 59 5F 65 6B 71 77 7D 83 89 8F 95 9B A1 A7 AD B3 B9 BF C5 CB D1 D7 DD E3 E9 EF F5 FB storage_stat.dat [root@localhost data]#
驗證是否啓動成功
[root@localhost data]# ps -ef|grep storage root 3220 1 1 08:08 ? 00:00:02 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf root 3251 2475 0 08:12 pts/1 00:00:00 grep storage
確認啓動成功後,能夠運行 fdfs_monitor 查看 storage服務器是否已經登記到 tracker服務器。 # /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
[root@localhost data]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf [2017-09-07 08:14:32] DEBUG - base_path=/fastdfs/storage, 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 192.168.184.132:22122 group count: 1 Group 1: group name = group1 disk total space = 18916 MB disk free space = 14929 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 = 192.168.184.132 ip_addr = 192.168.184.132 ACTIVE http domain = version = 5.08 join time = 2017-09-07 08:08:50 up time = 2017-09-07 08:08:50 total storage = 18916 MB free storage = 14929 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 = 0 connection.max_count = 0 total_upload_count = 0 success_upload_count = 0 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 = 0 success_set_meta_count = 0 total_delete_count = 0 success_delete_count = 0 total_download_count = 0 success_download_count = 0 total_get_meta_count = 0 success_get_meta_count = 0 total_create_link_count = 0 success_create_link_count = 0 total_delete_link_count = 0 success_delete_link_count = 0 total_upload_bytes = 0 success_upload_bytes = 0 total_append_bytes = 0 success_append_bytes = 0 total_modify_bytes = 0 success_modify_bytes = 0 stotal_download_bytes = 0 success_download_bytes = 0 total_sync_in_bytes = 0 success_sync_in_bytes = 0 total_sync_out_bytes = 0 success_sync_out_bytes = 0 total_file_open_count = 0 success_file_open_count = 0 total_file_read_count = 0 success_file_read_count = 0 total_file_write_count = 0 success_file_write_count = 0 last_heart_beat_time = 2017-09-07 08:14:29 last_source_update = 1969-12-31 16:00:00 last_sync_update = 1969-12-31 16:00:00 last_synced_timestamp = 1969-12-31 16:00:00
看到「192.168.184.132 ACTIVE」便可確認 storage 運行正常。
目前tracker,storage服務都正常啓動運行
1修改client.conf文件
cp client.conf.sample ./client.conf vi client.conf base_path=/fastdfs/tracker #存放數據和日誌目錄 tracker_server=192.168.1.200:22122 # tracker服務地址
新建個test.txt文件, vi test.txt 內容隨意寫 hello world
執行上傳文件
/usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/test.txt
[root@localhost fdfs]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/tools/test.txt group1/M00/00/00/wKi4hFmxZJ6AYqyCAAAADFmwwCQ352.txt
此時返回了一個文件信息,說明上傳成功