关闭

centos6.3 64位安装FastDFS_v4.06

标签: LinuxFastDFS
1802人阅读 评论(0) 收藏 举报
分类:
    • FastDFS安装

          FastDFS是一个国产开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题.特别适合以文件为载体的在线服务,如相册网站、视频网站等等.FastDFS服务端有两个角色:跟踪器(tracker)和存储节点(storage).跟踪器主要做调度工作,在访问上起负载均衡的作用.

    • 整体网络配置

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

      01 #软件安装包存储:
      02   /usr/local/src
      03   /usr/local/fastdfs  fastdfs安装目录
      04  
      05 #基本目录列表:
      06 #创建fastdfs用户
      07   /usr/sbin/groupadd fastdfs
      08   /usr/sbin/useradd -g fastdfs fastdfs
      09 #创建存储数据目录
      10   mkdir -p /home/fastdfs/tracker;#创建tracker目录保存运行日志
      11   mkdir -p /home/fastdfs/storage;#创建Storage目录保存运行日志及其data数据
      12 # source .bashrc
    • 为方便查找目录,设置变量

      1 ################Tracker################
      2 # vi .bashrc
      3   alias  worksrc='cd /usr/local/src;ls'
      4   alias  workfastdfs='cd /usr/local/fastdfs;ls'
      5   alias  worktracker='cd /home/fastdfs/tracker;ls'
      6 #track启动 重启 停止
      7   alias  sertracker='service fdfs_trackerd'
      8 配置生效
      9 # source .bashrc
    • 为方便查找目录,设置变量

      01 ################Storage################
      02 # vi .bashrc
      03   alias  worksrc='cd /usr/local/src;ls'
      04   alias  workfastdfs='cd /usr/local/fastdfs;ls'
      05   alias  workstorage='cd /home/fastdfs/storage;ls'
      06   alias  workfastdfs='cd /usr/local/nginx;ls'
      07 #storage启动 重启 停止
      08   alias  serstorage='service fdfs_storaged'
      09 #nginx 启动 重启 停止
      10   alias  sernginx='service nginxd'
      11 配置生效
      12 # source .bashrc

    1.安装libevent 和 fastdfs

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

      01 #卸载系统自带libevent,自带版本过低,安装fastdfs会出错
      02   rpm -qa|grep libevent
      03 #  或者
      04   yum remove libevent*
      05 #下载安装libevent
      06 #worksrc;
      08   tar -zxvf libevent-2.0.19-stable.tar.gz;
      09   cd libevent-2.0.19-stable;
      10 #make clean;
      11   ./configure --prefix=/usr/local/libevent
      12   make && make install;
      13 #为libevent创建软链接到/lib库下,64位系统对应/lib64
      14   ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib/libevent-2.0.so.5
      15   ln -s /usr/local/libevent/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
      16 #命令汇总:
      17   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的步骤

      01 worksrc;
      04   tar -zxvf FastDFS_v4.06.tar.gz
      05   cd FastDFS
      06  
      07 #由于定义/usr/local/fastdfs为fastdfs安装目录,所以需要修改make.sh
      08   vim make.sh
      09 #/etc/fdfs 全部替换为 /usr/local/fastdfs/conf
      10   %s/\/etc\/fdfs/\/usr\/local\/fastdfs\/conf/g
      11  
      12 # TARGET_PREFIX=/usr/local 修改为 /usr/local/fastdfs
      13   sed -i 's:TARGET_PREFIX=.*:TARGET_PREFIX=/usr/local/fastdfs:g' make.sh
      14  
      15 # TARGET_CONF_PATH=/etc/fdfs 修改为 /usr/local/fastdfs/conf
      16   sed -i 's:TARGET_CONF_PATH=.*:TARGET_CONF_PATH=/usr/local/fastdfs/conf:g' make.sh
      17  
      18 #安装
      19   ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
      20   ./make.sh install
      修改 fastdfs 启动文件

      01 # 修改 fdfs_trackerd 配置文件
      02   vim /etc/init.d/fdfs_trackerd
      03 #替换
      04   %s/usr\/local/usr\/local\/fastdfs/g
      05   %s/etc\/fdfs/usr\/local\/fastdfs\/conf/g
      06 #增加x权限
      07   chmod a+x /etc/init.d/fdfs_trackerd
      08  
      09 # 修改 fdfs_storaged 配置文件
      10   vim /etc/init.d/fdfs_storaged
      11 #替换
      12   %s/usr\/local/usr\/local\/fastdfs/g
      13   %s/etc\/fdfs/usr\/local\/fastdfs\/conf/g
      14 #增加x权限
      15   chmod a+x /etc/init.d/fdfs_storaged



    2.安装Tracker Server - 192.168.55.222

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

      01 #修改tracker.conf配置
      02   vim /usr/local/fastdfs/conf/tracker.conf
      03 # the tracker server port
      04   port=22122
      05 # the base path to store data and log files
      06   base_path=/home/yuqing/fastdfs -> base_path=/home/fastdfs/tracker #日志目录
      07 # sed -i 's:base_path=.*:base_path=/home/fastdfs/tracker:g' tracker.conf
      08   reserved_storage_space = 4GB -> reserved_storage_space = 1GB
      09 # sed -i 's:reserved_storage_space=.*:reserved_storage_space = 1GB:g' tracker.conf
      10 #unix group name to run this program,
      11 #not set (empty) means run by the group of current user
      12   run_by_group= -> fastdfs
      13 #unix username to run this program,
      14 #not set (empty) means run by current user
      15   run_by_user= -> fastdfs
      16 #开启自定义server ID取代ip形式,方便内部网络服务器更换ip#**此方式要重点理解,4.0以后新特性
      17   use_storage_id = true #使用server ID作为storage server标识
      18   storage_ids_filename = storage_ids.conf #<id> <group_name> <ip_or_hostname>
      19   id_type_in_filename = id #文件名反解析中包含server ID,以前是ip
      复制storage_ids.conf文件
      1 cp -r /usr/local/src/FastDFS/conf/storage_ids.conf /usr/local/fastdfs/conf/
      2 #编辑storage服务器ID与IP地址的对应关系
      3   vim /usr/local/fastdfs/conf/storage_ids.conf
      4 #<id> <group_name> <ip_or_hostname>
      5 # 100001          group1           192.168.55.223
    • 设置 Tracker Server 用户及组

      1 chown -R fastdfs:fastdfs /home/fastdfs
      增加x权限
      1 chmod a+x /etc/init.d/fdfs_trackerd
      启动 Tracker

      1 service fdfs_trackerd start
      2 #启动过程中出现的错误
      3   ./fdfs_trackerd: error while loading shared libraries: libevent-2.0.so.5: cannot open shared object file: No such file or directory
      4 #解决办法
      5   ln -s /usr/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5
      6 #查看日志
      7   vim /home/fastdfs/tracker/logs/trackerd.log
      8 #启动后成功的日志
      9 #[2013-10-03 20:50:08] INFO - FastDFS v4.07, 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, accept_threads=1, 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_sy#nc_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_sp#ace_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_con#nection_pool=0, g_connection_pool_max_idle_time=3600s
      设置开机启动 Tracker
      1 vim /etc/rc.d/rc.local
      2 service fdfs_trackerd start
      附目录说明
      1 #  tracker server目录及文件结构:
      2 #  ${base_path}
      3 #    |__data
      4 #    |     |__storage_groups.dat:存储分组信息
      5 #    |     |__storage_servers.dat:存储服务器列表
      6 #    |__logs
      7 #          |__trackerd.log:tracker server日志文件



    3.安装Storage Server -192.168.55.223

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

      01 vim /usr/local/fastdfs/conf/storage.conf
      02 # the name of the group this storage server belongs to
      03   group_name=group1
      04 # the name of the group this storage server belongs to
      05 # the storage server port #the storage server port
      06   port=23000
      07 # the base path to store data and log files #日志目录
      08   base_path=/home/yuqing/fastdfs -> /home/fastdfs/storage
      09 # store_path#, based 0, if store_path0 not exists, it's value is base_path #data数据存储目录
      10 # the paths must be exist
      11   store_path0=/home/fastdfs/storage
      12 # tracker_server can ocur more than once, and tracker_server format is
      13 #  "host:port", host can be hostname or ip address
      14   tracker_server=192.168.209.121:22122 ->192.168.55.222:22122
      15 #unix group name to run this program,
      16 #not set (empty) means run by the group of current user
      17   run_by_group= -> fastdfs   #这儿一定填写执行的用户名,不然会启动报错,测试环境填写的 root
      18 #unix username to run this program,
      19 #not set (empty) means run by current user
      20   run_by_user= -> fastdfs   #这儿一定填写执行的用户名,不然会启动报错,测试环境填写的 root
      设置 Storage Server 用户及组

      1 chown -R fastdfs:fastdfs /home/fastdfs
      增加x权限
      1 chmod a+x /etc/init.d/fdfs_storaged
      启动 Storage
      1 service fdfs_storaged start
      2 #接下来会出现很多mkdir data path,这是系统在创建数据目录
      3 #data path: /home/fastdfs/storage/data, mkdir sub dir...
      4 #mkdir data path: 00 ...
      5 #mkdir data path: 01 ...
      6 #mkdir data path: 02 ...
      7 #mkdir data path: 03 ...
      8 #.......................
      9 #data path: /home/fastdfs/storage/data, mkdir sub dir done.
      设置开机启动 Storage 
      1 vim /etc/rc.d/rc.local
      2 service fdfs_storaged start
      附目录说明
      1 #  storage server目录及文件结构:
      2 #  ${base_path}
      3 #    |__data
      4 #    |     |__storage_stat.dat:本地存储信息
      5 #    |     |__sync
      6 #    |           |__ binlog.000
      7 #    |           |__ binlog.index
      8 #    |__logs
      9 #          |__storaged.log:storage server日志文件
    • 安装fastdfs-nginx-module模块

      1 #创建相关用户和目录创建www用户和组
      2   /usr/sbin/groupadd www
      3   /usr/sbin/useradd -g www www
      4 #创建nginx日志目录
      5   mkdir -p /home/www/logs
      6   chmod a+w /home/www/logs
      7   chown -R www:www /home/www/logs
      安装nginx

      1   cd /usr/local/src
      2 #下载 nginx
      4   tar -zxvf nginx-1.5.4.tar.gz
      5   cd nginx-1.5.4/
      6   ./configure --user=www --group=www --prefix=/usr/local/nginx --with-http_stub_status_module
      7   make && make install
      8 #--with-http_stub_status_module 用来监控nginx的当前状态
      安装fastdfs-nginx-module插件

      01 #worksrc;
      02   cd /usr/local/src
      04   tar -zxvf fastdfs-nginx-module_v1.15.tar.gz
      05 #修改插件配置文件
      06   vim /usr/local/src/fastdfs-nginx-module/src/config
      07 ngx_addon_name=ngx_http_fastdfs_module
      08 HTTP_MODULES="$HTTP_MODULES ngx_http_fastdfs_module"
      09 NGX_ADDON_SRCS="$NGX_ADDON_SRCS $ngx_addon_dir/ngx_http_fastdfs_module.c"
      10 CORE_INCS="$CORE_INCS /usr/local/fastdfs/include/fastdfs /usr/local/fastdfs/include/fastcommon/"
      11 CORE_LIBS="$CORE_LIBS -L/usr/local/fastdfs/lib -lfastcommon -lfdfsclient"
      12 CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64 -DFDFS_OUTPUT_CHUNK_SIZE='256*1024' -DFDFS_MOD_CONF_FILENAME='\"/usr/local/fastdfs/conf/mod_fastdfs.conf\"'"
      13 #复制mod_fastdfs.conf到/usr/local/fastdfs/conf/目录下
      14   cp /usr/local/src/fastdfs-nginx-module/src/mod_fastdfs.conf /usr/local/fastdfs/conf/
      上面编译时使用的动态链接库

      1 #启动nginx报错
      2 #./nginx: error while loading shared libraries: libfastcommon.so: cannot open shared object file: No such file or directory
      3 #解决办法 ---> 将/usr/local/fastdfs/lib 加入系统文件/etc/ld.so.conf中
      4   vim /etc/ld.so.conf
      5   /usr/local/fastdfs/lib
      6 #更新库文件缓存ld.so.cache
      7   /sbin/ldconfig -v
      编译fastdfs-nginx-module模块

      1 # 重新编译nginx 
      2   cd /usr/local/src/nginx-1.5.4
      3   ./configure --add-module=/usr/local/src/fastdfs-nginx-module/src
      4   makemake install
      修改mod_fastdfs.conf配置

      01   vim /usr/local/fastdfs/conf/mod_fastdfs.conf
      02 # the base path to store log files
      03   base_path=/tmp
      04 # if load FastDFS parameters from tracker server
      05 # since V1.12
      06 # default value is false
      07   load_fdfs_parameters_from_tracker=true
      08 # FastDFS tracker_server can ocur more than once, and tracker_server format is
      09 #  "host:port", host can be hostname or ip address
      10 # valid only when load_fdfs_parameters_from_tracker is true
      11   tracker_server=192.168.55.222:22122
      12 # the port of the local storage server
      13 # the default value is 23000
      14   storage_server_port=23000
      15 # the group name of the local storage server
      16   group_name=group1
      17 # if the url / uri including the group name
      18 # set to false when uri like /M00/00/00/xxx
      19 # set to true when uri like ${group_name}/M00/00/00/xxx, such as group1/M00/xxx
      20 # default value is false
      21   url_have_group_name = true
      22 # path(disk or mount point) count, default value is 1
      23 # must same as storage.conf
      24   store_path_count=1
      25 # store_path#, based 0, if store_path0 not exists, it's value is base_path
      26 # the paths must be exist
      27 # must same as storage.conf
      28   store_path0=/home/fastdfs/storage
      29 # set the log filename, such as /usr/local/apache2/logs/mod_fastdfs.log
      30 # empty for output to stderr (apache and nginx error_log file)
      31   log_filename=/home/www/logs/mod_fastdfs.log
      nginx配置简洁版本

      01 #vim /usr/local/nginx/conf/nginx.conf
      02 user  www www;
      03 worker_processes  2;
      04 error_log  /home/www/logs/error.log  notice;
      05 pid        /home/www/logs/nginx.pid;
      06  
      07 worker_rlimit_nofile 5120;
      08 events {
      09     use epoll;
      10     worker_connections  5120;
      11 }
      12  
      13 http {
      14     include       mime.types;
      15     default_type  application/octet-stream;
      16  
      17     sendfile        on;
      18     tcp_nopush     on;
      19     keepalive_timeout  60;
      20     tcp_nodelay on;
      21  
      22     server {
      23         listen       80;
      24         server_name  localhost;
      25