搭建fastdfs檔案伺服器
資源準備
- centos7
- libfastcommon 公共函數包
- FastDFS 本體
- fastdfs-nginx-module 與Nginx的關聯子產品
- nginx 1.15.4
官方文檔
https://github.com/happyfish100/fastdfs/wiki
環境搭建
伺服器IP規劃
tracker | storeage |
192.168.247.142 | 192.168.247.143 |
記得關閉防火牆~
tracker
# 建立部署封包件夾
mkdir /home/software/FASTDFS -p
将包上傳到該檔案夾下
安裝依賴環境
yum install -y gcc gcc-c++
yum install -y libevent
解壓包
# 安裝libfastcommon
tar -zxvf libfastcommon-1.0.42.tar.gz
cd libfastcommon-1.0.42/
./make.sh
./make.sh install
# 安裝FastDFS本體
cd ../
tar -zxvf fastdfs-6.04.tar.gz
cd fastdfs-6.04/
./make.sh
./make.sh install
cd conf/
cp * /etc/fdfs/
storage 也搭建到上述的步驟
配置tracker服務
cd /etc/fdfs/
mkdir /usr/local/fastdfs/tracker -p
vi tracker.conf
修改位置
# 基礎路徑
base_path=/usr/local/fastdfs/tracker
啟動
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
檢視tracker服務
ps -ef|grep tracker
啟動ok
配置storage服務
cd /etc/fdfs/
mkdir /usr/local/fastdfs/storage -p
vi storage.conf
修改位置
group_name=dance
base_path=/usr/local/fastdfs/storage
store_path0=/usr/local/fastdfs/storage
# 預設有兩個 注釋一個修改一個
tracker_server=192.168.247.142:22122
# tracker_server=192.168.209.122:22122
啟動
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
檢視storage服務
ps -ef|grep storaged
啟動ok
注意
需要先啟動tracker, 然後啟動storaged
測試
修改storage的client配置
cd /etc/fdfs/
mkdir /usr/local/fastdfs/client -p
vi client.conf
修改配置
base_path=/usr/local/fastdfs/client
# 修改一行注釋一行
tracker_server=192.168.247.142:22122
# tracker_server=192.168.0.197:22122
測試
cd /usr/bin/
# 下載下傳一張圖檔
wget https://img14.360buyimg.com/n0/jfs/t1/164012/18/30376/165351/63283bb6E1497b8c7/b15be526f4c39894.jpg
下載下傳完成後可以看到存儲的名字
移動到home下并重命名
mv b15be526f4c39894.jpg /home/test.jpg
測試上傳圖檔
/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/test.jpg
傳回結果
This is FastDFS client test program v6.04
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.fastken.com/
for more detail.
[2022-09-20 05:50:22] DEBUG - base_path=/usr/local/fastdfs/client, connect_timeout=10, 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
# 查詢可用storage集合
tracker_query_storage_store_list_without_group:
server 1. group_name=, ip_addr=192.168.247.143, port=23000
# 确定上傳的storage
group_name=dance, ip_addr=192.168.247.143, port=23000
storage_upload_by_filename
# 上傳組 和 遠端檔案名
group_name=dance, remote_filename=M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063.jpg
# 源IP
source ip address: 192.168.247.143
# 上傳時間
file timestamp=2022-09-20 05:50:22
# 檔案大小
file size=218181
file crc32=432168862
# 上傳完成後會傳回一個位址 并不能直接通路 需要配合Nginx
example file url: http://192.168.247.143/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063.jpg
storage_upload_slave_by_filename
group_name=dance, remote_filename=M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063_big.jpg
source ip address: 192.168.247.143
file timestamp=2022-09-20 05:50:22
file size=218181
file crc32=432168862
# 大圖
example file url: http://192.168.247.143/dance/M00/00/00/wKj3j2Mptw6AIhR9AANURRnCX54063_big.jpg