搭建fastdfs文件服务器
资源准备
- centos7
- libfastcommon 公共函数包
- FastDFS 本体
- fastdfs-nginx-module 与Nginx的关联模块
- nginx 1.15.4
官方文档
代码语言:javascript复制https://github.com/happyfish100/fastdfs/wiki
环境搭建
服务器IP规划
tracker | storeage |
---|---|
192.168.247.142 | 192.168.247.143 |
记得关闭防火墙~
tracker
代码语言:javascript复制# 创建部署包文件夹
mkdir /home/software/FASTDFS -p
将包上传到该文件夹下
安装依赖环境
代码语言:javascript复制yum install -y gcc gcc-c
yum install -y libevent
解压包
代码语言:javascript复制# 安装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服务
代码语言:javascript复制cd /etc/fdfs/
mkdir /usr/local/fastdfs/tracker -p
vi tracker.conf
修改位置
代码语言:javascript复制# 基础路径
base_path=/usr/local/fastdfs/tracker
启动
代码语言:javascript复制/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
查看tracker服务
代码语言:javascript复制ps -ef|grep tracker
启动ok
配置storage服务
代码语言:javascript复制cd /etc/fdfs/
mkdir /usr/local/fastdfs/storage -p
vi storage.conf
修改位置
代码语言:javascript复制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
启动
代码语言:javascript复制/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
查看storage服务
代码语言:javascript复制ps -ef|grep storaged
启动ok
注意
需要先启动tracker, 然后启动storaged
测试
修改storage的client配置
代码语言:javascript复制cd /etc/fdfs/
mkdir /usr/local/fastdfs/client -p
vi client.conf
修改配置
代码语言:javascript复制base_path=/usr/local/fastdfs/client
# 修改一行注释一行
tracker_server=192.168.247.142:22122
# tracker_server=192.168.0.197:22122
测试
代码语言:javascript复制cd /usr/bin/
# 下载一张图片
wget https://img14.360buyimg.com/n0/jfs/t1/164012/18/30376/165351/63283bb6E1497b8c7/b15be526f4c39894.jpg
下载完成后可以看到存储的名字
移动到home下并重命名
代码语言:javascript复制mv b15be526f4c39894.jpg /home/test.jpg
测试上传图片
代码语言:javascript复制/usr/bin/fdfs_test /etc/fdfs/client.conf upload /home/test.jpg
返回结果
代码语言:javascript复制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
返回的URL还不能直接访问, 需要配合Nginx