FastDFS是一款类GoogleFS的开源分布式文件系统,它用纯C语言实现,支持Linux、FreeBSD、AIX等UNIX系统。它只能通过专有API对文件进行存取访问,不支持POSIX接口方式,不能mount使用。准确地讲,GoogleFS以及FastDFS、mogileFS、HDFS、TFS等类GoogleFS都不是系统级的分布式文件系统,而是应用级的分布式文件存储服务。
FastDFS是为互联网应用量身定做的分布式文件系统,充分考虑了冗余备份、负载均衡、线性扩容等机制,并注重高可用、高性能等指标。和现有的类Google FS分布式文件系统相比,FastDFS的架构和设计理念有其独到之处,主要体现在轻量级、分组方式和对等结构三个方面。
FastDFS是由国人余庆所开发,其项目地址:https://github.com/happyfish100 。
FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。跟踪器主要做调度工作,在访问上起负载均衡的作用。
执行下面的shell,下载安装包,分别是libfastcommon基础组件、fastdfs、nginx、fastdfs-nginx-module。
wget https://github.com/happyfish100/libfastcommon/archive/V1.0.7.tar.gz
wget https://github.com/happyfish100/fastdfs/archive/V5.05.tar.gz
wget http://nginx.org/download/nginx-1.11.8.tar.gz
wget http://jaist.dl.sourceforge.NET/project/fastdfs/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz
# the base path to store data and log files
base_path=/home/kevin/fastdfs/tracker/data-and-log
# the base path to store data and log files
base_path=/home/kevin/fastdfs/storage
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
store_path0=/home/kevin/fastdfs/storage/images-data0
store_path1=/home/kevin/fastdfs/storage/images-data1
store_path2=/home/kevin/fastdfs/storage/images-data2
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.32:22122
# the base path to store log files
base_path=/home/kevin/fastdfs/client/data-and-log
# tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
tracker_server=192.168.1.32:22122
kevin@orange:~/fastdfs/temp$ wget http://img.tuku.cn/file_thumb/201504/m2015042221045424.jpg
kevin@orange:~/fastdfs/temp$ /usr/bin/fdfs_test /etc/fdfs/client.conf upload ./m2015042221045424.jpg
kevin@orange:~/fastdfs/storage/images-data0$ find . -name "*.jpg"
./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105.jpg
./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105_big.jpg
kevin@orange:~/fastdfs/temp$ /usr/bin/fdfs_upload_file /etc/fdfs/client.conf m2015042221045424.jpg
group1/M00/00/00/wKgBIFmenECAAOdbAAAdgkSCZh4066.jpg
kevin@orange:~/fastdfs/storage/images-data0$ find . -name "*.jpg" | xargs ls -l
-rw-r--r-- 1 root root 7554 8月 24 17:22 ./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105_big.jpg
-rw-r--r-- 1 root root 7554 8月 24 17:22 ./data/00/00/wKgBIFmemtyAGcebAAAdgkSCZh4105.jpg
-rw-r--r-- 1 root root 7554 8月 24 17:28 ./data/00/00/wKgBIFmenECAAOdbAAAdgkSCZh4066.jpg
# 修改配置文件中的无效路径,把local去掉
vim /opt/setups/FastDFS/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/"
复制文件:cp fastdfs-5.05/conf/http.conf /etc/fdfs
复制文件:cp fastdfs-5.05/conf/mime.types /etc/fdfs
sudo apt-get install openssl libssl-dev
sudo apt-get install libpcre3 libpcre3-dev
sudo apt-get install zlib1g-dev
通过命令,查看是否安装某些包
dpkg -l | grep zlib
创建nginx文件目录
mkdir -p /usr/local/nginx /var/log/nginx /var/temp/nginx /var/lock/nginx
生成配置,注意修改最后一行(–add-module参数)
./configure \
--prefix=/usr/local/nginx \
--pid-path=/var/local/nginx/nginx.pid \
--lock-path=/var/lock/nginx/nginx.lock \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--with-http_gzip_static_module \
--http-client-body-temp-path=/var/temp/nginx/client \
--http-proxy-temp-path=/var/temp/nginx/proxy \
--http-fastcgi-temp-path=/var/temp/nginx/fastcgi \
--http-uwsgi-temp-path=/var/temp/nginx/uwsgi \
--http-scgi-temp-path=/var/temp/nginx/scgi \
--add-module=/home/kevin/fastdfs/install/soft/fastdfs-nginx-module/src
复制配置文件:cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
确认nginx的fastdfs插件是否安装成功
root@orange:/usr/local/nginx/conf# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.11.8
built by gcc 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.3)
configure arguments: --prefix=/usr/local/nginx --pid-path=/var/local/nginx/nginx.pid --lock-path=/var/lock/nginx/nginx.lock --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-http_gzip_static_module --http-client-body-temp-path=/var/temp/nginx/client --http-proxy-temp-path=/var/temp/nginx/proxy --http-fastcgi-temp-path=/var/temp/nginx/fastcgi --http-uwsgi-temp-path=/var/temp/nginx/uwsgi --http-scgi-temp-path=/var/temp/nginx/scgi --add-module=/home/kevin/fastdfs/install/soft/fastdfs-nginx-module/src
# the base path to store log files
base_path=/home/kevin/fastdfs/fastdfs-nginx-module/data-and-log/
# FastDFS tracker_server can ocur more than once, and tracker_server format is
# "host:port", host can be hostname or ip address
# valid only when load_fdfs_parameters_from_tracker is true
tracker_server=192.168.1.32:22122
# if the url / uri including the group name
# set to false when uri like /M00/00/00/xxx
# set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
# default value is false
url_have_group_name = true
# store_path#, based 0, if store_path0 not exists, it's value is base_path
# the paths must be exist
# must same as storage.conf
store_path0=/home/kevin/fastdfs/storage/images-data0
store_path1=/home/kevin/fastdfs/storage/images-data1
store_path2=/home/kevin/fastdfs/storage/images-data2
# 在http添加对其他配置文件的引用
include /usr/local/nginx/conf/conf.d/*.conf;
server {
listen 8888;
server_name localhost;
location ~/group[0-9]/ {
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
地址:http://192.168.1.32:8888
上传不同类型的文件
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf meixi.jpg
group1/M00/00/00/wKgBIFmeyGWAJHacAACiyMy3SR8400.jpg
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf gnuplot.pdf
group1/M00/00/00/wKgBIFmeyJiAFBM2ABhOlsdTgP0787.pdf
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf my_multi.cnf
group1/M00/00/00/wKgBIFmeyLeARRxPAAAHX_E2eqU506.cnf
kevin@orange:~/fastdfs/temp$ fdfs_upload_file /etc/fdfs/client.conf tiger.txt
group1/M00/00/00/wKgBIFmeyLyAEhFzAAAFTfDtQ9M236.txt
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyGWAJHacAACiyMy3SR8400.jpg
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyJiAFBM2ABhOlsdTgP0787.pdf
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyLeARRxPAAAHX_E2eqU506.cnf
wget http://192.168.1.32:8888/group1/M00/00/00/wKgBIFmeyLyAEhFzAAAFTfDtQ9M236.txt