FastDFS分布式文件系统集群

Posted knmax

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了FastDFS分布式文件系统集群相关的知识,希望对你有一定的参考价值。

环境

ip fastdfs-role
192.168.1.115 Tracker +Storage
192.168.1.104 Tracker +Storage
192.168.1.106 Tracker +Storage

FastDFS安装配置

安装开发环境

# yum groupinstall "Development Tools" "Server platform Development" -y

安装libfastcommon

# git clone https://github.com/happyfish100/libfastcommon.git
# cd libfastcommon/
# ./make.sh
# ./make.sh install

安装Fastdfs

# git clone https://github.com/happyfish100/fastdfs.git
# cd fastdfs/
# ./make.sh
# ./make.sh install

3台机器都按这种方式安装好

配置Tracker

# cd /etc/fdfs/
# cp tracker.conf.sample tracker.conf
# vim tracker.conf
base_path=/data/fdfs/tracker
# mkdir -pv /data/fdfs/tracker
# /etc/init.d/fdfs_trackerd start  启动服务

配置Storage

# cd /etc/fdfs/
# cp storage.conf.sample storage.conf
# vim storage.conf
group_name=G1  #指定组名
base_path=/data/fdfs/storage # 用于存储数据
store_path_count=1 # 设置设备数量
store_path0=/data/fdfs/storage/m0 #指定存储路径0
  # 注意:同一组内存储路径不能冲突,例如:下一个节点的存储路径就是m2,m3....等
tracker_server=192.168.1.115:22122 #指定tracker
tracker_server=192.168.1.104:22122
tracker_server=192.168.1.106:22122

# mkdir -pv /data/fdfs/storage/m0
# /etc/init.d/fdfs_storaged start

配置client

# cp client.conf.sample client.conf
# vim client.conf
base_path=/data/fdfs/client
tracker_server=192.168.1.115:22122
tracker_server=192.168.1.104:22122
tracker_server=192.168.1.106:22122

# mkdir /data/fdfs/client

将3个配置文件分别拷贝到另外两台机器

# scp client.conf storage.conf tracker.conf 192.168.1.106:/etc/fdfs/
# scp client.conf storage.conf tracker.conf 192.168.1.115:/etc/fdfs/
# /etc/init.d/fdfs_trackerd restart
# /etc/init.d/fdfs_storaged restart

测试FastDFS

上传文件

  • fdfs_upload_file [storage_ip:port] [store_path_index]

    # fdfs_upload_file /etc/fdfs/client.conf /etc/issue
    G1/M00/00/00/wKgBaFe0S2eAZx-wAAAAF30Ccq87825622
    报错:
    [2016-08-17 18:06:28] ERROR - file: connection_pool.c, line: 130, connect to 192.168.1.115:22122 fail, errno: 113, error info: No route to host
    防火墙的原因 iptables -F

    查看文件

  • fdfs_file_info

    # fdfs_file_info /etc/fdfs/client.conf G1/M00/00/00/wKgBaFe0S2eAZx-wAAAAF30Ccq87825622
    source storage id: 0
    source ip address: 192.168.1.104
    file create timestamp: 2016-08-17 19:32:55
    file size: 23
    file crc32: 2097312431 (0x7D0272AF)

    下载文件

  • fdfs_download_file [local_filename] [ ]

    # fdfs_download_file /etc/fdfs/client.conf G1/M00/00/00/wKgBaFe0S2eAZx-wAAAAF30Ccq87825622

    查看存储节点状态

    # fdfs_monitor /etc/fdfs/client.conf

    配置nginx为storage server提供http访问接口

    下载fastdfs-nginx-module

    # git clone https://github.com/happyfish100/fastdfs-nginx-module.git

    下载nginx源码,并编译支持fastdfs

    # yum install openssl-devel pcre-devel -y &>/dev/null
    # wget http://nginx.org/download/nginx-1.10.1.tar.gz &>/dev/null
    # tar -xf nginx-1.10.1.tar.gz
    # useradd -s /sbin/nologin -M nginx
    # cd nginx-1.10.1
    ./configure --prefix=/usr/local/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/run/nginx.pid --lock-path=/var/lock/nginx.lock --user=nginx --group=nginx --with-http_ssl_module --with-http_stub_status_module --with-pcre --add-module=../fastdfs-nginx-module/src
    # make -j 8
    # make install

    复制配置文件

    #  cp /root/fastdfs-nginx-module/src/mod_fastdfs.conf  /etc/fdfs/
    #  cp /root/fastdfs/conf/{http.conf,mime.types}  /etc/fdfs/

    配置fastdfs-nginx-module配置文件

base_path=/data/fdfs/storage #存储节点的目录位置
tracker_server=192.168.1.115:22122
tracker_server=192.168.1.104:22122
tracker_server=192.168.1.106:22122   #指定定tracker-server
storage_server_port=23000
group_name=G1  #指定组名
url_have_group_name = true  #访问路径中是否包括组名
store_path_count=1 #配置路径个数
store_path0=/data/fdfs/storage/m0  #指定要查看的路径
[group1]
group_name=G1
storage_server_port=23000
store_path_count=1
store_path0=/data/fdfs/storage/m0
# scp /etc/fdfs/mod_fastdfs.conf 192.168.1.106:/etc/fdfs
# scp /etc/fdfs/mod_fastdfs.conf 192.168.1.115:/etc/fdfs

配置nginx

# vim /etc/nginx/nginx.conf
 location ~ /G[0-9]+/M00/ {
        root /data/fdfs/storage/m0/data/;
        ngx_fastdfs_module;
        }
# /usr/local/nginx/sbin/nginx

为存储文件路径穿件链接至M00

# ln -sv /data/fdfs/storage/m0/data  /data/fdfs/storage/m0/data/M00

启动nginx和重启storage并上传文件测试

# /usr/local/nginx/sbin/nginx
# fdfs_upload_file /etc/fdfs/client.conf /usr/share/wallpapers/CentOS7/contents/images/2560x1600.jpg
G1/M00/00/00/wKgBc1e0UamAEKGjAA6q2wjnW8s725.jpg

访问查看

http://192.168.1.106/G1/M00/00/00/wKgBaFe0UhKAbRbCAA6q2wjnW8s458.jpg
http://192.168.1.104/G1/M00/00/00/wKgBaFe0UhKAbRbCAA6q2wjnW8s458.jpg
http://192.168.1.115/G1/M00/00/00/wKgBaFe0UhKAbRbCAA6q2wjnW8s458.jpg

错误排查

返回28错误码

考虑是磁盘空间不足,无法上传新文件

[[email protected] ~]# fdfs_upload_file /etc/fdfs/client.conf 1.txt
[2017-05-01 15:10:33] ERROR - file: tracker_proto.c, line: 48, server: 192.168.1.106:22122, response status 28 != 0
tracker_query_storage fail, error no: 28, error info: No space left on device
[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/xvda1             40G  3.8G   34G  11% /
tmpfs                 3.9G     0  3.9G   0% /dev/shm
/dev/mapper/vgs_data-lvol0
                      983G  835G   99G  90% /opt

发现空间还是够的,查看预留空间值

# vim /etc/fdfs/tracker.conf
reserved_storage_space = 10%  # 预留了10%的空间,很显然现在空间只剩10%的样子

临时解决方案:
图片服务器会保留很多已经失效的图片,如果不做好图片清理回收机制,在这方面投入将是无底洞,还是得根据业务来。
如果图片必须保存后面需要磁盘扩容前期就得做好规划,比如使用lvm逻辑卷等

# vim /etc/fdfs/tracker.conf
reserved_storage_space = 5%   # 所有tracker节点都修改下,然后重启服务
# /etc/init.d/fdfs_trackerd restart
# /etc/init.d/fdfs_storaged restart
# fdfs_upload_file /etc/fdfs/client.conf 1.txt   上传测试
G1/M00/83/8D/CixLa1kG4U-ARX-uAAAAAAAAAAA379.txt

以上是关于FastDFS分布式文件系统集群的主要内容,如果未能解决你的问题,请参考以下文章

FastDfs分布式文件系统集群搭建(直接安装方式)

FastDFS分布式文件系统集群

分布式文件系统FastDFS集群部署

FastDFS分布式文件系统集群

FastDFS分布式文件系统集群安装与配置

FastDFS分布式文件系统集群安装与配置