fastdfs_v4.06分布式文件系统的安装及配置

PS:从初次接触FastDFS到对于其已经很熟悉的应用,很多人都要经历漫长的学习期,在FastDFS群里我也经常热心的回答群友的一些问题,但是随着群里人数的增加,单纯的回答越发无力,很多人没有找到合适的学习途径,以至于使用FastDFS过程中遇到种种不便利,我写这篇文章就是为了方便大家在”理解原理”后尝试手动服务器搭建FastDFS分布式文件系统环境测试,希望对他们有用!O(∩_∩)O 没有服务器就用虚拟机VMware搞吧!(*^__^*)

  • 整体网络配置

            Tracker  Server    192.168.127.11         /home/tracker  端口:22122
            Storage1 Server    192.168.127.12  group1 /home/storage  端口:23000
            Storage2 Server    192.168.127.13  group2 /home/storage  端口:23000
            Storage3 Server    192.168.127.14  group2 /home/storage  端口:23000
            #Storage2为group2的源服务器
            注意:
            1.group2同组的Storage2和Storage3 FastDFS服务端口必须一致: port=23000
            2.一台服务器可以装多个组(group)但不能装同组的多个Storage,日志会报错误,日志报错原因是"注意1"
            3.Version 4.05之前fastdfs内部绑定了libevent作为http服务器.Version 4.05之后的版本删除了内置的web http服务,O(∩_∩)O:内置的web http服务是个累赘,不用也罢!
            4.启动storage server时,一直处于僵死状态.启动storage server,storage将连接tracker server,如果连不上,将一直重试。直到连接成功,启动才算真正完成!如果集群中有2台tracker server,而其中一台tracker没有启动,可能会导致storage server一直处于僵死状态
            
  • 系统操作环境的设置

    系统初始化设置请参考—>centos系统初始化

            #软件安装包存储:
            /usr/local/src
            /usr/local/fastdfs  fastdfs安装目录
    
            #基本目录列表:
            #创建fastdfs用户
            /usr/sbin/groupadd fastdfs
            /usr/sbin/useradd -g fastdfs fastdfs
            #创建存储数据目录
            mkdir -p /home/fastdfs/tracker;#创建tracker目录保存运行日志
            mkdir -p /home/fastdfs/storage;#创建Storage目录保存运行日志及其data数据
            # source .bashrc
            

    为方便查找目录,设置变量

            **Tracker**
            # vi .bashrc
            alias  worksrc='cd /usr/local/src;ls'
            alias  workfastdfs='cd /usr/local/fastdfs;ls'
            alias  worktracker='cd /home/fastdfs/tracker;ls'
            #track启动 重启 停止
            alias  sertracker='service fdfs_trackerd'
            配置生效
            # source .bashrc
            

    为方便查找目录,设置变量

            **Storage**
            # vi .bashrc
            alias  worksrc='cd /usr/local/src;ls'
            alias  workfastdfs='cd /usr/local/fastdfs;ls'
            alias  workstorage='cd /home/fastdfs/storage;ls'
            alias  workfastdfs='cd /usr/local/nginx;ls'
            #storage启动 重启 停止
            alias  serstorage='service fdfs_storaged'
            #nginx 启动 重启 停止
            alias  sernginx='service nginxd'
            配置生效
            # source .bashrc
            
  1. 安装libevent 和 fastdfs

    • 首先安装libevent. fastdfs在编译源程序时fastdfs内部调用libevent的处理机制,,需要用到libevent一些依赖文件,否则编译fastdfs会出错

                      ##卸载系统自带libevent,自带版本过低,安装fastdfs会出错
                      rpm -qa|grep libevent;yum remove libevent*
                      #下载安装libevent
                     worksrc;
                      wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz;
                      tar -zxvf libevent-2.0.19-stable.tar.gz;
                      cd libevent-2.0.19-stable;
                      make clean;
                      ./configure --prefix=/usr/local/libevent
                      make && make install;
                      ##为libevent创建软链接到/lib库下,64位系统对应/lib64
                      ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
                      ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
                      #
                      命令汇总:worksrc;wget http://cloud.github.com/downloads/libevent/libevent/libevent-2.0.19-stable.tar.gz;tar -zxvf libevent-2.0.19-stable.tar.gz;cd libevent-2.0.19-stable;make clean;./configure --prefix=/usr/local/libevent;make && make install;cd ../
                      
    • 安装fastdfs的步骤

                      worksrc;
                      wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
                      tar -zxvf FastDFS_v4.06.tar.gz
                      cd FastDFS
                      #由于定义/usr/local/fastdfs为fastdfs安装目录,所以需要修改make.sh
                      vim make.sh
                      TARGET_PREFIX=/usr/local 修改为 /usr/local/fastdfs
                      TARGET_CONF_PATH=/etc/fdfs 修改为 /usr/local/fastdfs/conf
                      /etc/fdfs 全部替换为 /usr/local/fastdfs/conf
                      #安装
                      ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
                      ./make.sh install
                      
  2. 安装Tracker Server -192.168.127.11

    • 引用上例中安装libevent 和 fastdfs步骤
    • 配置及启动Tracker Server,端口:22122

                  #修改tracker.conf配置
                  vim /usr/local/fastdfs/conf/tracker.conf
                  # the tracker server port
                  port=22122
                  # the base path to store data and log files
                  base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs/tracker #日志目录
                  reserved_storage_space = 4GB -> reserved_storage_space = 1GB
                  #unix group name to run this program,
                  #not set (empty) means run by the group of current user
                  run_by_group= -> fastdfs
                  #unix username to run this program,
                  #not set (empty) means run by current user
                  run_by_user= -> fastdfs
                  #开启自定义server ID取代ip形式,方便内部网络服务器更换ip#**此方式要重点理解,4.0以后新特性
                  use_storage_id = true #使用server ID作为storage server标识
                  storage_ids_filename = storage_ids.conf #<id> <group_name> <ip_or_hostname>
                  id_type_in_filename = id #文件名反解析中包含server ID,以前是ip
                  
                  #移动storage_ids.conf文件
                  cp -r /usr/local/src/FastDFS/conf/storage_ids.conf /usr/local/fastdfs/conf/
                  #编辑storage服务器ID与IP地址的对应关系
                  vim /usr/local/fastdfs/conf/storage_ids.conf
                  #<id> <group_name> <ip_or_hostname>
                   100001          group1           192.168.127.12
                   100002          group2           192.168.127.13
                   100003          group2           192.168.127.14
                  
    • 启动Tracker Server

                  chown -R fastdfs:fastdfs /home/fastdfs
                  

      Tracker Server脚本

                  vim /etc/init.d/fdfs_trackerd
                  #增加下面的内容
                  #!/bin/bash
                  #
                  # fdfs_trackerd Starts fdfs_trackerd
                  #
                  #
                  # chkconfig: 2345 99 01
                  # description: FastDFS tracker server
                  ### BEGIN INIT INFO
                  # Provides: $fdfs_trackerd
                  ### END INIT INFO
                  # Source function library.
                  . /etc/init.d/functions
                  FastDfs='/usr/local/fastdfs'
                  CONF="$FastDfs/conf/tracker.conf"
                  if [ ! -f $CONF ]; then
                    echo "file $CONF does not exist!"
                    exit 2
                  fi
                  PRG="$FastDfs/bin/fdfs_trackerd"
                  if [ ! -f $PRG ]; then
                    echo "file $PRG does not exist!"
                    exit 2
                  fi
                  Stop="$FastDfs/bin/stop.sh"
                  if [ ! -f $Stop ]; then
                    echo "file $Stop does not exist!"
                    exit 2
                  fi
                  Restart="$FastDfs/bin/restart.sh"
                  if [ ! -f $Restart ]; then
                    echo "file $Restart does not exist!"
                    exit 2
                  fi
                  RETVAL=0
                  start() {
                      echo -n $"Starting FastDFS tracker server: "
                      $PRG $CONF &
                      RETVAL=$?
                      echo
                      return $RETVAL
                  }
                  stop() {
                      echo -n $"Stop FastDFS tracker server: "
                      $Stop $PRG $CONF
                      RETVAL=$?
                      return $RETVAL
                  }
                  rhstatus() {
                      status fdfs_trackerd
                  }
                  restart() {
                          $Restart $PRG $CONF &
                  }
                  case "$1" in
                    start)
                      start
                      ;;
                    stop)
                      stop
                      ;;
                    status)
                      rhstatus
                      ;;
                    restart|reload)
                      restart
                      ;;
                    condrestart)
                      restart
                      ;;
                    *)
                      echo $"Usage: $0 {start|stop|status|restart|condrestart}"
                      exit 1
                  esac
                  exit $?
                  

      启动脚本

                  #增加x权限
                  chmod a+x /etc/init.d/fdfs_trackerd
                  service fdfs_trackerd start
                  
                  # base_path 附目录说明:
                    tracker server目录及文件结构:
                    ${base_path}
                      |__data
                      |     |__storage_groups.dat:存储分组信息
                      |     |__storage_servers.dat:存储服务器列表
                      |__logs
                            |__trackerd.log:tracker server日志文件
                  

      启动成功,加入开机启动

                  # vim /etc/rc.d/rc.local
                  service fdfs_trackerd start
                  #启动过程中出现的错误
                  #./fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
                  #解决办法
                  ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
                  
    • #检查tracker是否启动成功,可以查看如下文件

                  vim /home/fastdfs/tracker/logs/trackerd.log
                  #[2012-08-26 19:01:30] INFO - FastDFS v4.06, base_path=/home/fastdfs/tracker, run_by_group=fastdfs, run_by_user=fastdfs, connect_timeout=30s, network_timeout=60s, port=22122, bind_addr=, max_connections=256, work_threads=4, store_lookup=2, store_group=, store_server=0, store_path=0, reserved_storage_space=10.00%, download_server=0, allow_ip_count=-1, sync_log_buff_interval=10s, check_active_interval=120s, thread_stack_size=64 KB, storage_ip_changed_auto_adjust=1, storage_sync_file_max_delay=86400s, storage_sync_file_max_time=300s, use_trunk_file=0, slot_min_size=256, slot_max_size=16 MB, trunk_file_size=64 MB, trunk_create_file_advance=0, trunk_create_file_time_base=02:00, trunk_create_file_interval=86400, trunk_create_file_space_threshold=20 GB, trunk_init_check_occupying=0, trunk_init_reload_from_binlog=0, use_storage_id=1, id_type_in_filename=id, storage_id_count=1, rotate_error_log=0, error_log_rotate_time=00:00, rotate_error_log_size=0, store_slave_file_use_link=0, use_connection_pool=1, g_connection_pool_max_idle_time=3600s
                  

    安装Storage Server -192.168.127.12
    配置及启动存储服务(Storage Server)

    • 引用上例中安装libevent 和 fastdfs步骤
    • 修改storage.conf配置

                  vim /usr/local/fastdfs/conf/storage.conf
                  # the name of the group this storage server belongs to
                  group_name=group1
                  # the name of the group this storage server belongs to
                  # the storage server port #the storage server port
                  port=23000
                  # the base path to store data and log files #日志目录
                  base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage
                  # store_path#, based 0, if store_path0 not exists, it's value is base_path #data数据存储目录
                  # the paths must be exist
                  store_path0=/home/fastdfs/storage
                  # tracker_server can ocur more than once, and tracker_server format is
                  #  "host:port", host can be hostname or ip address
                  tracker_server=192.168.209.121:22122 ->192.168.127.11:22122
                  #unix group name to run this program,
                  #not set (empty) means run by the group of current user
                  run_by_group= -> fastdfs
                  #unix username to run this program,
                  #not set (empty) means run by current user
                  run_by_user= -> fastdfs
                  
    • 编辑启动脚本

                  vim /etc/init.d/fdfs_storaged
                  #增加下面的内容
                  #!/bin/bash
                  #
                  # fdfs_storaged Starts fdfs_storaged
                  #
                  #
                  # chkconfig: 2345 99 01
                  # description: FastDFS storage server
                  ### BEGIN INIT INFO
                  # Provides: $fdfs_storaged
                  ### END INIT INFO
                  # Source function library.
                  . /etc/init.d/functions
                  FastDfs='/usr/local/fastdfs'
                  CONF="$FastDfs/conf/storage.conf"
                  if [ ! -f $CONF ]; then
                    echo "file $CONF does not exist!"
                    exit 2
                  fi
                  PRG="$FastDfs/bin/fdfs_storaged"
                  if [ ! -f $PRG ]; then
                    echo "file $PRG does not exist!"
                    exit 2
                  fi
                  Stop="$FastDfs/bin/stop.sh"
                  if [ ! -f $Stop ]; then
                    echo "file $Stop does not exist!"
                    exit 2
                  fi
                  Restart="$FastDfs/bin/restart.sh"
                  if [ ! -f $Restart ]; then
                    echo "file $Restart does not exist!"
                    exit 2
                  fi
                  RETVAL=0
                  start() {
                      echo -n $"Starting FastDFS storage server: "
                      $PRG $CONF &
                      RETVAL=$?
                      echo
                      return $RETVAL
                  }
                  stop() {
                      echo -n $"Stop FastDFS storage server: "
                      $Stop $PRG $CONF
                      RETVAL=$?
                      return $RETVAL
                  }
                  rhstatus() {
                      status fdfs_storaged
                  }
                  restart() {
                          $Restart $PRG $CONF &
                  }
                  case "$1" in
                    start)
                      start
                      ;;
                    stop)
                      stop
                      ;;
                    status)
                      rhstatus
                      ;;
                    restart|reload)
                      restart
                      ;;
                    condrestart)
                      restart
                      ;;
                    *)
                      echo $"Usage: $0 {start|stop|status|restart|condrestart}"
                      exit 1
                  esac
                  exit $?
                  #
                  #增加x权限
                  chmod a+x /etc/init.d/fdfs_storaged
                  
                  #启动storage
                  service fdfs_storaged restart
                  #接下来会出现很多mkdir data path,这是系统在创建数据目录
                  data path: /home/fastdfs/storage/data, mkdir sub dir...
                  mkdir data path: 00 ...
                  mkdir data path: 01 ...
                  mkdir data path: 02 ...
                  mkdir data path: 03 ...
                  .......................
                  data path: /home/fastdfs/storage/data, mkdir sub dir done.
                  
                  # base_path 附目录说明:
                    storage server目录及文件结构:
                    ${base_path}
                      |__data
                      |     |__storage_stat.dat:本地存储信息
                      |     |__sync
                      |           |__ binlog.000
                      |           |__ binlog.index
                      |__logs
                            |__storaged.log:storage server日志文件
                  
                  #启动成功,加入开机启动
                  # vim /etc/rc.d/rc.local
                  service fdfs_storaged restart
                  
    • Storage安装fastdfs-nginx-module模块,通过url访问
      建议参考–详细nginx安装步骤

                  #创建相关用户和目录创建www用户和组
                  /usr/sbin/groupadd www
                  /usr/sbin/useradd -g www www
                  #创建nginx日志目录
                  mkdir -p /home/www/logs
                  chmod a+w /home/www/logs
                  chown -R www:www /home/www/logs
      
                  #安装nginx必需的库:gcc zlib-devel openssl-devel pcre
                  yum -y install gcc gcc-c++ zlib-devel openssl-devel;
      
                  手动安装pcre库,为了使nginx支持HTTP Rewrite 模块
                  #tar -zxvf pcre-8.20.tar.gz
                  cd pcre-8.20/
                  ./configure
                  make && make install
      
                  #安装基本nginx
                  tar -zxvf nginx-1.1.19.tar.gz
                  cd nginx-1.1.19/
                  ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
                  make && make install
                  #--with-http_stub_status_module 用来监控nginx的当前状态
                  

      安装fastdfs-nginx-module插件

                  worksrc;
                  wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz;
                  tar -zxvf fastdfs-nginx-module_v1.15.tar.gz;
                  #修改插件配置文件
                  vim /usr/local/src/fastdfs-nginx-module/src/config
                  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/local/fastdfs/include/fastdfs /usr/local/fastdfs/include/fastcommon/"
                  CORE_LIBS="$CORE_LIBS -L/usr/local/fastdfs/lib -lfastcommon -lfdfsclient"
                  CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/usr/local/fastdfs/conf/mod_fastdfs.conf\"'"
      
                  #复制mod_fastdfs.conf到/usr/local/fastdfs/conf/目录下
                  cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fastdfs/conf/
                  

      上面编译时使用的动态链接库

                  #将/usr/local/fastdfs/lib 加入系统文件/etc/ld.so.conf中
                  vim /etc/ld.so.conf
                  /usr/local/fastdfs/lib
                  #更新库文件缓存ld.so.cache
                  /sbin/ldconfig
                  

      编译fastdfs-nginx-module模块

                  cd nginx-1.1.19/;
                  ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
                  make; make install;
                  

      修改mod_fastdfs.conf配置

                  vim /usr/local/fastdfs/conf/mod_fastdfs.conf
                  # the base path to store log files
                  base_path=/tmp
                  # if load FastDFS parameters from tracker server
                  # since V1.12
                  # default value is false
                  load_fdfs_parameters_from_tracker=true
                  # FastDFS tracker_server can ocur more than once, and tracker_server format is
                  #  "host:port", host can be hostname or ip address
                  # valid only when load_fdfs_parameters_from_tracker is true
                  tracker_server=192.168.25.11:22122
                  # the port of the local storage server
                  # the default value is 23000
                  storage_server_port=23000
                  # the group name of the local storage server
                  group_name=group1
                  # if the url / uri including the group name
                  # set to false when uri like /M00/00/00/xxx
                  # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
                  # default value is false
                  url_have_group_name = true
                  # path(disk or mount point) count, default value is 1
                  # must same as storage.conf
                  store_path_count=1
                  # store_path#, based 0, if store_path0 not exists, it's value is base_path
                  # the paths must be exist
                  # must same as storage.conf
                  store_path0=/home/fastdfs/storage
                  # set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
                  # empty for output to stderr (apache and nginx error_log file)
                  log_filename=/home/www/logs/mod_fastdfs.log
                  

      nginx配置简洁版本

                  #vim /usr/local/nginx/conf/nginx.conf
                  user  www www;
                  worker_processes  2;
                  error_log  /home/www/logs/error.log  notice;
                  pid        /home/www/logs/nginx.pid;
      
                  worker_rlimit_nofile 5120;
                  events {
                      use epoll;
                      worker_connections  5120;
                  }
      
                  http {
                      include       mime.types;
                      default_type  application/octet-stream;
      
                      sendfile        on;
                      tcp_nopush     on;
                      keepalive_timeout  60;
                      tcp_nodelay on;
      
                      server {
                          listen       80;
                          server_name  localhost;
                          location /group1/M00 {
                              alias /home/fastdfs/storage/data;
                              ngx_fastdfs_module;
                          }
                      }
                  }
      
                  #启动nginx
                  #脚本在《详细nginx安装步骤》
                  sernginx start
                  

    安装Storage Server -192.168.127.13
    配置及启动存储服务(Storage Server)

    • 引用上例中安装libevent 和 fastdfs步骤
    • 修改storage.conf配置

                  vim /usr/local/fastdfs/conf/storage.conf
                  # the name of the group this storage server belongs to
                  group_name=group2
                  # the name of the group this storage server belongs to
                  # the storage server port #the storage server port
                  port=23000
                  # the base path to store data and log files #日志目录
                  base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage
                  # store_path#, based 0, if store_path0 not exists, it's value is base_path #data数据存储目录
                  # the paths must be exist
                  store_path0=/home/fastdfs/storage
                  #unix group name to run this program,
                  #not set (empty) means run by the group of current user
                  run_by_group= -> fastdfs
                  #unix username to run this program,
                  #not set (empty) means run by current user
                  run_by_user= -> fastdfs
                  # tracker_server can ocur more than once, and tracker_server format is
                  #  "host:port", host can be hostname or ip address
                  tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122
                  
    • 引用上例中’编辑启动脚本’步骤
    • 启动storage

                  service fdfs_storaged restart
                  #接下来会出现很多mkdir data path,这是系统在创建数据目录
                  data path: /home/fastdfs/storage/data, mkdir sub dir...
                  mkdir data path: 00 ...
                  mkdir data path: 01 ...
                  mkdir data path: 02 ...
                  mkdir data path: 03 ...
                  .......................
                  data path: /home/fastdfs/storage/data, mkdir sub dir done.
                  
                  #启动成功,加入开机启动
                  # vim /etc/rc.d/rc.local
                  service fdfs_storaged restart
                  
    • Storage安装fastdfs-nginx-module模块,通过url访问

      1. nginx安装参考上例或详细nginx安装步骤
      2. 安装fastdfs-nginx-module插件

                            worksrc;
                            wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz;
                            tar -zxvf fastdfs-nginx-module_v1.15.tar.gz;
                            #修改插件配置文件
                            vim /usr/local/src/fastdfs-nginx-module/src/config
                            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/local/fastdfs/include/fastdfs /usr/local/fastdfs/include/fastcommon/"
                            CORE_LIBS="$CORE_LIBS -L/usr/local/fastdfs/lib -lfastcommon -lfdfsclient"
                            CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/usr/local/fastdfs/conf/mod_fastdfs.conf\"'"
        
                            #复制mod_fastdfs.conf到/usr/local/fastdfs/conf/目录下
                            cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fastdfs/conf/
                            

        上面编译时使用的动态链接库

                            #将/usr/local/fastdfs/lib 加入系统文件/etc/ld.so.conf中
                            vim /etc/ld.so.conf
                            /usr/local/fastdfs/lib
                            #更新库文件缓存ld.so.cache
                            /sbin/ldconfig
                            
      3. 编译fastdfs-nginx-module模块

                            cd nginx-1.1.19/;
                            ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
                            make; make install;
                            

        修改mod_fastdfs.conf配置

                            vim /usr/local/fastdfs/conf/mod_fastdfs.conf
                            # the base path to store log files
                            base_path=/tmp
                            # if load FastDFS parameters from tracker server
                            # since V1.12
                            # default value is false
                            load_fdfs_parameters_from_tracker=true
                            # FastDFS tracker_server can ocur more than once, and tracker_server format is
                            #  "host:port", host can be hostname or ip address
                            # valid only when load_fdfs_parameters_from_tracker is true
                            tracker_server=192.168.25.11:22122
                            # the port of the local storage server
                            # the default value is 23000
                            storage_server_port=23000
                            # the group name of the local storage server
                            group_name=group2
                            # if the url / uri including the group name
                            # set to false when uri like /M00/00/00/xxx
                            # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
                            # default value is false
                            url_have_group_name = true
                            # path(disk or mount point) count, default value is 1
                            # must same as storage.conf
                            store_path_count=1
                            # store_path#, based 0, if store_path0 not exists, it's value is base_path
                            # the paths must be exist
                            # must same as storage.conf
                            store_path0=/home/fastdfs/storage
                            # set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
                            # empty for output to stderr (apache and nginx error_log file)
                            log_filename=/home/www/logs/mod_fastdfs.log
                            

        nginx配置简洁版本

                            #vim /usr/local/nginx/conf/nginx.conf
                            user  www www;
                            worker_processes  2;
                            error_log  /home/www/logs/error.log  notice;
                            pid        /home/www/logs/nginx.pid;
        
                            worker_rlimit_nofile 5120;
                            events {
                                use epoll;
                                worker_connections  5120;
                            }
        
                            http {
                                include       mime.types;
                                default_type  application/octet-stream;
        
                                sendfile        on;
                                tcp_nopush     on;
                                keepalive_timeout  60;
                                tcp_nodelay on;
        
                                server {
                                    listen       80;
                                    server_name  localhost;
                                    location /group2/M00 {
                                        alias /home/fastdfs/storage/data;
                                        ngx_fastdfs_module;
                                    }
                                }
                            }
        
                            #启动nginx
                            #脚本在《详细nginx安装步骤》
                            sernginx start
                            

    安装Storage Server -192.168.127.14
    参考192.168.127.13安装,不同点就是192.168.127.13是group2的源服务,storage.conf配置不同,需要注意

  3. 测试及使用fastdfs-192.168.127.11

    • fastdfs之配置client

              vim /usr/local/fastdfs/conf/client.conf
              base_path=/home/yuqing/fastdfs-> base_path=/home/fastdfs/tracker
              tracker_server=192.168.209.121:22122 -> tracker_server=192.168.127.11:22122
              
    •         cd /usr/local/bin
              vim aa.txt 增加内容:展示aa.txt文本数据   :wq
              ./fdfs_test /usr/local/fastdfs/conf/client.conf upload aa.txt
              

      执行成功后会出现如下提示:

              # ./fdfs_test /usr/local/fastdfs/conf/client.conf upload aa.txt
              [2012-08-25 02:08:26] INFO - base_path=/home/fastdfs/tracker, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0
              tracker_query_storage_store_list_without_group:
                      server 1. group_name=group2, ip_addr=192.168.127.13, port=23000
              group_name=group2, ip_addr=192.168.127.6, port=23000
              storage_upload_by_filename
              group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710.txt
              source ip address: 192.168.127.13
              file timestamp=2012-08-25 02:08:26
              file size=7
              file crc32=3422443254
              file url:
              storage_upload_slave_by_filename
              group_name=group2, remote_filename=M00/00/00/wKh_BlA3wxql4hTXAAAAB8v-VvY710_big.txt
              source ip address: 192.168.127.6
              file timestamp=2012-08-25 02:08:26
              file size=7
              file crc32=3422443254
              file url:
              
              执行过程中可能出现防火墙封口:
              # ERROR - file: tracker_proto.c, line: 420, connect to 192.168.127.11:22122 fail, errno: 113, error info: No route to host
              解决:
              iptables -L;iptables -F;service iptables stop
              
    • 测试下载文件
      在浏览器中,输入上图中的url地址, tracker server会自动重定向到存储文件的storage server,文件下载成功。至此,已经成功搭建了fastdfs,编写你自己的client来进行访问吧:

              展示aa.txt文本数据
              
    • 常规命令范例:

              #监控storage
              /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/storage.conf
              #如果存在多个多个组,只需要监控其中一个组,就能调出所有组的状态
      
              #删除组内服务器storage和查看各个组内服务器状态
              /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/client.conf delete group2 192.168.127.13
              /usr/local/fastdfs/bin/fdfs_monitor /usr/local/fastdfs/conf/client.conf
              storage server有7个状态,如下(数值从1~7):
              # FDFS_STORAGE_STATUS:INIT      :初始化,尚未得到同步已有数据的源服务器
              # FDFS_STORAGE_STATUS:WAIT_SYNC :等待同步,已得到同步已有数据的源服务器
              # FDFS_STORAGE_STATUS:SYNCING   :同步中
              # FDFS_STORAGE_STATUS:DELETED   :已删除,该服务器从本组中摘除
              # FDFS_STORAGE_STATUS:OFFLINE   :离线
              # FDFS_STORAGE_STATUS:ONLINE    :在线,尚不能提供服务
              # FDFS_STORAGE_STATUS:ACTIVE    :在线,可以提供服务
              

FastDFS原理
存储节点采用了分组(group)的方式。存储系统由一个或多个group组成,group与group之间的文件是相互独立的,所有group的文件容量累加就是整个存储系统中的文件容量。一个group可以由一台或多台存储服务器组成,一个group下的存储服务器中的文件都是相同的,group中的多台存储服务器起到了冗余备份和负载均衡的作用(一个组的存储容量为该组内存储服务器容量最小的那个,不同组的Storage server之间不会相互通信,同组内的Storage server之间会相互连接进行文件同步)。

在group中增加服务器时,同步已有的文件由系统自动完成,同步完成后,系统自动将新增服务器切换到线上提供服务。

当存储空间不足或即将耗尽时,可以动态添加group。只需要增加一台或多台服务器,并将它们配置为一个新的group,这样就扩大了存储系统的容量。

FastDFS只有两个角色:Tracker server和Storage server。Tracker server作为中心结点,其主要作用是负载均衡和调度。Tracker server在内存中记录分组和Storage server的状态等信息,不记录文件索引信息,占用的内存量很少。另外,客户端(应用)和Storage server访问Tracker server时,Tracker server扫描内存中的分组和Storage server信息,然后给出应答。由此可以看出Tracker server非常轻量化,不会成为系统瓶颈。

FastDFS中的Storage server在其他文件系统中通常称作Trunk server或Data server。Storage server直接利用OS的文件系统存储文件。FastDFS不会对文件进行分块存储,客户端上传的文件和Storage server上的文件一一对应(FastDFS中的文件标识分为两个部分:组名和文件名,二者缺一不可)

相关文章
  1. gearman应用-分布式图库系统设计
  2. FastDFS 4.06配置详细描述
  3. FastDFS storage服务器上nginx配置的root和alias指令的区别
  4. FastDFS分布式文件系统的安装及配置-多服务器版
  5. fastDFS-php 扩展安装
  6. FastDFS分布式文件系统的安装及配置-单服务器版
本站版权
1、本站所有主题由该文章作者发表,该文章作者与尘埃享有文章相关版权
2、其他单位或个人使用、转载或引用本文时必须同时征得该文章作者和尘埃的同意
3、本帖部分内容转载自其它媒体,但并不代表本站赞同其观点和对其真实性负责
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、原文链接:
二维码
Posted in FastDFS分布式文件系统

发表评论