FastDFS

  1. 安装准备

     yum install \
     vim \
     git \
     gcc \
     gcc-c++ \
     wget \
     make \
     libtool \
     automake \
     autoconf \
     -y \
    
  2. 安装libfastcommon

     cd /root
     git clone https://github.com/happyfish100/libfastcommon.git
     cd libfastcommon/
     ./make.sh
     ./make.sh install
    
  3. 安装fastdfs

     cd /root
     wget https://github.com/happyfish100/fastdfs/archive/V5.10.tar.gz
     tar -zxvf V5.10.tar.gz
     cd fastdfs-5.10
     ./make.sh  
     ./make.sh install
    
  4. 如果只想安装FastDFS php客户端,请直接向下,找到php安装FastDFS扩展

  5. 创建目录

     mkdir /data/
     mkdir /data/fdfs
     # 代码服务器执行
     mkdir /data/fdfs/client
     # 存储服务器执行
     mkdir /data/fdfs/storage
     # 跟踪服务器执行
     mkdir /data/fdfs/tracker
    
  6. 配置的建议

    1. 每一台client配置上所有tracker服务器地址
    2. 每一台storage配置上所有tracker服务器地址
    3. 每一个group至少有2个storage服务互为备份机
    4. group name建议从group0开始命名(兼容FastDHT)
  7. 配置client(在client服务器[代码服务器])

     cp /etc/fdfs/client.conf.sample /etc/fdfs/client.conf
     vim /etc/fdfs/client.conf
    
     base_path=/data/fdfs/client
     tracker_server=192.168.1.101:22122 #tracker服务器1 ip地址
     tracker_server=192.168.1.102:22122 #tracker服务器2 ip地址
    
     ESC
     :wq
    
  8. 配置storage(在storage服务器)

     cp /etc/fdfs/storage.conf.sample /etc/fdfs/storage.conf
     vim /etc/fdfs/storage.conf
    
     group_name=group0
     base_path=/data/fdfs/storage
     #这样配置只有M00
     store_path0=/data/fdfs/storage
     #这样配置就有M01(一般用于磁盘挂载的情况)
     #store_path1=/mnt/fdfs/storage
     #设置storage最大连接数
     max_connections=1024
     #tracker服务器1 ip地址
     tracker_server=192.168.1.101:22122
     #只有一台tracker不要增加这条↓!!!!!!!!
     #tracker_server=192.168.1.102:22122 #tracker服务器2 ip地址
    
     #以下配置安装FastDHT才配置!!!!!!!!
     #以下配置安装FastDHT才配置!!!!!!!!
     #以下配置安装FastDHT才配置!!!!!!!!
    
     check_file_duplicate=1
     key_namespace=FastDFS
     keep_alive=1
     #include /etc/fdht/fdht_servers.conf
    
     ESC
     :wq
    
  9. 配置tracker(在tracker服务器)

     cp /etc/fdfs/tracker.conf.sample /etc/fdfs/tracker.conf
     vim /etc/fdfs/tracker.conf
    
     bind_addr=192.168.1.101
     base_path=/data/fdfs/tracker
     # 0轮询 1指定组 2最大剩余空间
     store_lookup=2
     max_connections=1024
     # work_threads <= max_connections
     work_threads=16
    
     ESC
     :wq
    
  10. 启动及测试【注意】

     # 如果storage.conf做了FastDHT配置,一定要先安装FastDHT
    
  11. 启动tracker和storage

     # 用来做tracker的服务器执行
     /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
    
     # 用来做storage的服务器执行
     /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
    
  12. 启动与停止

     # 只能在对应服务器上进行对应操作!!!!!!!!
     # 只能在对应服务器上进行对应操作!!!!!!!!
     # 只能在对应服务器上进行对应操作!!!!!!!!
     # 启动
     /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
     /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
    
     # 关闭
     /usr/bin/stop.sh /usr/bin/fdfs_trackerd
     /usr/bin/stop.sh /usr/bin/fdfs_storaged
    
     # 重启
     /usr/bin/restart.sh /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
     /usr/bin/restart.sh /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
    
     # 查看集群storage分布(在storage服务器执行)
     /usr/bin/fdfs_monitor /etc/fdfs/storage.conf
    
     # 删除某个group中的一个storage(在storage服务器执行)
     /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf delete [group name] [ip address]
    
  13. 开机启动

     # 用来做tracker的服务器执行
     vim /etc/rc.local
    
     /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
    
     ESC
     :wq
    
     chmod +x /etc/rc.local
    
     # 用来做storage的服务器执行
     vim /etc/rc.local
    
     /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
    
     ESC
     :wq
    
     chmod +x /etc/rc.local
    
  14. 可通过日志查看是否启动成功

     # 用来做storage的服务器执行
     cat /data/fdfs/storage/logs/storaged.log|grep ERROR
     cat /data/fdfs/storage/logs/storaged.log|grep WARNING
    
     # 用来做tracker的服务器执行
     cat /data/fdfs/tracker/logs/trackerd.log|grep ERROR
     cat /data/fdfs/tracker/logs/trackerd.log|grep WARNING
    
     # 在storage服务器创建软连接
     # 配置Nginx才添加!!!!!!!!
     # 配置Nginx才添加!!!!!!!!
     # 配置Nginx才添加!!!!!!!!
     mkdir /www/fastdfs/group0
     ln -s /data/fdfs/storage/data/ /www/fastdfs/group0/M00
    
  15. 防火墙相关配置

     yum install firewalld
    
     systemctl enable firewalld
     systemctl start firewalld
    
     firewall-cmd --zone=public --add-port=11411/tcp --permanent
     firewall-cmd --zone=public --add-port=22122/tcp --permanent
     firewall-cmd --zone=public --add-port=23000/tcp --permanent
    
     firewall-cmd --reload
    
  16. 测试功能是否正常

     mkdir /test
     cd /test
     vim test.txt
     This is a test file.
     ESC
     :wq
     #上传
     /usr/bin/fdfs_test /etc/fdfs/client.conf upload /test/test.txt
    
     #下载
     /usr/bin/fdfs_download_file /etc/fdfs/client.conf group0/M00/00/00/xxx.txt
     #查看下载文件
     ll /test
     #删除下载文件
     rm /xxx.txt
    
     #删除
     /usr/bin/fdfs_delete_file /etc/fdfs/client.conf group0/M00/00/00/xxx.cfg
    
  17. 为php安装fastdfs_client扩展

     cd /root/fastdfs-5.10/php_client
     phpize
     ./configure
    
     make
     make install
    
     cat /root/fastdfs-5.10/php_client/fastdfs_client.ini >> /usr/local/php/lib/php.ini
     kill -USR2 `cat /usr/local/php/var/run/php-fpm.pid`
    
  18. 为php安装fastcommon扩展

     cd /root/libfastcommon/php-fastcommon
     phpize
     ./configure
    
     make
     make install
    
     vim /usr/local/php/lib/php.ini
    
     extension=fastcommon.so
    
     ESC
     :wq
    
     kill -USR2 `cat /usr/local/php-7.1.4/var/run/php-fpm.pid`
    
  19. FastDFS集群原理图 FastDFS集群原理

@耿志环 2012-∞ 冀ICP备17033181号, powered by Gitbook修订: 2019-01-11 16:52:19

results matching ""

    No results matching ""