zoukankan      html  css  js  c++  java
  • FastDFS-文件服务器

    参考地址:

      https://blog.csdn.net/kamroselee/article/details/80334621
      https://www.cnblogs.com/chiangchou/p/fastdfs.html

    一、FastDFS编译:

    1. 下载安装libfastcommon:

    下载:   wget -P /srv/ftp https://github.com/happyfish100/libfastcommon/archive/V1.0.39.tar.gz
    解压:   tar xzvf /srv/ftp/V1.0.39.tar.gz -C /usr/local/src/
    重命名:  mv /usr/local/src/libfastcommon-1.0.39 /usr/local/src/libfastcommon
    进入目录: cd /usr/local/src/libfastcommon/  
    编译:  ./make.sh         
    安装:  ./make.sh install   

    2. 创建两个软连接:

    ln -sv /usr/include/fastcommon/ /usr/local/include/fastcommon
    ln -sv /usr/lib/libfastcommon.so /usr/local/lib/libfastcommon.so

    3. 将FastDFS上传进行进行编译安装:

    解压:  tar xzvf /srv/ftp/FastDFS_v5.08.tar.gz  -C /usr/local/src/
    进入目录:cd /usr/local/src/FastDFS/
    编译:  ./make.sh
    安装:  ./make.sh install

      检查是否安装成功:“ll /etc/fdfs/”,是否有配置模板;

    二、fastdfs-tracker(追踪)服务安装:

    1.通过模板复制一个tracker配置文件:

    cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

    2. 创建一个目录进行数据存储:

    cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf

    3. 修改tracker.conf配置文件:vim /etc/fdfs/tracker.conf

    port=22122      //tracker服务端口
    base_path=/usr/data/fdfs/tracker  //tracker数据存储目录

    4. 进行客户端配置文件拷贝:

    cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf

    5. 创建客户端信息的存储目录:

    mkdir -p /usr/data/fdfs/client

    6. 编辑“client.conf”配置文件:vim /etc/fdfs/client.conf

    base_path=/usr/data/fdfs/client
    tracker_server=192.168.195.160:22122

    7. 启动tracker服务:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

    8.此时可以通过client上传图片进行验证:(建议storagr服务安装完成一起测试)

    /usr/bin/fdfs_test /etc/fdfs/client.conf upload /srv/ftp/xb.png  //上传
    /usr/bin/fdfs_download_file /etc/fdfs/client.conf group1/M00/00/00/wKjDoV0lfHSAbXyxAAGQU2qW1Zw280.png  //下载
    /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKjDoV0lfHSAbXyxAAGQU2qW1Zw280.png    //删除
    /usr/bin/fdfs_monitor /etc/fdfs/client.conf  //查看所有主机状态

    三、fastdfs-storage(存储)服务安装:

    1. 通过模板复制一个storage配置文件:

    cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

    2. 定义一个目录负责存储storage数据:mkdir -p /usr/data/fdfs/storage

    3. 配置“storage.conf”配置文件:vim /etc/fdfs/storage.conf

    base_path=/usr/data/fdfs/storage    //数据保存目录
    store_path0=/usr/data/fdfs/storage   //数据存储目录,可以在此挂载多个路径
    tracker_server=192.168.195.160:22122  //tracker服务地址

    4. 启动storage服务:

    三、fastdfs-storage(存储)服务安装:

    1. 通过模板复制一个storage配置文件:

    cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf

    2. 定义一个目录负责存储storage数据:mkdir -p /usr/data/fdfs/storage

    3. 配置“storage.conf”配置文件:vim /etc/fdfs/storage.conf

    base_path=/usr/data/fdfs/storage    //数据保存目录
    store_path0=/usr/data/fdfs/storage   //数据存储目录,可以在此挂载多个路径
    tracker_server=192.168.195.160:22122  //tracker服务地址

    4. 启动storage服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

    四、storage配置nginx:

    1. 将fastdfs与nginx有关的程序包上传:

    2. 解压到“usr/local/src”目录中:

    tar xzvf /srv/ftp/nginx-1.11.3.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/echo-nginx-module-0.59.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/ngx_cache_purge-2.3.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/nginx-upstream-fair-a18b409.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/pcre-8.36.tar.gz -C /usr/local/src/
    tar xvf /srv/ftp/zlib-1.2.8.tar.gz -C /usr/local/src/

    3. 建立一个nginx存储目录:

    mkdir -p /usr/local/nginx/{logs,conf,fastcgi_temp,sbin,client_body_temp,proxy_temp,uwsgi_temp,scgi_temp}

    4. 进行nginx源代码目录进行配置、编译安装:

      》进入nginx源代码目录:cd /usr/local/src/nginx-1.11.3/

      》编译前的配置:

    ./configure --prefix=/usr/local/nginx/ 
    --sbin-path=/usr/local/nginx/sbin/ 
    --with-http_ssl_module 
    --conf-path=/usr/local/nginx/conf/nginx.conf 
    --pid-path=/usr/local/nginx/logs/nginx.pid 
    --error-log-path=/usr/local/nginx/logs/error.log 
    --http-log-path=/usr/local/nginx/logs/access.log 
    --http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp 
    --http-client-body-temp-path=/usr/local/nginx/client_body_temp 
    --http-proxy-temp-path=/usr/local/nginx/proxy_temp 
    --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp 
    --http-scgi-temp-path=/usr/local/nginx/scgi_temp 
    --add-module=/usr/local/src/echo-nginx-module-0.59 
    --add-module=/usr/local/src/gnosek-nginx-upstream-fair-a18b409 
    --add-module=/usr/local/src/ngx_cache_purge-2.3 
    --add-module=/usr/local/src/fastdfs-nginx-module/src 
    --with-zlib=/usr/local/src/zlib-1.2.8 
    --with-pcre=/usr/local/src/pcre-8.36

      》程序编译的时候会出现一个错误,打开目录进行修改:vim /usr/local/src/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/"  //修改后

      》执行编译和安装:make && make install

    5. 此时进行nginx与storage整合:

      》拷贝配置文件:cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/

      》修改“mod_fastdfs.conf”配置文件:vim /etc/fdfs/mod_fastdfs.conf 

    base_path=/usr/data/fdfs/storage      //设置storage存储地址
    tracker_server=192.168.195.160:22122    //tracker服务地址
    group_name=group1               //设置存储组名称
    url_have_group_name = true          //设置URL显示组名
    store_path0=/usr/data/fdfs/storage     //设置数组存储节点

    6. 要想HTTP访问,还需要两个Http配置文件:

    cp /usr/local/src/FastDFS/conf/http.conf /etc/fdfs/
    cp /usr/local/src/FastDFS/conf/mime.types /etc/fdfs/

    7. 在进行文件上传的时候有一个“M00”的路径,如果要想通过nginx访问,必须为其设置一个软连接:ln -s /usr/data/fdfs/storage /usr/data/fdfs/storage/M00

    8. 修改nginx配置文件:vim /usr/local/nginx/conf/nginx.conf

            location ~/group[1-3]/M00 {
                    root /usr/data/fdfs/storage/ ;
                    ngx_fastdfs_module ;
            }

    9. 进行nginx的测试:/usr/local/nginx/sbin/nginx -t

    10. 如果复制配置多台storage:

      》修改:vim /etc/fdfs/storage.conf

    group_name=group2

      》修改:vim /etc/fdfs/mod_fastdfs.conf

    group_name=group2

    11. 启动storage服务:/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

         启动tracker服务:/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf

      启动nginx:/usr/local/nginx/sbin/nginx

         查看主机状态:/usr/bin/fdfs_monitor /etc/fdfs/client.conf

    五、tracker配置nginx:

    1. 将tracker与nginx有关的程序包上传:

    2. 将所有源代码解压:

    tar xzvf /srv/ftp/nginx-1.11.3.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/echo-nginx-module-0.59.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/ngx_cache_purge-2.3.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/nginx-upstream-fair-a18b409.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/fastdfs-nginx-module_v1.16.tar.gz -C /usr/local/src/
    tar xzvf /srv/ftp/pcre-8.36.tar.gz -C /usr/local/src/
    tar xvf /srv/ftp/zlib-1.2.8.tar.gz -C /usr/local/src/

    3. 创建nginx编译后的存储目录:

    mkdir -p /usr/local/nginx/{logs,conf,fastcgi_temp,sbin,client_body_temp,proxy_temp,uwsgi_temp,scgi_temp}

    4. 进行nginx源代码目录进行配置、编译安装:

      》进入nginx源代码目录:cd /usr/local/src/nginx-1.11.3/

      》编译前的配置:

    ./configure --prefix=/usr/local/nginx/ 
    --sbin-path=/usr/local/nginx/sbin/ 
    --with-http_ssl_module 
    --conf-path=/usr/local/nginx/conf/nginx.conf 
    --pid-path=/usr/local/nginx/logs/nginx.pid 
    --error-log-path=/usr/local/nginx/logs/error.log 
    --http-log-path=/usr/local/nginx/logs/access.log 
    --http-fastcgi-temp-path=/usr/local/nginx/fastcgi_temp 
    --http-client-body-temp-path=/usr/local/nginx/client_body_temp 
    --http-proxy-temp-path=/usr/local/nginx/proxy_temp 
    --http-uwsgi-temp-path=/usr/local/nginx/uwsgi_temp 
    --http-scgi-temp-path=/usr/local/nginx/scgi_temp 
    --add-module=/usr/local/src/echo-nginx-module-0.59 
    --add-module=/usr/local/src/gnosek-nginx-upstream-fair-a18b409 
    --add-module=/usr/local/src/ngx_cache_purge-2.3 
    --add-module=/usr/local/src/fastdfs-nginx-module/src 
    --with-zlib=/usr/local/src/zlib-1.2.8 
    --with-pcre=/usr/local/src/pcre-8.36

      》程序编译的时候会出现一个错误,打开目录进行修改:vim /usr/local/src/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/"  //修改后

      》执行编译和安装:make && make install

    5. 进行nginx配置文件修改:vim /usr/local/nginx/conf/nginx.conf

      》定义一些nginx数据缓存目录:mkdir -p /usr/data/ngin/{tmp,cache}

    #user  nobody;
    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  65536;
        use epoll;
    }
    
    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;
        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 /usr/data/nginx/cache levels=1:2 keys_zone=http-cache:500m max_size=10g inactive=30d;
        proxy_temp_path /usr/data/nginx/tmp;
      
        upstream fdfs_group1 {
            server 192.168.28.227:8090 weight=1 max_fails=2 fail_timeout=30s;
        }
        upstream fdfs_group2 {
            server 192.168.28.227:8091 weight=1 max_fails=2 fail_timeout=30s;
        }
    
        #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
        #                  '$status $body_bytes_sent "$http_referer" '
        #                  '"$http_user_agent" "$http_x_forwarded_for"';
        #access_log  logs/access.log  main;
        sendfile        on;
        #tcp_nopush     on;
        #keepalive_timeout  0;
        keepalive_timeout  65;
        #gzip  on;
    
        server {
            listen       80;
            server_name  localhost;
    
            #charset koi8-r;
    
            #access_log  logs/host.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 http://fdfs_group1;
                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 http://fdfs_group2;
                expires 30d;
            }
            location ~ /purge(/.*) {
                allow 127.0.0.1;
                allow 192.168.28.0/24;
                deny all;
                proxy_cache_purge http-cache  $1$is_args$args;
            }
    
            location / {
                root   html;
                index  index.html index.htm;
            }
    
            #error_page  404              /404.html;
    
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   html;
            }
    
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ .php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
    
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            #location ~ .php$ {
            #    root           html;
            #    fastcgi_pass   127.0.0.1:9000;
            #    fastcgi_index  index.php;
            #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
            #    include        fastcgi_params;
            #}
    
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            #location ~ /.ht {
            #    deny  all;
            #}
        }
        # another virtual host using mix of IP-, name-, and port-based configuration
        #
        #server {
        #    listen       8000;
        #    listen       somename:8080;
        #    server_name  somename  alias  another.alias;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
        # HTTPS server
        #
        #server {
        #    listen       443 ssl;
        #    server_name  localhost;
    
        #    ssl_certificate      cert.pem;
        #    ssl_certificate_key  cert.key;
    
        #    ssl_session_cache    shared:SSL:1m;
        #    ssl_session_timeout  5m;
    
        #    ssl_ciphers  HIGH:!aNULL:!MD5;
        #    ssl_prefer_server_ciphers  on;
    
        #    location / {
        #        root   html;
        #        index  index.html index.htm;
        #    }
        #}
    
    }

    6.  nginx启动检测:/usr/local/nginx/sbin/nginx -t

     nginx启动:/usr/local/nginx/sbin/nginx

  • 相关阅读:
    [bzoj1263]整数划分
    [bzoj3171]循环格
    [bzoj3551]Peaks加强版
    [bzoj3307]雨天的尾巴
    [bzoj2756]奇怪的游戏
    [bzoj4025]二分图
    人比人该死啊
    数据挖掘十大经典算法[0]-K-Means算法
    ISODATA算法
    CodeForces Round 197 Div2
  • 原文地址:https://www.cnblogs.com/luliang888/p/11167582.html
Copyright © 2011-2022 走看看