标签:fastdfs
由于网站使用nfs共享方式保存用户上传的图片,附件等资料,然后通过apache下载的方式供用户访问,在网站架构初期,使用这种简单的方式实现了静态 资源的读写分离,但随着网站数据量的增加,图片服务器渐渐成为整个网站的短板,缘次催生了使用fastfds的想法,故而先进行一番简单的测试!在开始之 前还是先来看看fastfds的介绍信息:
FastDFS is an open source high performance distributed file system (DFS). It‘s major functions include: file storing, file syncing and file accessing, and design for high capacity and load balancing.
FastDFS is an open source high performance distributed file system. It‘s major functions include: file storing, file syncing and file accessing (file uploading and file downloading), and it can resolve the high capacity and load balancing problem. FastDFS should meet the requirement of the website whose service based on files such as photo sharing site and vidio sharing site.
FastDFS has two roles: tracker and storage. The tracker takes charge of scheduling and load balancing for file access. The storage store files and it‘s function is file management including: file storing, file syncing, providing file access interface. It also manage the meta data which are attributes representing as key value pair of the file. For example: width=1024, the key is "width" and the value is "1024".
The tracker and storage contain one or more servers. The servers in the tracker or storage cluster can be added to or removed from the cluster by any time without affecting the online services. The servers in the tracker cluster are peer to peer.
The storarge servers organizing by the file volume/group to obtain high capacity. The storage system contains one or more volumes whose files are independent among these volumes. The capacity of the whole storage system equals to the sum of all volumes‘ capacity. A file volume contains one or more storage servers whose files are same among these servers. The servers in a file volume backup each other, and all these servers are load balancing. When adding a storage server to a volume, files already existing in this volume are replicated to this new server automatically, and when this replication done, system will switch this server online to providing storage services. When the whole storage capacity is insufficiency, you can add one or more volumes to expand the storage capacity. To do this, you need to add one or more storage servers.
The identification of a file is composed of two parts: the volume name and the file name.
大意为:
fastdfs是一个开源的,高性能的的分布式文件系统,他主要的功能包括:文件存储,同步和访问,设计基于高可用和负载均衡,fastfd非常适用于基于文件服务的站点,例如图片分享和视频分享网站
fastfds有两个角色:跟踪服务和存储服务,跟踪服务控制,调度文件以负载均衡的方式访问;存储服务包括:文件存储,文件同步,提供文件访问接口,同时以key value的方式管理文件的元数据
跟踪和存储服务可以由1台或者多台服务器组成,同时可以动态的添加,删除跟踪和存储服务而不会对在线的服务产生影响,在集群中,tracker服务是对等的
存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务 器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储服务器起到了冗余备份和负载均衡的作用。在卷中增加服务器时,同步已有的文件由系统自动 完成,同步完成后,系统自动将新增服务器切换到线上提供服务。当存储空间不足或即将耗尽时,可以动态添加卷。只需要增加一台或多台服务器,并将它们配置为 一个新的卷,这样就扩大了存储系统的容量。
下面几张图可以清楚的说明fastfds的架构和文件上传和下载流程等:
安装过程:
由于FastDFS内部绑定了libevent作为http服务器,所以必须先安装libevent。如果已经安装了libevent,请确认安装路径是 /usr,因为FastDFS在编译源程序时,需要到此目录下查找一些依赖文件,否则编译会出错。如果不是,建议首先卸载libevent,然后安装到 /usr下。
下载最新的libevent包并安装
wget https://sourceforge.net/projects/levent/files/libevent/libevent-2.0/libevent-2.0.22-stable.tar.gz
1、解压
tar -zxvf libevent-2.0.22-stable.tar.gz
2、进入解压目录编译和安装
cd cd libevent-2.0.22-stable
./configure --prefix=/usr/local/libevent/
make && make install
安装FastDFS:5.5版本编译出现错误,建议使用5.2or5.3版本。。。
wget http://sourceforge.net/projects/fastdfs/files/FastDFS%20Server%20Source%20Code/FastDFS%20Server%20with%20PHP%20Extension%20Source%20Code%20V5.03/FastDFS_v5.03.tar.gz
1、解压
tar -zxvf tar zxvf FastDFS_v5.05.tar.gz
2、进入解压目录修改make.sh中TARGET_PREFIX=你要安装的目录
cd FastDFS
vim make.sh
3、编译和安装
./make.sh
./make.sh install
安装完成后如果出现ln -fs ....即表示安装成功,安装成功后的配置文件在/etc/fdfs
安装FastDHT:
wget http://sourceforge.net/projects/fastdht/files/FastDHT%20server%20and%20php%20ext/FastDHT%20Server%20Source%20Code%20V1.23/FastDHT_v1.23.tar.gz
1、解压
tar -zxvf FastDHT_v1.23.tar.gz
2、进入解压目录修改mak.sh中的TARGET_PREFIX=你的安装目录
3、编译和安装
./make.sh
./make.sh install
安装完成后如果出现ln -fs ....即表示安装成功,安装成功后的配置文件在/etc/fdht
安装至此结束。。。
修改配置文件
vim /etc/fdfs/tracker.conf
1.base_path=/home/yuqing/fastdfs
2.#改成你想要的http端口,将来http下载文件的端口就是他了
3.http.server_port=8080 -> http.server_port=8090
#http支持
4.##include http.conf -> #include http.conf
#默认4GB,如果空间不足会报no free space的异常,无法正常启动,建议暂时调小
5.reserved_storage_space = 4GB -> reserved_storage_space = 1GB
#tracker server对storage server供服务的端口,使用默认的即可,也可以自定义
6.port=22122
B、将http.conf文件拷贝到/etc/fdfs目录下,执行
7. cp %FastDFS%/conf/http.conf /etc/fdfs/
注:为了支持http,必须将这个文件拷贝到此目录,否则无法启动,报param http.XXX not exist or is empty类似的错误
启动:
/usr/local/fdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf
报错:
ERROR - file: ../common/process_ctrl.c, line: 189, "/home/yuqing/fastdfs" can‘t be accessed, error info: No such file or directory
解决:
[root@localhost FastDHT]# echo ‘/usr/local/libevent/include/‘ >> /etc/ld.so.conf[root@localhost FastDHT]# echo ‘/usr/local/libevent/lib/‘ >> /etc/ld.so.conf
[root@localhost FastDHT]# ldconfig
依然报错:
[2015-05-29 07:36:03] ERROR - file: ../common/process_ctrl.c, line: 189, "/home/yuqing/fastdfs" can‘t be accessed, error info: No such file or directory
解决:
mkdir -p /home/yuqing/fastdfs
这回正常了,查看启动成功与否
[root@localhost FastDHT]# ps -ef |grep track |grep -v ‘grep‘
root 37018 1 0 07:38 ? 00:00:00 /usr/local/fdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf
本文出自 “初心、始终” 博客,谢绝转载!
标签:fastdfs
原文地址:http://gouyc.blog.51cto.com/1594451/1656454