• FastDFS_V5.0分布式存储(介绍、安装与使用)


    介绍  架构分析(http://blog.csdn.net/MONKEY_D_MENG/article/details/6038133)

    FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。

    FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage)。
    跟踪器主要做调度工作,在访问上起负载均衡的作用。
    存储节点存储文件,完成文件管理的所有功能:存储、同步和提供存取接口,FastDFS同时对文件的metadata进行管理。所谓文件的meta data就是文件的相关属性,以键值对(key valuepair)方式表示,如:width=1024,其中的key为width,value为1024。文件metadata是文件属性列表,可以包含多个键值对。

    存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。在卷中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为一个新的卷,这样就扩大了存储系统的容量。

    上传交互
    1. client询问tracker上传到的storage,不需要附加参数;
    2. tracker返回一台可用的storage;
    3. client直接和storage通讯完成文件上传。
    下载交互
    1. client询问tracker下载文件的storage,参数为文件标识(卷名和文件名);
    2. tracker返回一台可用的storage;
    3. client直接和storage通讯完成文件下载。

     

    分以下步骤进行:

    服务器IP:192.9.38.192/193

    服务器系统信息:

    一、创建数据存储目录:

    mkdir /usr/local/odrive/fastdfs 

    mkdir /usr/local/odrive/fastdfs/tracker  #tracker目录保存运行日志

    mkdir /usr/local/odrive/fastdfs/storage  #Storage目录保存运行日志及其data数据

    二、安装依赖包:

    yum install -y zlib zlib-devel pcre pcre-devel gcc gcc-c++ openssl openssl-devel libevent libevent-devel perl unzip

    也可以手动下载以下需要的依赖包:

    fastdfs-nginx-module_v1.16.tar.gz

    FastDFS_v5.08.tar.gz

    nginx-1.9.7.tar.gz

    libfastcommon-master.zip(https://github.com/happyfish100/libfastcommon/archive/master.zip)

    三、安装libfastcommon

    cd libfastcommon-master/

    ./make.sh

    ./make.sh install

    四、安装Fastdfs

    wget http://sourceforge.net/projects/fastdfs/files/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.05/FastDFS_v5.05.tar.gz/download

    解压 进入cd FastDFS

    tar -zxvf FastDFS_v5.05.tar.gz

    sudo ./make.sh

    sudo ./make.sh install

    复制(解压源代码目录)/usr/local/odrive/installsoft/FastDFS/conf/目录下的所有文年到/etc/fdfs/目录下

    进入目录/usr/local/odrive/installsoft/fastdfs-nginx-module/src

    sudo cp mod_fastdfs.conf /etc/fdfs/

    五、配置tracker 和 storage 配置文件, 对应修改

    cd /etc/fdfs/

    vi storage.conf

    group_name=group1

    base_path=/export/fastdfs/storage

    store_path0=/export/fastdfs/storage

    tracker_server=192.9.38.192:22122

    tracker_server=192.9.38.193:22122

    http.server_port=80

    i tracker.conf

    base_path=/export/fastdfs/tracker

     

    vi mod_fastdfs.conf

    group_name=group1

    base_path=/export/fastdfs/storage

    store_path0=/export/fastdfs/storage

    tracker_server=192.9.38.192:22122

    tracker_server=192.9.38.193:22122

    url_have_group_name = true

    vi client.conf

    tracker_server=192.9.38.192:22122

    tracker_server=192.9.38.193:22122

    六、安装nginx和fastdfs-nginx-module模块

    wget http://nginx.org/download/nginx-1.8.0.tar.gz

    http://sourceforge.net/projects/fastdfs/files/FastDFS%20Nginx%20Module%20Source%20Code/fastdfs-nginx-module_v1.16.tar.gz/download

    tar zxf fastdfs-nginx-module_v1.16.tar.gz && tar zxf nginx-1.8.0.tar.gz 

    #修改模块中对应的路径,要不然模块不能正确安装加载

    cd fastdfs-nginx-module/src

    vi conf   #更改如下, 去掉local,并指定lib64(64系统)

    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

    CORE_LIBS="$CORE_LIBS -L/usr/lib64 -lfastcommon -lfdfsclient"

    修改后的示例

    ngx_addon_name=ngx_http_fastdfs_module

    HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"

    NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"

    CORE_INCS="$CORE_INCS /usr/include/fastdfs /usr/include/fastcommon/"

    CORE_LIBS="$CORE_LIBS -L/usr/lib64 -lfastcommon -lfdfsclient"

    CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='"/etc/fdfs/mod_fastdfs.conf"'"

     ulimit -SHn 102400

    useradd -s /sbin/nologin www

    cd nginx-1.8.0

    /configure --user=www --group=www --add-module=../fastdfs-nginx-module/src/ --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_realip_module

    make

    make install

    七、配置nginx

     server_name 192.9.38.192;

           root /webdata/fastdfs.com;

           index index.html index.htm;

     

       location / {

     

           if (!-e $request_filename) {

              rewrite ^(.*)$ /index.html last;

              }

     

       location /group1/M00 {

                root /export/fastdfs/storage/data/;

                ngx_fastdfs_module;

              }

     

       location ~ .*.(gif|jpg|jpeg|png|bmp|swf|js)$ {

           

    #       fastcgi_cache cache_one;  #nginx.conf 开启cache才行,要不然启动报错

           fastcgi_cache_valid 200 10m;

           fastcgi_cache_valid 304 3m;

           fastcgi_cache_valid 301 302 1h;

           fastcgi_cache_valid any 1m;

           fastcgi_cache_min_uses 1;

           fastcgi_cache_use_stale error timeout invalid_header http_500;

           fastcgi_cache_key $host$request_uri;

           access_log off;

           }

           }

     

        access_log off;

     

    }

     

    cd  /usr/local/odrive/nginx/conf

    修改nginx.conf

    添加如下内容

    server {

            listen       80;

            server_name  192.9.38.192;

            #charset koi8-r;

            #access_log  logs/host.access.log  main;

            location / {

                root   html;

                index  index.html index.htm;

            }

            location /group1/M00 {

                root /usr/local/odrive/fastdfs/storage/data/;

                ngx_fastdfs_module;

             }

            #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;

            }

     八、193 的配置一样, nginx对应的ip为193, 启动nginx和fastdfs

    /etc/init.d/nginx -t

    ngx_http_fastdfs_set pid=8985

    nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok

    nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful

    [root@test-1 vhost]# /etc/init.d/nginx -s reload

    ngx_http_fastdfs_set pid=8986

    九、测试

    在浏览器输入生成的URL:

     后续补充:相关知识,及安装配置出现的问题。

  • 相关阅读:
    16进制与10进制
    npm模块管理器
    Vue2+VueRouter2+webpack 构建项目实战(四)接通api,先渲染个列表
    cross-env使用笔记
    webpack 运行提示“The ‘mode‘ option has not been set”的原因和解决方法
    cnpm install -S 与cnpm install -D (dependencies和devDependencies的区别)
    Webpack基础学习
    webpack入门——webpack的安装与使用
    npm init 之package.json
    入门 Webpack,看这篇就够了
  • 原文地址:https://www.cnblogs.com/Caleb-NoOnly/p/6322196.html
Copyright © 2020-2023  润新知