赞
踩
FastDFS 是用 C 语言编写的一款开源的分布式文件系统,功能主要包括:文件存储、文件同步、文件访问(上传、下载) 等,解决了文件大容量存储和高性能访问的问题。FastDFS 特别适合以文件为载体的在线服务,如:图片、视频、文档等等。
hash
处理,避免出现重复文件,节约磁盘空间;nameserver
或 metaserver
)FastDFS 服务分别由:Tracker Server
跟踪服务器,Storage Server
存储服务器以及 Client
客户端三个部分组成。
跟踪服务器:
存储服务器:
这里的 Client,作为业务请求的发起方,通过专用接口,使用 TCP/IP
协议与跟踪服务器和存储服务器进行数据交互。
文件上传:
文件下载:
准备工作:
主机名 | 操作系统 | IP 地址 |
---|---|---|
FastDFS | CentOS7.4 | 192.168.1.1 |
安装基础包:
[root@FastDFS ~]# yum install -y make cmake gcc gcc-c++
[root@FastDFS ~]# wget https://github.com/happyfish100/libfastcommon/archive/V1.0.38.tar.gz
[root@FastDFS ~]# tar zxf V1.0.38.tar.gz -C /usr/src/
[root@FastDFS ~]# cd /usr/src/libfastcommon-1.0.38
[root@FastDFS libfastcommon-1.0.38]# ./make.sh && ./make.sh install
[root@FastDFS ~]# wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz
[root@FastDFS ~]# tar zxf V5.11.tar.gz -C /usr/src/
[root@FastDFS ~]# cd /usr/src/fastdfs-5.11
[root@FastDFS fastdfs-5.11]# ./make.sh && ./make.sh install
[root@FastDFS fastdfs-5.11]# rm -f /etc/fdfs/*
[root@FastDFS fastdfs-5.11]# cp conf/*.conf /etc/fdfs/
[root@FastDFS fastdfs-5.11]# cp conf/mime.types /etc/fdfs/
1) 配置 Tracker 服务
[root@FastDFS ~]# mkdir -p /app/fastdfs/tracker
[root@FastDFS ~]# sed -i 's/base_path.*/base_path=\/app\/fastdfs\/tracker/' /etc/fdfs/tracker.conf
[root@FastDFS ~]# fdfs_trackerd /etc/fdfs/tracker.conf
[root@FastDFS ~]# netstat -nlpt | grep 22122
2)配置 Storage 服务
[root@FastDFS ~]# mkdir /app/fastdfs/storage
[root@FastDFS ~]# sed -i 's/base_path.*/base_path=\/app\/fastdfs\/storage/' /etc/fdfs/storage.conf
[root@FastDFS ~]# sed -i 's/store_path0.*/store_path0=\/app\/fastdfs\/storage/' /etc/fdfs/storage.conf
[root@FastDFS ~]# sed -i 's/tracker_server.*/tracker_server=192.168.1.1:22122/' /etc/fdfs/storage.conf
[root@FastDFS ~]# sed -i 's/group_name.*/group_name=default/' /etc/fdfs/storage.conf
[root@FastDFS ~]# fdfs_storaged /etc/fdfs/storage.conf
[root@FastDFS ~]# netstat -nlpt | grep 23000
3)验证
[root@FastDFS ~]# fdfs_monitor /etc/fdfs/storage.conf
准备工作
[root@FastDFS ~]# mkdir /app/fastdfs/client
[root@FastDFS ~]# sed -i 's/base_path.*/base_path=\/app\/fastdfs\/client/' /etc/fdfs/client.conf
[root@FastDFS ~]# sed -i 's/tracker_server.*/tracker_server=192.168.1.1:22122/' /etc/fdfs/client.conf
1)验证上传
[root@FastDFS ~]# echo "Hello World" > Hello.txt
[root@FastDFS ~]# fdfs_upload_file /etc/fdfs/client.conf Hello.txt
default
组名,M00
磁盘,00/00
目录,wKgBAWL6CraAYL2xAAAADAsMGmk731.txt
文件名。2)验证下载
[root@FastDFS ~]# fdfs_download_file /etc/fdfs/client.conf default/M00/00/00/wKgBAWL6CraAYL2xAAAADAsMGmk731.txt
3)验证删除
[root@FastDFS ~]# fdfs_delete_file /etc/fdfs/client.conf default/M00/00/00/wKgBAWL6CraAYL2xAAAADAsMGmk731.txt
fastdfs-nginx-module
模块。[root@FastDFS ~]# yum -y install zlib zlib-devel pcre-devel
[root@FastDFS ~]# wget http://www.nginx.org/download/nginx-1.21.0.tar.gz
[root@FastDFS ~]# tar zxf nginx-1.21.0.tar.gz -C /usr/src/
[root@FastDFS ~]# wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz
[root@FastDFS ~]# tar zxf V1.20.tar.gz
[root@FastDFS ~]# sed -i 's#/usr/local/include#/usr/include/fastdfs /usr/include/fastcommon#' fastdfs-nginx-module-1.20/src/config
[root@FastDFS ~]# mv fastdfs-nginx-module-1.20 /usr/local/src/
[root@FastDFS ~]# cd /usr/src/nginx-1.21.0
[root@FastDFS nginx-1.21.0]# ./configure --prefix=/usr/local/nginx --add-module=/usr/local/src/fastdfs-nginx-module-1.20/src/
[root@FastDFS nginx-1.21.0]# make && make install
1)修改 Nginx 配置文件
[root@FastDFS ~]# vim /usr/local/nginx/conf/nginx.conf http { ... server { listen 80; server_name localhost; location / { root html; index index.html index.htm; } location ~/default/M00 { root /app/fastdfs/storage/data; ngx_fastdfs_module; } } }
2)替换操作
[root@FastDFS ~]# cp /usr/local/src/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf /etc/fdfs/
[root@FastDFS ~]# sed -i 's/tracker_server.*/tracker_server=192.168.1.1:22122/' /etc/fdfs/mod_fastdfs.conf
[root@FastDFS ~]# sed -i 's/store_path0.*/store_path0=\/app\/fastdfs\/storage/' /etc/fdfs/mod_fastdfs.conf
[root@FastDFS ~]# sed -i 's/group_name.*/group_name=default/' /etc/fdfs/mod_fastdfs.conf
[root@FastDFS ~]# sed -i 's/url_have_group_name.*/url_have_group_name=true/' /etc/fdfs/mod_fastdfs.conf
[root@FastDFS ~]# /usr/local/nginx/sbin/nginx -t
[root@FastDFS ~]# /usr/local/nginx/sbin/nginx
3)验证
[root@FastDFS ~]# ps aux | grep nginx
[root@FastDFS ~]# netstat -nlpt | grep nginx
[root@FastDFS ~]# fdfs_upload_file /etc/fdfs/client.conf Hello.txt
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。