FastDFS是一个开源的轻量级分布式文件系统,由跟踪服务器(tracker server)、存储服务器(storage server)和客户端(client)三个部分组成,主要解决了海量数据存储问题,特别适合以中小文件(建议范围:4KB < file_size <500MB)为载体的在线服务。在生成环境FastDFS一般都是用集群配置,以提高FastDFS的可用性,并发能力。
部署架构:

环境IP地址(关闭所有环境的防火墙):
Tracker 192.168.18.178
Group 1:
  S1:192.168.110.71
  S2:192.168.110.91
Group 2:
  S3:192.168.100.90
  S4:192.168.100.194
注:Tracker可以部署多台,提供负载,这里资源有限,就部署一台。
由于需要安装nginx,每台机器都安装依赖:
yum -y install  zlib pcre pcre-devel zlib-devel
所用的安装软件到Linux公社资源站下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2017年资料/1月/23日/FastDFS之文件服务器集群部署详解/
------------------------------------------分割线------------------------------------------
一、安装tracker
1.安装依赖libfastcommon
unzip libfastcommon-master.zip
cd libfastcommon
./make.sh 
./make.sh  install
2.安装FastDFS
unzip fastdfs.zip
cd fastdfs
./make.sh
./make.sh install
默认安装目录:/usr/bin
将原安装文件夹下的配置文件复制到/etc/fdfs目下:cp ./conf/*  /etc/fdfs/
3.配置
编辑配置文件目录下的tracker.conf
一般只需改动以下几个参数即可:
disabled=false            #启用配置文件
port=22122                #设置tracker的端口号
base_path=/home/fastdfs  #设置tracker的数据文件和日志目录(需预先创建)
http.server_port=8080    #设置http端口号
4.启动
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf start
二、安装tracker代理nginx
在tracker上安装的nginx主要为了提供http访问的反向代理、负载均衡以及缓存服务。
1.安装nginx
tar -zxvf nginx-1.8.0.tar.gz 
tar -zxvf ngx_cache_purge-2.3.tar.gz 
cd nginx-1.8.0
./configure --prefix=/usr/local/nginx --add-module=/root/ngx_cache_purge-2.3
make 
make install
如果提示错误,可能缺少依赖的软件包,需先安装依赖包,再次运行./configure
nginx以及nginx cache purge插件模块安装完成,安装目录/usr/local/nginx
2.配置nginx
user  root;  
worker_processes  1;  
    
#error_log  logs/error.log;  
#error_log  logs/error.log  notice;  
error_log  logs/error.log  info;  
    
#pid        logs/nginx.pid;  
    
    
events {  
    worker_connections  1024;  
}  
    
    
http {  
    include      mime.types;  
    default_type  application/octet-stream;  
    #设置缓存参数  
    server_names_hash_bucket_size 128;  
    client_header_buffer_size 32k;  
    large_client_header_buffers 4 32k;  
    client_max_body_size 300m;  
    sendfile        on;  
    tcp_nopush    on;  
    proxy_redirect off;  
    proxy_set_header Host $http_host;  
    proxy_set_header X-Real-IP $remote_addr;  
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;  
    proxy_connect_timeout 90;  
    proxy_send_timeout 90;  
    proxy_read_timeout 90;  
    proxy_buffer_size 16k;  
    proxy_buffers 4 64k;  
    proxy_busy_buffers_size 128k;  
    proxy_temp_file_write_size 128k;  
    #设置缓存存储路径、存储方式、分配内存大小、磁盘最大空间、缓存期限  
    proxy_cache_path /var/cache/nginx/proxy_cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;  
        
    proxy_temp_path /var/cache/nginx/proxy_cache/tmp;  
    
    keepalive_timeout  65;  
    
    #设置group服务器  
    upstream fdfs_group1 {  
        server 192.168.110.71:8090 weight=1 max_fails=2 fail_timeout=30s;  
        server 192.168.110.91:8090 weight=1 max_fails=2 fail_timeout=30s;  
    }  
    upstream fdfs_group2 {  
        server 192.168.100.90:8090 weight=1 max_fails=2 fail_timeout=30s;  
        server 192.168.100.194:8090 weight=1 max_fails=2 fail_timeout=30s;  
    }  
    
    server {  
        listen      80;  
        server_name  localhost;  
        charset utf-8;  
        #access_log  /usr/local/nginx/logs/localhost.access.log  main;  
    
        location /group1/M00 {  
                proxy_next_upstream http_502 http_504 error timeout invalid_header;  
                proxy_cache http-cache;  
                proxy_cache_valid  200 304 12h;  
                proxy_cache_key $uri$is_args$args;  
                proxy_pass ;  
                expires 30d;  
        }  
        location /group2/M00 {  
                proxy_next_upstream http_502 http_504 error timeout invalid_header;  
                proxy_cache http-cache;  
                proxy_cache_valid  200 304 12h;  
                proxy_cache_key $uri$is_args$args;  
                proxy_pass ;  
                expires 30d;  
        }  
        #设置清除缓存的访问权限  
        location ~ /purge(/.*) {  
                allow 127.0.0.1;  
                allow 172.16.1.0/24;  
                deny all;  
                proxy_cache_purge http-cache  $1$is_args$args;  
        }  
    }  
    
}
创建缓存目录:/var/cache/nginx/proxy_cache/tmp
3.启动
/usr/local/nginx/sbin/nginx
三、安装storage
1.安装
参考安装tracker前2步骤。
2.配置
编辑配置文件目录下的storage.conf

