FastDFS是一个开源高性能分布式文件系统(DFS)。它的主要功能包括:文件存储,文件同步和文件访问,以及高容量和负载平衡的设计
源码托管在Github上: https://github.com/happyfish100
原理可以参考这篇文章: http://www.tuicool.com/articles/YniEnyf
创建相关目录
mkdir /home/dfs #创建数据存储目录
cd /usr/local/src #切换到安装目录准备下载安装包
在每一台tracker和storage服务器上安装libfatscommon
yum install git gcc gcc-c++ make automake autoconf libtool pcre pcre-devel zlib zlib-devel openssl-devel wget vim -y #相关依赖包安装一下
git clone https://github.com/happyfish100/libfastcommon.git --depth 1
cd libfastcommon/
./make.sh && ./make.sh install #编译安装
在每一台tracker和storage服务器上执行
cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs.git --depth 1
cd fastdfs/
./make.sh && ./make.sh install #编译安装
#配置文件准备
cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf #客户端文件,测试用
cp /usr/local/src/fastdfs/conf/http.conf /etc/fdfs/ #供nginx访问使用
cp /usr/local/src/fastdfs/conf/mime.types /etc/fdfs/ #供nginx访问使用
cd ../ #返回上一级目录
git clone https://github.com/happyfish100/fastdfs-nginx-module.git --depth 1
cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs
useradd -M -s /sbin/nologin nginx
yum install -y redhat-rpm-config pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel perl-ExtUtils-Embed GeoIP-devel gperftools gperftools-devel
wget http://nginx.org/download/nginx-1.15.4.tar.gz #下载nginx压缩包
tar -zxvf nginx-1.15.4.tar.gz #解压
cd nginx-1.15.4/
./configure --add-module=/usr/local/src/fastdfs-nginx-module/src/
make && make install #编译安装
修改tracker配置文件/etc/fdfs/tracker.conf
#需要修改的内容如下
port=22122 # tracker服务器端口(默认22122,一般不修改)
base_path=/home/dfs # 存储日志和数据的根目录
修改storage配置文件/etc/fdfs/storage.conf
#需要修改的内容如下
port=23000 # storage服务端口(默认23000,一般不修改)
base_path=/home/dfs # 数据和日志文件存储根目录
store_path0=/home/dfs # 第一个存储目录
tracker_server=192.168.253.128:22122 # tracker服务器IP和端口,有多个tracker就填写多个
tracker_server=192.168.253.158:22122
tracker_server=192.168.253.168:22122
http.server_port=8888 # http访问文件的端口(默认8888,看情况修改,和nginx中保持一致)
修改配置文件/etc/fdfs/client.conf
base_path=/home/dfs
tracker_server=192.168.253.128:22122 # tracker服务器IP和端口,有多个tracker就填写多个
tracker_server=192.168.253.158:22122
tracker_server=192.168.253.168:22122
修改/etc/fdfs/mod_fastdfs.conf
tracker_server=192.168.253.128:22122 # tracker服务器IP和端口,有多个tracker就填写多个
tracker_server=192.168.253.158:22122
tracker_server=192.168.253.168:22122
url_have_group_name = false #这一项是设置url是否包含group,false为不包含
修改nginx配置文件/usr/local/nginx/conf/nginx.conf
server {
listen 8888; ## 该端口为storage.conf中的http.server_port相同
server_name localhost;
location /M00 {
alias /home/dfs;
ngx_fastdfs_module;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
/etc/init.d/fdfs_trackerd start #启动tracker服务
/etc/init.d/fdfs_trackerd restart #重启动tracker服务
/etc/init.d/fdfs_trackerd stop #停止tracker服务
chkconfig fdfs_trackerd on #自启动tracker服务
/etc/init.d/fdfs_storaged start #启动storage服务
/etc/init.d/fdfs_storaged restart #重动storage服务
/etc/init.d/fdfs_storaged stop #停止动storage服务
chkconfig fdfs_storaged on #自启动storage服务
/usr/local/nginx/sbin/nginx #启动
/usr/local/nginx/sbin/nginx -s reload #重载
/usr/local/nginx/sbin/nginx -s stop # 停止
/usr/bin/fdfs_monitor /etc/fdfs/storage.conf
这里只分了一组 如果需要多分几组可以在配置文件/etc/fdfs/storage.conf,修改这一项
group_name=group1
fdfs_upload_file /etc/fdfs/client.conf /etc/fstab #上传一个文件
这个url是跟刚才上传文件返回的fid有关
curl http://192.168.253.128:8888/M00/00/00/wKj9nlvoKk-ABSu9AAAB0SJZwMg0358063
参考文章:
http://www.tuicool.com/articles/YniEnyf
http://joelhy.github.io/2015/01/27/FastDFS-v5-06-deploy/
https://github.com/happyfish100