最新fastdfs搭配nginx配置集群单个tracker管理多个storage(多个实例机器)


一、下载安装依赖

    1.1 下载依赖、解压
    1.2 安装libfastcommon
    1.3 安装fastdfs
    1.4 编辑fastdfs配置
    1.5 安装 nginx-module
    1.6 配置nginx

    192.168.2.155  安装tracker 和 storage
    192.168.2.154  安装 storage
    192.168.2.153  安装 storage

 192.168.2.155 安装


1.1 下载依赖、解压

  wget https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz -SO libfastcommon.tar.gz
  wget https://github.com/happyfish100/fastdfs/archive/V5.11.tar.gz -SO fastdfs.tar.gz
  wget https://github.com/happyfish100/fastdfs-nginx-module/archive/V1.20.tar.gz -SO fastdfs-nginx-module.tar.gz
  wget http://nginx.org/download/nginx-1.10.3.tar.gz

   如果嫌麻烦可以下载我提供的网盘的里面的都打包好了

链接: https://pan.baidu.com/s/1hoGAQ0yB-sgBvzPIEc5BaA  密码: cr82

    先安装环境   

   yum install -y gcc-c++ perl

  解压包

    tar -zxvf libfastcommon-1.0.40.tar.gz

1.2 安装libfastcommon

## 进入libfastcommon解压目录 安装

    ./make.sh
    ./make.sh install

1.3 安装 fastdfs

## 进入fastdfs解压目录

    ./make.sh
    . /make.sh install

1.4 修改配置文件

    cd /etc/fdfs/
    mv client.conf.sample client.conf
    mv storage.conf.sample storage.conf
    mv storage_ids.conf.sample storage_ids.conf
    mv tracker.conf.sample tracker.con   

## 进入创建应用log和数据目录 

    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/client
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/storage
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/tracker
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/nginx-model

   修改/etc/fdfs/client.conf配置文件

    vim client.conf

   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/client
   修改: tracker_server=192.168.2.155:22122
   修改: http.tracker_server_port=9270

  修改 tracker.conf配置文件

    vim tracker.conf

   修改/etc/fdfs/tracker.conf
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/tracker
   修改: store_group=group1
   修改: http.server_port=9270

   修改/etc/fdfs/storage.conf配置文件

     vim storage.conf

   修改: group_name=group1(这里指定分组,这个很关键,fastdfs同分组的每个storage会互相备份数据,我不需要备份所以每个节点的分组不一致)
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: store_path0=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: tracker_server=192.168.2.155:22122


   修改/etc/fdfs/mod_fastdfs.conf配置文件(可先执行完1.5再执行)
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/nginx-model
   修改: tracker_server=192.168.2.155:22122
   修改: group_name=group1
   修改: store_path0=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: url_have_group_name=true


   启动tracker

    fdfs_trackerd /etc/fdfs/tracker.conf start

  启动storage
  

     fdfs_storaged /etc/fdfs/storage.conf start


   测试启动是否正常
  

     fdfs_test /etc/fdfs/client.conf upload /root/9d545aa4d2f1ffbecf5567ae71f4e4fb.jpg

1.5 安装 nginx-module


  下载nginx-1.10.3.tar.gz源码包到/opt

     tar -zxvf nginx-1.10.3
     cd nginx-1.10.3


   编译nginx配置
  

    ./configure   --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module  --with-debug --add-module=/usr/local/fastdfs-nginx-module-1.20/src


   编译安装
  

    make
    make install


   拷贝nginx-module所需要的配置文件
  

    scp /usr/local/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf  /etc/fdfs/
    scp /home/fastdfs/fdfs/fastdfs-5.12/conf/http.conf  /etc/fdfs/
    scp /home/fastdfs/fdfs/fastdfs-5.12/conf/mime.types  /etc/fdfs/


   修改nginx配置文件(这样配置后可以通过192.168.2.155上的ng转发到这台服务器上的ng,来统一文件访问的路径。只需要通过192.168.2.155上就可以访问上面的3台storage上的文件)
   vim /usr/local/nginx/conf/nginx.conf

server {
        listen       9270;
        server_name  localhost;

        #charset koi8-r;

        #access_log  logs/host.access.log  main;

        location ~/group1/ {
            ngx_fastdfs_module;
        }

        location ~/group2/ {    #设置group1的负载均衡参数
         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 http://192.168.2.154:10000;
         expires 30d;
        }

        location ~/group3/ {    #设置group1的负载均衡参数
         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 http://192.168.2.153:10000;
         expires 30d;
        }
        
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
 
    }

   启动nginx

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  如果启动报proxy_cache http-cache的错就把这一段去掉

 重启tracker
 

    fdfs_trackerd /etc/fdfs/tracker.conf restart

 重启storage
 

    fdfs_storaged /etc/fdfs/storage.conf restart   

 192.168.2.154 安装

 

1.1 下载依赖、解压

   把上面的包kao b

    先安装环境   

   yum install -y gcc-c++ perl

  解压包

    tar -zxvf libfastcommon-1.0.40.tar.gz

1.2 安装libfastcommon

## 进入libfastcommon解压目录 安装

    ./make.sh
    ./make.sh install

1.3 安装 fastdfs

## 进入fastdfs解压目录

    ./make.sh
    ./make.sh install

1.4 修改配置文件

    cd /etc/fdfs/
    mv client.conf.sample client.conf
    mv storage.conf.sample storage.conf
    mv storage_ids.conf.sample storage_ids.conf
    mv tracker.conf.sample tracker.con   

## 进入创建应用log和数据目录 

    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/client
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/storage
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/tracker
    mkdir -p /home/fastdfs/fdfs/fastdfs-5.12/data/nginx-model

   修改/etc/fdfs/client.conf配置文件

    vim client.conf

   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/client
   修改: tracker_server=192.168.2.155:22122
   修改: http.tracker_server_port=9270

    tracker.conf配置文件(这里因为用的是192.168.2.155的tracker来协调管理的所以不需要配置启动,当然需如果需要多个tracker也可以起启动起来)

    vim tracker.conf

   修改/etc/fdfs/tracker.conf
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/tracker
   修改: store_group=group1
   修改: http.server_port=9270

   修改/etc/fdfs/storage.conf配置文件

     vim storage.conf

   修改: group_name=group2(这里指定分组,这个很关键,fastdfs同分组的每个storage会互相备份数据,我不需要备份所以每个节点的分组不一致)
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: store_path0=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: tracker_server=192.168.2.155:22122(这里指向192.168.2.155的tracker)


   修改/etc/fdfs/mod_fastdfs.conf配置文件(可先执行完1.5再执行)
   修改: base_path=/home/fastdfs/fdfs/fastdfs-5.12/data/nginx-model
   修改: tracker_server=192.168.2.155:22122
   修改: group_name=group2
   修改: store_path0=/home/fastdfs/fdfs/fastdfs-5.12/data/storage
   修改: url_have_group_name=true


  启动storage
  

     fdfs_storaged /etc/fdfs/storage.conf start

测试启动是否正常
  

     fdfs_test /etc/fdfs/client.conf upload /root/9d545aa4d2f1ffbecf5567ae71f4e4fb.jpg

 1.5 安装 nginx-module


  下载nginx-1.10.3.tar.gz源码包到/opt

     tar -zxvf nginx-1.10.3
     cd nginx-1.10.3


   编译nginx配置
  

    ./configure   --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module  --with-debug --add-module=/usr/local/fastdfs-nginx-module-1.20/src


   编译安装
  

    make
    make install


   拷贝nginx-module所需要的配置文件
  

    scp /usr/local/fastdfs-nginx-module-1.20/src/mod_fastdfs.conf  /etc/fdfs/
    scp /home/fastdfs/fdfs/fastdfs-5.12/conf/http.conf  /etc/fdfs/
    scp /home/fastdfs/fdfs/fastdfs-5.12/conf/mime.types  /etc/fdfs/


   修改nginx配置文件(这样配置后可以通过192.168.2.155上的ng转发到这台服务器上的ng,来统一文件访问的路径。只需要通过192.168.2.155上就可以访问上面的3台storage上的文件)
   vim /usr/local/nginx/conf/nginx.conf

server {
        listen       10000;
        server_name  192.168.2.154;

        location /group2/ {
            root /home/fastdfs/fdfs/fastdfs-5.12/data/storage;
            rewrite ^/group2/M01/(.*) /$1 break;
            }
       }

   
server {
        listen       9270;
        server_name  192.168.2.154;

        location ~/group2/ {
            ngx_fastdfs_module;
             }
        }   

   启动nginx

    /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf

  如果启动报proxy_cache http-cache的错就把这一段去掉

 重启storage
 

    fdfs_storaged /etc/fdfs/storage.conf restart   

   192.168.2.153  安装 同192.168.2.154

  把上面关于192.168.2.154的配置改成192.168.2.153,

   nginx.conf location /group2 改成location /group2

 

最后 java代码提交指定分组即可

        File file1 = new File(TempPath1);
        InputStream inputStream = new FileInputStream(file1);
        String group = "group1";
        StorePath groupName = storageClient.uploadFile(group, inputStream,   
        file1.length(), "png");

        System.out.println("groupName1 : "+groupName.getFullPath());

        System.out.println("groupName1 : "+groupName.getPath());

        System.out.println("groupName1 : "+groupName.getGroup()); 
        System.exit(1);

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

tomMMMMMMMMMMM

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值