1、分佈式文件系統介紹
分佈式文件系統:Distributed file system, DFS,又叫作網絡文件系統:Network File System。一種容許文件經過網絡在多臺主機上分享的文件系統,可以讓多機器上的多用戶分享文件和存儲空間。
特色:在一個分享的磁盤文件系統中,全部節點對數據存儲區塊都有相同的訪問權,在這樣的系統中,訪問權限就必須由客戶端程序來控制。分佈式文件系統可能包含的功能有:透通的數據複製與容錯。
分佈式文件系統是被設計用在局域網。而分佈式數據存儲,則是泛指應用分佈式運算技術的文件和數據庫等提供數據存儲服務的系統。
決定因素:數據的存儲方式、數據的讀取速率、數據的安全機制。
發展歷史:大體分爲三個發展階段,網絡文件系統(1980s)、共享SAN文件系統(1990s)、面向對象的並行文件系統(2000s)。javascript
2、FastDFS分佈式系統架構介紹
FastDFS:是一個開源的輕量級分佈式文件系統,功能包括:文件存儲、文件同步、文件訪問(文件上傳、文件下載)等,解決了大容量存儲和負載均衡的問題。特別適合中小文件(建議範圍:4KB < file_size <500MB),對以文件爲載體的在線服務,如相冊網站、視頻網站等。php
FastDFS是爲互聯網應用量身定作的分佈式文件系統,充分考慮了冗餘備份、負載均衡、線性擴容等機制,並注重高可用、高性能等指標。和現有的類Google FS分佈式文件系統相比,FastDFS的架構和設計理念有其獨到之處,主要體如今輕量級、分組方式和對等結構三個方面。css
FastDFS架構圖
FastDFS服務端有兩個角色:跟蹤器(tracker)和存儲節點(storage)。跟蹤器主要作調度工做,在訪問上起負載均衡的做用。html
FastDFS模塊介紹
1)tracker server:跟蹤服務器,用來調度來自客戶端的請求,且在內存中記錄全部存儲組和存儲服務器的信息狀態。
2)storage server:存儲服務器,用來存儲文件(data)和文件屬性(metadata)。
3)client:客戶端,業務請求發起方,經過專用接口基於TCP協議與tracker server和storage server進行交互。
4)group:組,也可稱爲卷,同組內上的文件是徹底相同的。
5)文件標識:包括兩部分,組名(group)和文件名(含路徑)
6)文件相關屬性:鍵值對(Key Value Pair)方式
7)文件名:與原文件名並不相同。由storage server根據特定信息生成,而且可逆,文件名包含:源存儲服務器的IP地址、文件建立時間戳、文件大小、隨機數和文件擴展名等。java
FastDFS由跟蹤服務器(Tracker Server)、存儲服務器(Storage Server)和客戶端(Client)構成,其中:node
跟蹤服務器Tracker Server
主要作調度工做,起到均衡的做用;負責管理全部的 storage server和 group,每一個 storage 在啓動後會鏈接 Tracker,告知本身所屬 group 等信息,並保持週期性心跳。tracker根據storage的心跳信息,創建group==>[storage serverlist]的映射表。
Tracker須要管理的元信息不多,會所有存儲在內存中;另外tracker上的元信息都是由storage彙報的信息生成的,自己不須要持久化任何數據,這樣使得tracker很是容易擴展,直接增長tracker機器便可擴展爲tracker cluster來服務,cluster裏每一個tracker之間是徹底對等的,全部的tracker都接受stroage的心跳信息,生成元數據信息來提供讀寫服務。nginx
存儲服務器Storage Server
主要提供容量和備份服務;以 group 爲單位,每一個 group 內能夠有多臺 storage server,數據互爲備份。以group爲單位組織存儲能方便的進行應用隔離、負載均衡、副本數定製(group內storage server數量即爲該group的副本數),好比將不一樣應用數據存到不一樣的group就能隔離應用數據,同時還可根據應用的訪問特性來將應用分配到不一樣的group來作負載均衡;缺點是group的容量受單機存儲容量的限制,同時當group內有機器壞掉時,數據恢復只能依賴group內地其餘機器,使得恢復時間會很長。
group內每一個storage的存儲依賴於本地文件系統,storage可配置多個數據存儲目錄,好比有10塊磁盤,分別掛載在/data/disk1-/data/disk10,則可將這10個目錄都配置爲storage的數據存儲目錄。storage接受到寫文件請求時,會根據配置好的規則選擇其中一個存儲目錄來存儲文件。爲了不單個目錄下的文件數太多,在storage第一次啓動時,會在每一個數據存儲目錄裏建立2級子目錄,每級256個,總共65536個文件,新寫的文件會以hash的方式被路由到其中某個子目錄下,而後將文件數據做爲本地文件存儲到該目錄中。c++
客戶端Client
主要是上傳下載數據的服務器,也就是咱們本身的項目所部署在的服務器。每一個客戶端服務器都須要安裝Nginx
基本架構以下圖所示。git
FastDFS的存儲策略
爲了支持大容量,存儲節點(服務器)採用了分卷(或分組)的組織方式。存儲系統由一個或多個卷組成,卷與卷之間的文件是相互獨立的,全部卷的文件容量累加就是整個存儲系統中的文件容量。一個卷能夠由一臺或多臺存儲服務器組成,一個卷下的存儲服務器中的文件都是相同的,卷中的多臺存儲服務器起到了冗餘備份和負載均衡的做用。
在卷中增長服務器時,同步已有的文件由系統自動完成,同步完成後,系統自動將新增服務器切換到線上提供服務。當存儲空間不足或即將耗盡時,能夠動態添加捲。只須要增長一臺或多臺服務器,並將它們配置爲一個新的卷,這樣就擴大了存儲系統的容量。github
FastDFS的上傳過程
FastDFS向使用者提供基本文件訪問接口,好比upload、download、append、delete等,以客戶端庫的方式提供給用戶使用。
Storage Server會按期的向Tracker Server發送本身的存儲信息。當Tracker Server Cluster中的Tracker Server不止一個時,各個Tracker之間的關係是對等的,因此客戶端上傳時能夠選擇任意一個Tracker。
當Tracker收到客戶端上傳文件的請求時,會爲該文件分配一個能夠存儲文件的group,當選定了group後就要決定給客戶端分配group中的哪個storage server。當分配好storage server後,客戶端向storage發送寫文件請求,storage將會爲文件分配一個數據存儲目錄。而後爲文件分配一個fileid,最後根據以上的信息生成文件名存儲文件。文件名的格式以下:
FastDFS的文件同步
寫文件時,客戶端將文件寫至group內一個storage server即認爲寫文件成功,storage server寫完文件後,會由後臺線程將文件同步至同group內其餘的storage server。
每一個storage寫文件後,同時會寫一份binlog,binlog裏不包含文件數據,只包含文件名等元信息,這份binlog用於後臺同步,storage會記錄向group內其餘storage同步的進度,以便重啓後能接上次的進度繼續同步;進度以時間戳的方式進行記錄,因此最好能保證集羣內全部server的時鐘保持同步。
storage的同步進度會做爲元數據的一部分彙報到tracker上,tracke在選擇讀storage的時候會以同步進度做爲參考。
客戶端上傳文件後存儲與服務器將文件ID返回給客戶端,此文件ID用於之後訪問該文件的索引信息。文件索引信息包括:組名,虛擬磁盤路徑,數據兩級目錄,文件名。
路徑格式:
FastDFS的文件下載
客戶端uploadfile成功後,會拿到一個storage生成的文件名,接下來客戶端根據這個文件名便可訪問到該文件。
跟upload file同樣,在downloadfile時客戶端能夠選擇任意tracker server。tracker發送download請求給某個tracker,必須帶上文件名信息,tracke從文件名中解析出文件的group、大小、建立時間等信息,而後爲該請求選擇一個storage用來服務讀請求。
FastDFS性能方案
3、Centos下部署FastDFS分佈式存儲操做記錄
1)服務器信息(centos6.9)
描述 ip地址 主機名稱 分組 跟蹤服務器1 192.168.10.200 Fastdfs_tracker_t1 跟蹤服務器2 192.168.10.201 Fastdfs_tracker_t2 存儲服務器1 192.168.10.202 Fastdfs_storage_s1 group1 存儲服務器2 192.168.10.203 Fastdfs_storage_s2 group2 存儲服務器3 192.168.10.204 Fastdfs_storage_s3 group3 客戶機1 192.168.10.205 Fastdfs_client
2)FastDFS安裝(全部tracker服務器、storage服務器、客戶端機器都要有以下操做。這裏以Fastdfs_tracker_t1服務器操做爲例)
1)編譯和安裝所需的依賴包 [root@Fastdfs_tracker_t1 ~]# yum install make cmake gcc gcc-c++ 2)安裝libfastcommon [root@Fastdfs_tracker_t1 ~]# cd /usr/local/src/ [root@Fastdfs_tracker_t1 src]# wget https://codeload.github.com/happyfish100/libfastcommon/tar.gz/V1.0.7 -O libfastcommon-1.0.7.tar.gz [root@Fastdfs_tracker_t1 src]# tar zxf libfastcommon-1.0.7.tar.gz [root@Fastdfs_tracker_t1 src]# cd libfastcommon-1.0.7 [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ./make.sh [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ./make.sh install libfastcommon 默認安裝到了/usr/lib64/libfastcommon.so和/usr/lib64/libfdfsclient.so 由於FastDFS主程序設置的lib目錄是/usr/local/lib,因此須要建立軟連接 [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ln -s /usr/lib64/libfdfsclient.so /usr/local/lib/libfdfsclient.so [root@Fastdfs_tracker_t1 libfastcommon-1.0.7]# ln -s /usr/lib64/libfdfsclient.so /usr/lib/libfdfsclient.so 3)安裝FastDFS 先提早安裝依賴 [root@Fastdfs_tracker_t1 ~]# yum install gettext gettext-devel libXft libXft-devel libXpm libXpm-devel autoconf libxtst-devel zlib-devel libpng-devel glib-devel [root@Fastdfs_tracker_t1 ~]# cd /usr/local/src/ [root@Fastdfs_tracker_t1 src]# wget https://github.s3.amazonaws.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz [root@Fastdfs_tracker_t1 src]# tar -zvxf libevent-2.0.20-stable.tar.gz [root@Fastdfs_tracker_t1 src]# cd libevent-2.0.20-stable [root@Fastdfs_tracker_t1 libevent-2.0.20-stable]# ./configure && make && make install 接着編譯安裝FastDFS(編譯前要確保已經成功安裝了 libfastcommon)。百度雲盤下載:https://pan.baidu.com/s/1x_CTcRqZr_BTptXF9kHOng 提取密碼:9ku2 [root@Fastdfs_tracker_t1 src]# pwd /usr/local/src [root@Fastdfs_tracker_t1 src]# ls FastDFS_v5.05.tar.gz FastDFS_v5.05.tar.gz [root@Fastdfs_tracker_t1 src]# tar -zvxf FastDFS_v5.05.tar.gz [root@Fastdfs_tracker_t1 src]# cd FastDFS [root@Fastdfs_tracker_t1 FastDFS]# ./make.sh [root@Fastdfs_tracker_t1 FastDFS]# ./make.sh install 採用默認安裝的方式安裝,安裝後的相應文件與目錄: 服務腳本在: /etc/init.d/fdfs_storaged /etc/init.d/fdfs_trackerd 配置文件在(樣例配置文件): /etc/fdfs/client.conf.sample /etc/fdfs/storage.conf.sample /etc/fdfs/tracker.conf.sample 命令工具在/usr/bin/目錄下的: fdfs_appender_test fdfs_appender_test1 fdfs_append_file fdfs_crc32 fdfs_delete_file fdfs_download_file fdfs_file_info fdfs_monitor fdfs_storaged fdfs_test fdfs_test1 fdfs_trackerd fdfs_upload_appender fdfs_upload_file stop.sh restart.sh 由於FastDFS服務腳本設置的bin目錄是/usr/local/bin,但實際命令安裝在/usr/bin,能夠進入/user/bin 目錄使用如下命令查看 fdfs 的相關命令: [root@Fastdfs_tracker_t1 ~]# cd /usr/bin/ [root@Fastdfs_tracker_t1 bin]# ls | grep fdfs 所以須要修改FastDFS服務腳本中相應的命令路徑,也就是把/etc/init.d/fdfs_storaged和/etc/init.d/fdfs_trackerd 兩個腳本中的/usr/local/bin修改爲/usr/bin: [root@Fastdfs_tracker_t1 bin]# vim /etc/init.d/fdfs_trackerd 使用查找替換命令進統一修改::%s+/usr/local/bin+/usr/bin [root@Fastdfs_tracker_t1 bin]# vim /etc/init.d/fdfs_storaged 使用查找替換命令進統一修改::%s+/usr/local/bin+/usr/bin
3)配置FastDFS跟蹤器Tracker(兩臺機器Fastdfs_tracker_t1和Fastdfs_tracker_t2都須要操做)
1)複製 FastDFS 跟蹤器樣例配置文件,並重命名 [root@Fastdfs_tracker_t1 ~]# cd /etc/fdfs/ [root@Fastdfs_tracker_t1 fdfs]# cp tracker.conf.sample tracker.conf 2)編輯跟蹤器配置文件 [root@Fastdfs_tracker_t1 fdfs]# vim /etc/fdfs/tracker.conf // 修改的內容以下(其它參數保留默認配置) ...... disabled=false //啓用配置文件 port=22122 //tracker 的端口號,通常採用 22122 這個默認端口 base_path=/fastdfs/tracker //tracker 的數據文件和日誌目錄 # the method of selecting group to upload files # 0: round robin # 1: specify group # 2: load balance, select the max free space group to upload file store_lookup=0 //採起輪巡方式選擇要上傳的組進行存儲,默認2 選擇最大空閒空間的組 3)建立基礎數據目錄(參考基礎目錄 base_path 配置) [root@Fastdfs_tracker_t1 fdfs]# mkdir -p /fastdfs/tracker 4)關閉iptables防火牆 [root@Fastdfs_tracker_t1 fdfs]# /etc/init.d/iptables stop ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 舒適提示: 若是iptables防火牆中開啓的話,則須要打開跟蹤器端口(默認爲 22122) [root@Fastdfs_tracker_t1 fdfs]# vim /etc/sysconfig/iptables ## FastDFS Tracker Port -A INPUT -m state --state NEW -m tcp -p tcp --dport 22122 -j ACCEPT [root@Fastdfs_tracker_t1 fdfs]# service iptables restart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5)啓動Tracker服務 [root@Fastdfs_tracker_t1 fdfs]# /etc/init.d/fdfs_trackerd start Starting FastDFS tracker server: 初次成功啓動,會在/fastdfs/tracker 目錄下建立 data、logs 兩個目錄;能夠查看tracker是否啓動成功: [root@Fastdfs_tracker_t1 fdfs]# ls /fastdfs/tracker/ data logs [root@Fastdfs_tracker_t1 fdfs]# netstat -unltp|grep fdfs tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 10469/fdfs_trackerd [root@Fastdfs_tracker_t1 fdfs]# lsof -i:22122 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME fdfs_trac 10469 root 5u IPv4 214098 0t0 TCP *:22122 (LISTEN) [root@Fastdfs_tracker_t1 fdfs]# tail -100f /fastdfs/tracker/logs/trackerd.log 關閉Tracker [root@Fastdfs_tracker_t2 fdfs]# /etc/init.d/fdfs_trackerd stop 設置FastDFS跟蹤器開機啓動 [root@Fastdfs_tracker_t1 fdfs]# chkconfig fdfs_trackerd on [root@Fastdfs_tracker_t1 fdfs]# chkconfig --list|grep fdfs_trackerd fdfs_trackerd 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@Fastdfs_tracker_t1 fdfs]# vim /etc/rc.d/rc.local [root@Fastdfs_tracker_t1 fdfs]# cat /etc/rc.d/rc.local ....... /etc/init.d/fdfs_trackerd start
4)配置FastDFS存儲服務(三臺機器Fastdfs_storage_s一、Fastdfs_storage_s二、Fastdfs_storage_s3都須要操做)
1)複製FastDFS存儲器樣例配置文件,並重命名。 [root@Fastdfs_storage_s1 FastDFS]# cd /etc/fdfs/ [root@Fastdfs_storage_s1 fdfs]# cp storage.conf.sample storage.conf [root@Fastdfs_storage_s1 fdfs]# vim /etc/fdfs/storage.conf //修改的內容以下(其它參數保留默認配置): ....... disabled=false //啓用配置文件 group_name=group1 //組名(第一組爲 group1,第二組爲 group2) port=23000 //storage 的端口號,同一個組的 storage 端口號必須相同 base_path=/fastdfs/storage //設置 storage 的日誌目錄 store_path0=/fastdfs/storage //存儲路徑 store_path_count=1 //存儲路徑個數,須要和 store_path 個數匹配 tracker_server=192.168.10.200:22122 //tracker 服務器的 IP 地址和端口 tracker_server=192.168.1.201:22122 //多個 tracker 直接添加多條配置 http.server_port=8888 //設置 http 端口號 2)建立基礎數據目錄(參考基礎目錄 base_path 配置) [root@Fastdfs_storage_s1 fdfs]# mkdir -p /fastdfs/storage 4)關閉iptables防火牆 [root@Fastdfs_storage_s1 fdfs]# /etc/init.d/iptables stop ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 舒適提示: 若是iptables防火牆中開啓的話,則須要打開23000端口 [root@Fastdfs_tracker_t1 fdfs]# vim /etc/sysconfig/iptables ## FastDFS Tracker Port -A INPUT -m state --state NEW -m tcp -p tcp --dport 23000 -j ACCEPT [root@Fastdfs_storage_s1 fdfs]# service iptables restart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5)啓動 Storage [root@Fastdfs_storage_s1 fdfs]# /etc/init.d/fdfs_storaged start Starting FastDFS storage server: 初次成功啓動,會在/fastdfs/storage 目錄下建立數據目錄 data 和日誌目錄 logs)各節點啓動動, 使用 tail -f /fastdfs/storage/logs/storaged.log 命令監聽存儲節點日誌,能夠看到存儲節點連接到跟蹤器, 並提示哪個爲 leader 跟蹤器。同時也會看到同一組中的其餘節點加入進來的日誌信息。 查看23000端口監聽狀況: [root@Fastdfs_storage_s1 fdfs]# netstat -unltp|grep fdfs tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 28347/fdfs_storaged [root@Fastdfs_storage_s1 fdfs]# lsof -i:23000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME fdfs_stor 28347 root 5u IPv4 211801 0t0 TCP *:inovaport1 (LISTEN) [root@Fastdfs_storage_s1 fdfs]# tail -f /fastdfs/storage/logs/storaged.log mkdir data path: FD ... mkdir data path: FE ... mkdir data path: FF ... data path: /fastdfs/storage/data, mkdir sub dir done. [2018-02-26 14:27:46] INFO - file: storage_param_getter.c, line: 191, use_storage_id=0, id_type_in_filename=ip, storage_ip_changed_auto_adjust=1, store_path=0, reserved_storage_space=10.00%, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, trunk_compress_binlog_min_interval=0, store_slave_file_use_link=0 [2018-02-26 14:27:46] INFO - file: storage_func.c, line: 254, tracker_client_ip: 192.168.10.202, my_server_id_str: 192.168.10.202, g_server_id_in_filename: -905271104 [2018-02-26 14:27:51] INFO - local_host_ip_count: 2, 127.0.0.1 192.168.10.202 [2018-02-26 14:27:51] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.10.201:22122, as a tracker client, my ip is 192.168.10.202 [2018-02-26 14:27:51] INFO - file: tracker_client_thread.c, line: 1235, tracker server 192.168.10.201:22122, set tracker leader: 192.168.10.201:22122 [2018-02-26 14:27:52] INFO - file: tracker_client_thread.c, line: 310, successfully connect to tracker server 192.168.10.200:22122, as a tracker client, my ip is 192.168.10.202 ....... 關閉storage [root@Fastdfs_storage_s1 fdfs]# /etc/init.d/fdfs_storaged stop 設置storage開機啓動 [root@Fastdfs_storage_s1 fdfs]# chkconfig fdfs_storaged on [root@Fastdfs_storage_s1 fdfs]# chkconfig --list|grep fdfs_storaged fdfs_storaged 0:off 1:off 2:on 3:on 4:on 5:on 6:off [root@Fastdfs_storage_s1 fdfs]# vim /etc/rc.d/rc.local ...... /etc/init.d/fdfs_storaged start 全部Storage節點都啓動以後,能夠在任一 Storage 節點上使用以下命令查看集羣信息: [root@Fastdfs_storage_s1 fdfs]# /usr/bin/fdfs_monitor /etc/fdfs/storage.conf [2018-02-26 14:30:22] DEBUG - base_path=/fastdfs/storage, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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=2, server_index=0 tracker server is 192.168.10.200:22122 group count: 3 Group 1: group name = group1 disk total space = 50268 MB disk free space = 45029 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.10.202 ip_addr = 192.168.10.202 ACTIVE http domain = version = 5.05 join time = 2018-02-26 14:27:07 up time = 2018-02-26 14:27:07 total storage = 50268 MB free storage = 45029 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 = 2018-02-26 14:29:52 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 Group 2: group name = group2 disk total space = 49086 MB disk free space = 44696 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.10.203 ip_addr = 192.168.10.203 ACTIVE http domain = version = 5.05 join time = 2018-02-26 14:27:09 up time = 2018-02-26 14:27:09 total storage = 49086 MB free storage = 44696 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 = 2018-02-26 14:30:15 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00 Group 3: group name = group3 disk total space = 49086 MB disk free space = 44962 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.10.204 ip_addr = 192.168.10.204 ACTIVE http domain = version = 5.05 join time = 2018-02-26 14:27:10 up time = 2018-02-26 14:27:10 total storage = 49086 MB free storage = 44962 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 = 2018-02-26 14:29:55 last_source_update = 1970-01-01 08:00:00 last_sync_update = 1970-01-01 08:00:00 last_synced_timestamp = 1970-01-01 08:00:00
5)文件上傳測試(在客戶機192.168.10.205上測試便可,也能夠直接在Fastdfs_tracker服務器如192.168.10.200上測試,只要在安裝fastdfs_client機器上測試就行)
1)修改客戶端配置文件 [root@Fastdfs_client ~]# cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf [root@Fastdfs_client ~]# vim /etc/fdfs/client.conf //修改的內容以下(其它參數保留默認配置): ...... base_path=/fastdfs/tracker tracker_server=192.168.10.200:22122 tracker_server=192.168.10.201:22122 2)建立基礎數據目錄(參考基礎目錄 base_path 配置) [root@Fastdfs_client ~]# mkdir -p /fastdfs/tracker 3)上傳(能夠經過Xftp5上傳)一張圖片(好比test.png)到客戶機192.168.10.205目錄/usr/local/src/,用做上傳測試 [root@Fastdfs_client src]# pwd /usr/local/src [root@Fastdfs_client src]# ll test.png -rw-r--r--. 1 root root 165712 Feb 26 14:53 test.png 而後使用FastDFS上傳命令,將測試圖片上傳到FastDFS存儲裏。 [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.png group1/M00/00/00/wKgKylqTsFCAdeEuAAKHUIZ3K9s287.png 如上能返回文件ID號,說明上傳成功。由返回的信息可知,test.png圖片被上傳到group1下的數據目錄下了。 到group1組內機器(即Fastdfs_storage_s1)的數據目錄下可找到剛纔上傳的文件: [root@Fastdfs_storage_s1 ~]# ll /fastdfs/storage/data/00/00/ total 164 -rw-r--r--. 1 root root 165712 Feb 26 14:59 wKgKylqTsFCAdeEuAAKHUIZ3K9s287.png 同理,再上傳一張圖片進行測試 [root@Fastdfs_client ~]# cd /usr/local/src/ [root@Fastdfs_client src]# ll haha.png -rw-r--r--. 1 root root 12331 Feb 26 16:40 haha.png [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/haha.png group2/M00/00/00/wKgKy1qTyCKAFGzSAAAwK2jUNaY428.png 即haha.png圖片被上傳到group2組內機器的數據目錄下了 [root@Fastdfs_storage_s2 ~]# ll /fastdfs/storage/data/00/00/ total 16 -rw-r--r--. 1 root root 12331 Feb 26 16:41 wKgKy1qTyCKAFGzSAAAwK2jUNaY428.png 再上傳一次 [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/haha.png group3/M00/00/00/wKgKzFqTyRaAeDLJAAAwK2jUNaY992.png [root@Fastdfs_storage_s3 ~]# ll /fastdfs/storage/data/00/00/ total 16 -rw-r--r--. 1 root root 12331 Feb 26 16:45 wKgKzFqTyRaAeDLJAAAwK2jUNaY992.png 這裏,我測試的時候,一個group組內只有一臺存儲服務器,測試圖片上傳到group內,只上傳到一臺存儲服務器上了。 正常來講,應該要在同一個group組內添加2臺以上的存儲服務器,這樣圖片就是被上傳到多臺存儲服務器上, 那麼當一臺存儲服務器掛掉後,圖片還能從其餘的存儲服務器上讀出來。
6)在各個存儲節點上安裝Nginx(Fastdfs_storage_s一、Fastdfs_storage_s二、Fastdfs_storage_s3)
1)fastdfs-nginx-module 做用說明 FastDFS 經過Tracker服務器,將文件放在Storage服務器存儲,可是同組存儲服務器之間須要進入文件複製,有同步延遲的問題。 假設Tracker服務器將文件上傳到了A機器上,上傳成功後文件ID已經返回給客戶端。此時FastDFS存儲集羣機制會將這個文件同步到同組存儲B機器上, 在文件尚未複製完成的狀況下,客戶端若是用這個文件ID在B機器上取文件,就會出現文件沒法訪問的錯誤。 而fastdfs-nginx-module能夠重定向文件鏈接到源服務器取文件,避免客戶端因爲複製延遲致使的文件沒法訪問錯誤。 (解壓後的fastdfs-nginx-module在nginx安裝時使用) 2)安裝nginx前,須要配置如下依賴 [root@Fastdfs_storage_s1 ~]# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel 3)安裝nginx和fastdfs-nginx-module [root@Fastdfs_storage_s1 ~]# cd /usr/local/src/ [root@Fastdfs_storage_s1 src]# wget http://nginx.org/download/nginx-1.13.9.tar.gz 下載fastdfs-nginx-module地址:https://pan.baidu.com/s/1i6Jqsi5 提取密碼:g1ps [root@Fastdfs_storage_s1 src]# ll fastdfs-nginx-module_v1.16.tar.gz -rw-r--r--. 1 root root 17510 Feb 26 16:58 fastdfs-nginx-module_v1.16.tar.gz [root@Fastdfs_storage_s1 src]# ls nginx-1.13.9.tar.gz nginx-1.13.9.tar.gz [root@Fastdfs_storage_s1 src]# tar -zvxf nginx-1.13.9.tar.gz [root@Fastdfs_storage_s1 src]# tar -zvxf fastdfs-nginx-module_v1.16.tar.gz [root@Fastdfs_storage_s1 src]# vim /usr/local/src/fastdfs-nginx-module/src/config 將 CORE_INCS="$CORE_INCS /usr/local/include/fastdfs /usr/local/include/fastcommon/" 修改成: CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/" 千萬注意:這個路徑修改是很重要的,否則在 nginx 編譯的時候會報錯的! 緊接着進行nginx的編譯安裝操做 [root@Fastdfs_storage_s1 src]# cd nginx-1.13.9 [root@Fastdfs_storage_s1 nginx-1.13.9]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module/src [root@Fastdfs_storage_s1 nginx-1.13.9]# make && make install 4)複製 fastdfs-nginx-module 源碼中的配置文件到/etc/fdfs 目錄,並修改 [root@Fastdfs_storage_s1 src]# cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/ [root@Fastdfs_storage_s1 src]# vim /etc/fdfs/mod_fastdfs.conf ...... connect_timeout=10 base_path=/tmp tracker_server=192.168.10.200:22122 tracker_server=192.168.10.201:22122 storage_server_port=23000 group_name=group1 url_have_group_name = true store_path0=/fastdfs/storage group_count = 3 [group1] group_name=group1 storage_server_port=23000 store_path_count=1 store_path0=/fastdfs/storage [group2] group_name=group2 storage_server_port=23000 store_path_count=1 store_path0=/fastdfs/storage [group3] group_name=group3 storage_server_port=23000 store_path_count=1 store_path0=/fastdfs/storage 特別注意: 第二組內的Storage服務器(這裏指Fastdfs_storage_s2)的mod_fastdfs.conf配置與第一組配置只有group_nam不一樣,即: group_name=group2 第三組內的Storage服務器(這裏指Fastdfs_storage_s3)的mod_fastdfs.conf 配置與第一組配置只有group_name不一樣,即: group_name=group3 5)複製 FastDFS 的部分配置文件到/etc/fdfs 目錄 [root@Fastdfs_storage_s1 src]# cd /usr/local/src/FastDFS/conf [root@Fastdfs_storage_s1 conf]# cp http.conf mime.types /etc/fdfs/ 6)在/fastdfs/storage 文件存儲目錄下建立軟鏈接,將其連接到實際存放數據的目錄 [root@Fastdfs_storage_s1 conf]# ln -s /fastdfs/storage/data/ /fastdfs/storage/data/M00 7)配置 Nginx,簡潔版 nginx 配置樣例 [root@Fastdfs_storage_s1 src]# cd /usr/local/nginx/conf/ [root@Fastdfs_storage_s1 conf]# cp nginx.conf nginx.conf.bak [root@Fastdfs_storage_s1 conf]# cat nginx.conf user www; //若是url訪問圖片時出現404,能夠將這個修改成"user root" worker_processes 8; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 65535; } http { include mime.types; default_type application/octet-stream; charset utf-8; ###### ## set access log format ###### log_format main '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_cookie" $host $request_time'; ####### ## http setting ####### sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; proxy_cache_path /var/www/cache levels=1:2 keys_zone=mycache:20m max_size=2048m inactive=60m; proxy_temp_path /var/www/cache/tmp; fastcgi_connect_timeout 3000; fastcgi_send_timeout 3000; fastcgi_read_timeout 3000; fastcgi_buffer_size 256k; fastcgi_buffers 8 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; # client_header_timeout 600s; client_body_timeout 600s; # client_max_body_size 50m; client_max_body_size 100m; #容許客戶端請求的最大單個文件字節數 client_body_buffer_size 256k; #緩衝區代理緩衝請求的最大字節數,能夠理解爲先保存到本地再傳給用戶 gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php; gzip_vary on; ## includes vhosts include vhosts/*.conf; } [root@Fastdfs_storage_s1 conf]# mkdir vhosts [root@Fastdfs_storage_s1 conf]# cd vhosts/ [root@Fastdfs_storage_s1 vhosts]# vim fastdfs.conf [root@Fastdfs_storage_s1 vhosts]# cat fastdfs.conf server { listen 8888; server_name localhost; location /group1/M00 { //注意,Fastdfs_storage_s2機器內此處修改成/group2/M00,Fastdfs_storage_s3機器內此處修改成/group3/M00 #alias /fastdfs/storage/data; ngx_fastdfs_module; } error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } } [root@Fastdfs_storage_s1 vhosts]#useradd www [root@Fastdfs_storage_s1 vhosts]# mkdir -p /var/www/cache [root@Fastdfs_storage_s1 vhosts]# /usr/local/nginx/sbin/nginx -t [root@Fastdfs_storage_s1 vhosts]# /usr/local/nginx/sbin/nginx [root@Fastdfs_storage_s1 vhosts]# /usr/local/nginx/sbin/nginx -s reload [root@Fastdfs_storage_s1 vhosts]# lsof -i:8888 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 31543 root 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31617 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31618 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31619 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31620 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31621 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31622 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31623 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) nginx 31624 www 10u IPv4 218910 0t0 TCP *:ddi-tcp-1 (LISTEN) +++++++++++++++++++++++++++++++++++++++++++特別注意++++++++++++++++++++++++++++++++++++++++++++++++++ A、8888 端口值是要與/etc/fdfs/storage.conf 中的 http.server_port=8888 相對應, 由於 http.server_port 默認爲 8888,若是想改爲 80,則要對應修改過來。 B、Storage 對應有多個 group 的狀況下,訪問路徑帶 group 名,如/group1/M00/00/00/xxx, 對應的 Nginx 配置爲: location ~/group([0-9])/M00 { ngx_fastdfs_module; } C、如查下載時如發現老報 404,將 nginx.conf 第一行 user www 修改成 user root 後從新啓動!這個要特別注意!!!!! ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8)設置Nginx開機啓動 [root@Fastdfs_storage_s1 ~]# vim /etc/rc.d/rc.local ........ /usr/local/nginx/sbin/nginx 9)關閉iptables防火牆 [root@Fastdfs_storage_s1 conf]# /etc/init.d/iptables stop ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 舒適提示: 若是打開了iptables防火牆功能,則須要開通8888端口訪問 [root@Fastdfs_storage_s1 ~]# vim /etc/sysconfig/iptables ## FastDFS Tracker Port -A INPUT -m state --state NEW -m tcp -p tcp --dport 8888 -j ACCEPT [root@Fastdfs_storage_s1 ~]# service iptables restart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 10)經過瀏覽器訪問測試時上傳的文件(對應上傳到FastDFS存儲裏的路徑) 在客戶端機器上傳圖片 [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/haha.png group1/M00/00/00/wKgKylqT3OCAUrqYAAAwK2jUNaY262.png [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.png group2/M00/00/00/wKgKy1qT3P-Ae-vQAAKHUIZ3K9s459.png [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.png group3/M00/00/00/wKgKzFqT3SWAaunZAAKHUIZ3K9s849.png 而後訪問圖片的url http://192.168.10.202:8888/group1/M00/00/00/wKgKylqT3OCAUrqYAAAwK2jUNaY262.png http://192.168.10.203:8888/group2/M00/00/00/wKgKy1qT3P-Ae-vQAAKHUIZ3K9s459.png http://192.168.10.204:8888/group3/M00/00/00/wKgKzFqT3SWAaunZAAKHUIZ3K9s849.png
7)在各個跟蹤節點服務器上安裝Nginx(Fastdfs_tracker_t一、Fastdfs_tracker_t2)
在tracker上安裝的nginx主要爲了提供 http 訪問的反向代理、負載均衡以及緩存服務
1)安裝編譯 Nginx 所需的依賴包 [root@Fastdfs_tracker_t1 ~]# yum install gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl openssl-devel 2)上傳 ngx_cache_purge-2.3.tar.gz和nginx-1.13.9.tar.gz到/usr/local/src,解壓 [root@Fastdfs_tracker_t1 ~]# cd /usr/local/src/ [root@Fastdfs_tracker_t1 src]# wget http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz [root@Fastdfs_tracker_t1 src]# wget http://nginx.org/download/nginx-1.13.9.tar.gz [root@Fastdfs_tracker_t1 src]# tar -zvxf ngx_cache_purge-2.3.tar.gz [root@Fastdfs_tracker_t1 src]# tar -zvxf nginx-1.13.9.tar.gz [root@Fastdfs_tracker_t1 src]# cd nginx-1.13.9 [root@Fastdfs_tracker_t1 nginx-1.13.9]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/ngx_cache_purge-2.3 && make && make install 3)配置 Nginx,設置負載均衡以及緩存 [root@Fastdfs_tracker_t1 conf]# cp nginx.conf nginx.conf.conf [root@Fastdfs_tracker_t1 conf]# cat nginx.conf user www; worker_processes 8; #error_log logs/error.log; #error_log logs/error.log notice; #error_log logs/error.log info; #pid logs/nginx.pid; events { worker_connections 65535; } http { include mime.types; default_type application/octet-stream; charset utf-8; ###### ## set access log format ###### log_format main '$http_x_forwarded_for $remote_addr $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_cookie" $host $request_time'; ####### ## http setting ####### sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; proxy_cache_path /fastdfs/cache/nginx/proxy_cache levels=1:2 keys_zone=mycache:20m max_size=2048m inactive=60m; proxy_temp_path /fastdfs/cache/nginx/proxy_cache/tmp; fastcgi_connect_timeout 3000; fastcgi_send_timeout 3000; fastcgi_read_timeout 3000; fastcgi_buffer_size 256k; fastcgi_buffers 8 256k; fastcgi_busy_buffers_size 256k; fastcgi_temp_file_write_size 256k; fastcgi_intercept_errors on; # client_header_timeout 600s; client_body_timeout 600s; # client_max_body_size 50m; client_max_body_size 100m; client_body_buffer_size 256k; gzip on; gzip_min_length 1k; gzip_buffers 4 16k; gzip_http_version 1.1; gzip_comp_level 9; gzip_types text/plain application/x-javascript text/css application/xml text/javascript application/x-httpd-php; gzip_vary on; ## includes vhosts include vhosts/*.conf; } [root@Fastdfs_tracker_t1 conf]# mkdir vhosts [root@Fastdfs_tracker_t1 vhosts]# cat lb.conf //若是group組內有多個存儲服務器,則這裏的負載就起做用了。 upstream fdfs_group1 { server 192.168.10.202:8888 weight=1 max_fails=2 fail_timeout=30s; } upstream fdfs_group2 { server 192.168.10.203:8888 weight=1 max_fails=2 fail_timeout=30s; } upstream fdfs_group3 { server 192.168.10.204:8888 weight=1 max_fails=2 fail_timeout=30s; } server{ listen 8000; server_name localhost; access_log /usr/local/nginx/logs/lb_access.log main; error_log /usr/local/nginx/logs/lb_error.log; location /group1/M00 { proxy_pass http://fdfs_group1; } location /group2/M00 { proxy_pass http://fdfs_group2; } location /group3/M00 { proxy_pass http://fdfs_group3; } #設置清除緩存的訪問權限 location ~/purge(/.*) { allow 127.0.0.1; allow 114.242.193.201; allow 192.168.10.0/24; deny all; proxy_cache_purge mycache $host$1$is_args$args ; } } 按以上 nginx 配置文件的要求,建立對應的緩存目錄 [root@Fastdfs_tracker_t1 conf]# useradd www [root@Fastdfs_tracker_t1 conf]# ulimit 65535 [root@Fastdfs_tracker_t1 conf]# mkdir -p /fastdfs/cache/nginx/proxy_cache [root@Fastdfs_tracker_t1 conf]# mkdir -p /fastdfs/cache/nginx/proxy_cache/tmp [root@Fastdfs_tracker_t1 conf]# /usr/local/nginx/sbin/nginx -t [root@Fastdfs_tracker_t1 conf]# /usr/local/nginx/sbin/nginx [root@Fastdfs_tracker_t1 conf]# /usr/local/nginx/sbin/nginx -s reload 4)關閉iptables防火牆 [root@Fastdfs_tracker_t1 conf]# /etc/init.d/iptables stop ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 舒適提示: 若是iptables防火牆中開啓的話,則須要打開8000端口 [root@Fastdfs_tracker_t1 fdfs]# vim /etc/sysconfig/iptables ## FastDFS Tracker Port -A INPUT -m state --state NEW -m tcp -p tcp --dport 8000 -j ACCEPT [root@Fastdfs_tracker_t1 conf]# service iptables restart ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5)設置Nginx開機啓動 [root@Fastdfs_storage_s1 ~]# vim /etc/rc.d/rc.local ........ /usr/local/nginx/sbin/nginx 6)文件訪問測試 在客戶端機器上傳圖片(或使用上面測試中已經上傳過的圖片路徑進行訪問測試) [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.jpg group1/M00/00/00/wKgKylqUxBOAFo8hAAKHUIZ3K9s443.jpg [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/haha.png group2/M00/00/00/wKgKy1qUxBeAT0PxAAAwK2jUNaY575.png [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.jpg group3/M00/00/00/wKgKzFqUxBmATFurAAKHUIZ3K9s282.jpg 而後訪問圖片的url http://192.168.10.200:8000/group1/M00/00/00/wKgKylqUxBOAFo8hAAKHUIZ3K9s443.jpg http://192.168.10.201:8000/group1/M00/00/00/wKgKylqUxBOAFo8hAAKHUIZ3K9s443.jpg http://192.168.10.200:8000/group2/M00/00/00/wKgKy1qUxBeAT0PxAAAwK2jUNaY575.png http://192.168.10.201:8000/group2/M00/00/00/wKgKy1qUxBeAT0PxAAAwK2jUNaY575.png http://192.168.10.200:8000/group3/M00/00/00/wKgKzFqUxBmATFurAAKHUIZ3K9s282.jpg http://192.168.10.201:8000/group3/M00/00/00/wKgKzFqUxBmATFurAAKHUIZ3K9s282.jpg 以上是簡單配置,屢次測試能夠發現,每個Tracker中的 Nginx都單獨對後端的Storage存儲服務器組作了負載均衡, 但整套FastDFS 集羣若是想對外提供統一的文件訪問地址,還須要對兩個Tracker中的Nginx進行HA集羣。 即對Fastdfs_tracker_t1(192.168.10.200)和Fastdfs_tracker_t2(192.168.10.201)作keepalived+nginx的高可用。 192.168.10.200 Master 192.168.10.201 Slave 192.168.10.210 VIP 也就是說整套FastDFS 集羣對外提供統一的文件訪問(VIP)地址192.168.10.210. Keepalived+Nginx 主從部署記錄能夠參考:http://www.cnblogs.com/kevingrace/p/6138185.html,部署記錄這裏就不介紹了
8)fdfs經常使用命令
1)上傳文件命令:fdfs_upload_file 不只能夠上傳圖片文件,也能夠上傳其餘文件。 [root@Fastdfs_client src]# echo "hahaha" > test.txt [root@Fastdfs_client src]# /usr/bin/fdfs_upload_file /etc/fdfs/client.conf /usr/local/src/test.txt group3/M00/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 上傳成功後,返回一串帶有組和路徑標識的字符串,這是文件的id,而後到group3組內的存儲服務器上查看這個文件的id信息 [root@Fastdfs_storage_s3 ~]# ll /fastdfs/storage/data/00/00/ total 84 -rw-r--r--. 1 root root 7 Feb 27 11:02 wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt [root@Fastdfs_storage_s3 ~]# cat /fastdfs/storage/data/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt hahaha [root@Fastdfs_storage_s3 ~]# md5sum /fastdfs/storage/data/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 5a6d311c0d8f6d1dd03c1c129061d3b1 /fastdfs/storage/data/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 2)下載文件命令:fdfs_download_file 在客戶端機器上將上面上傳到Fastdfs存儲裏文文件下載下來 [root@Fastdfs_client ~]# cd /mnt/ [root@Fastdfs_client mnt]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group3/M00/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt [root@Fastdfs_client mnt]# ls wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt [root@Fastdfs_client mnt]# cat wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt hahaha [root@Fastdfs_client mnt]# md5sum wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 5a6d311c0d8f6d1dd03c1c129061d3b1 wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 下載後能夠對比文件的md5值。 3)查看文件信息命令:fdfs_file_info [root@Fastdfs_client ~]# /usr/bin/fdfs_file_info /etc/fdfs/client.conf group3/M00/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt source storage id: 0 source ip address: 192.168.10.204 file create timestamp: 2018-02-27 11:02:02 file size: 7 file crc32: 3909919332 (0xE90CA264) 4)刪除文件命令:fdfs_delete_file [root@Fastdfs_client ~]# /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group3/M00/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt 刪除以後沒有信息提示,咱們再進行下載和查找,結果以下: [root@Fastdfs_client mnt]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group3/M00/00/00/wKgKzFqUyiqAabn8AAAAB-kMomQ229.txt [2018-02-27 14:21:08] ERROR - file: tracker_proto.c, line: 48, server: 192.168.10.204:23000, response status 2 != 0 download file fail, error no: 2, error info: No such file or directory 到group3組內的存儲服務器上查看,發現沒有這個文件的id信息 [root@Fastdfs_storage_s3 ~]# ll /fastdfs/storage/data/00/00/ [root@Fastdfs_storage_s3 ~]# 5)追加文件內容命令:fdfs_upload_appender 和 fdfs_append_file 先使用命令上傳一個appender文件 [root@Fastdfs_client src]# echo "123456" > haha.txt [root@Fastdfs_client src]# /usr/bin/fdfs_upload_appender /etc/fdfs/client.conf /usr/local/src/haha.txt group1/M00/00/00/wKgKylqU_myEa194AAAAACXX7BE787.txt 到group1組內的存儲服務器上查看這個文件 [root@Fastdfs_storage_s1 ~]# ll /fastdfs/storage/data/00/00/ total 12 -rw-r--r--. 1 root root 7 Feb 27 14:45 wKgKylqU_myEa194AAAAACXX7BE787.txt [root@Fastdfs_storage_s1 ~]# cat /fastdfs/storage/data/00/00/wKgKylqU_myEa194AAAAACXX7BE787.txt 123456 而後進行內容追加 [root@Fastdfs_client src]# echo "abcdefgh" > heihei.txt [root@Fastdfs_client src]# /usr/bin/fdfs_append_file /etc/fdfs/client.conf group1/M00/00/00/wKgKylqU_myEa194AAAAACXX7BE787.txt /usr/local/src/heihei.txt 再次到group1組內的存儲服務器上查看這個文件內容 [root@Fastdfs_storage_s1 ~]# cat /fastdfs/storage/data/00/00/wKgKylqU_myEa194AAAAACXX7BE787.txt 123456 abcdefgh 或者將文件下載到本地查看 [root@Fastdfs_client src]# cd /mnt/ [root@Fastdfs_client mnt]# /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKgKylqU_myEa194AAAAACXX7BE787.txt [root@Fastdfs_client mnt]# ls wKgKylqU_myEa194AAAAACXX7BE787.txt [root@Fastdfs_client mnt]# cat wKgKylqU_myEa194AAAAACXX7BE787.txt 123456 abcdefgh 6)監控服務器狀態命令:fdfs_monitor [root@Fastdfs_client src]# /usr/bin/fdfs_monitor /etc/fdfs/client.conf [2018-02-27 14:49:06] DEBUG - base_path=/fastdfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=2, 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=2, server_index=0 tracker server is 192.168.10.200:22122 group count: 3 Group 1: group name = group1 disk total space = 50268 MB disk free space = 44987 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.10.202 ip_addr = 192.168.10.202 ACTIVE http domain = ........ ........ 7)移除故障節點示例 若是一個group組內有多個節點,其中一個節點的上的fastdfs出了問題,須要將它從組中移除,可根據下面的命令操做: a)停掉fastdfs上的storage服務 # /etc/init.d/fdfs_storaged stop # lsof -i :23000 //確保storage服務中止 b)將問題節點(好比group1組內的節點storage-node3,ip爲192.168.10.23)從組中移除 # /usr/bin/fdfs_monitor /etc/fdfs/client.conf delete group1 192.168.10.23 c)移除成功,使用fdfs_monitor命令進行監控 # /usr/bin/fdfs_monitor /etc/fdfs/client.conf 經過監控,能夠發現移除以後,storage-node3節點的狀態爲DELETED。 d)當storage-node3上的fastdfs修復後,能夠再把它加入到fastdfs組中,加入的操做只須要把storage-node3上的fastdfs服務正常啓動就好, 由於配置文件已經作了配置,若是服務正常的話,修復後的節點能夠自動加入到fastdfs組中 啓動fastdfs_storaged服務 # /etc/init.d/fdfs_storaged stop # lsof -i :23000 使用fdfs_monitor命令進行監控 # /usr/bin/fdfs_monitor /etc/fdfs/client.conf 修復後,再次監控,能夠看到,此時storage-node3已經變爲ACTIVE狀態了。