博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
FastDFS 安装及使用详解
阅读量:4220 次
发布时间:2019-05-26

本文共 5296 字,大约阅读时间需要 17 分钟。

 

Google了一下,流行的开源分布式文件系统有很多,介绍如下:
 
mogileFS:Key-Value型元文件系统,不支持FUSE,应用程序访问它时需要API,主要用在web领域处理海量小图片,效率相比mooseFS高很多。
fastDFS:国人在mogileFS的基础上进行改进的key-value型文件系统,同样不支持FUSE,提供比mogileFS更好的性能。
mooseFS:支持FUSE,相对比较轻量级,对master服务器有单点依赖,用perl编写,性能相对较差,国内用的人比较多
glusterFS:支持FUSE,比mooseFS庞大
ceph:支持FUSE,客户端已经进入了linux-2.6.34内核,也就是说可以像ext3/rasierFS一样,选择ceph为文件系统。彻底的分布式,没有单点依赖,用C编写,性能较好。基于不成熟的btrfs,其本身也非常不成熟。
lustre:Oracle公司的企业级产品,非常庞大,对内核和ext3深度依赖
NFS:老牌网络文件系统,具体不了解,反正NFS最近几年没发展,肯定不能用。
鉴于fastDFS是国人开发,也有国内的一些大公司在使用,so…
 
普通的文件架构其实一两年内也是没有问题的,但有句话叫未雨绸缪,于是决定折腾折腾。
源码下载:http://code.google.com/p/fastdfs
寻求帮助:http://www.csource.org
 

一、安装libevent

首先检查依赖环境gcc安装没有,如果没有安装,先安装
yum install gcc* make*
fastDFS需要安装libevent比较新的版本,将本机的比较低的版本卸载了。
 
ls -al /usr/lib | grep libevent
查看是否已安装,如果已安装且版本低于1.3,则先进行卸载。
rpm -qa libeventlibevent-1.4.13-1.el6.x86_64rpm -e --nodeps libevent
安装一个最新稳定版
 
wget https://github.com/downloads/libevent/libevent/libevent-2.0.18-stable.tar.gztar zxvf libevent-2.0.18-stable.tar.gzcd libevent-2.0.18-stable./configuremake && make install
为libevent创建软链接到/lib库下,64位系统对应/lib64
 
ln -s /usr/local/lib/libevent* /lib/ln -s /usr/local/lib/libevent* /lib64/

二、安装FastDFS

 
wget http://fastdfs.googlecode.com/files/FastDFS_v3.06.tar.gztar zxvf FastDFS_v3.06.tar.gzcd FastDFS./make.sh./make.sh install

三、配置FastDFS

环境:
tracker server
192.168.1.5
storage server
192.168.1.51
192.168.1.52
 
1、配置并启动 tracker server
配置 tracker.conf
 
mkdir /home/yuqing/fastdfsvim /etc/fdfs/tracker.confbase_path=/home/yuqing/fastdfs
启动 tracker
/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
设置开机启动
 
vim /etc/rc.local/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf
2、配置并启动 storage server
配置
storage.conf
 
vim /etc/fdfs/storage.confbase_path=/home/yuqing/fastdfsstore_path0=/home/yuqing/fastdfstracker_server=192.168.1.5:22122
启动
storage 
 
/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
设置开机启动
 
vim /etc/rc.local/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
3、为storage节点安装fastdfs-nginx-module模块
①安装模块
安装Nginx详见:
需重新编译Nginx
wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gzwget http://nginx.org/download/nginx-1.2.0.tar.gztar zxvf fastdfs-nginx-module_v1.15.tar.gztar zxvf pcre-8.38.tar.gztar zxvf nginx-1.2.0.tar.gz./configure --prefix=/usr/local/nginx --with-pcre=/temp/pcre-8.38 --add-module=/temp/fastdfs-nginx-module/srcmake && make install
 
②配置
编辑nginx.conf
 
vim /usr/local/nginx/conf/nginx.confserver {    listen       80;    server_name  localhost;     location /M00 {        alias /data/images/data;        ngx_fastdfs_module;    }    ......}
 
拷贝mod_fastdfs.conf 到 /etc/fdfs/并编辑
 
cp fastdfs-nginx-module/src/mod_fastdfs.conf /etc/fdfs/vim /etc/fdfs/mod_fastdfs.confbase_path=/home/yuqing/fastdfstracker_server=192.168.1.5:22122store_path0=/home/yuqing/fastdfs
如果需要上传之后访问路径包含group1,则需要配置mod_fastdfs.conf配置文件如下:
url_have_group_name = true
启动nginx:
/usr/local/nginx/sbin/nginx
 
如果需要重启nginx,命令如下:
/usr/local/nginx/sbin/nginx -s reload

四、使用FastDFS

1、上传文件
FastDFS安装包中,自带了客户端程序,通过程序可以进行文件上传。在使用这个客户端程序之前,首先需要配置client.conf,然后再进行文件上传及下载。
在tracker上修改客户端配置文件client.conf
 
vim /etc/fdfs/client.confbase_path=/home/yuqing/fastdfstracker_server=192.168.1.5:22122
如果需要支持外网访问需要用真实的IP
vim a.html
This Is FastDFS Test.
上传文件
 
/usr/local/bin/fdfs_test /etc/fdfs/client.conf upload a.html
This is FastDFS client test program v3.06
 
Copyright (C) 2008, Happy Fish / YuQing
 
FastDFS may be copied only under the terms of the GNU General
Public License V3, which may be found in the FastDFS source kit.
Please visit the FastDFS Home Page http://www.csource.org/ 
for more detail.
 
[2012-04-29 12:42:53] INFO - base_path=/data/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=group1, ip_addr=192.168.1.51, port=23000
server 2. group_name=group1, ip_addr=192.168.1.52, port=23000
 
group_name=group1, ip_addr=192.168.1.51, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBM0-cxs32qFyYAAAADigvbpc90.html
source ip address: 192.168.1.51
file timestamp=2012-04-29 12:42:53
file size=14
file crc32=674197143
file url: http://192.168.1.5/group1/M00/00/00/wKgBM0-cxs32qFyYAAAADigvbpc90.html
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBM0-cxs32qFyYAAAADigvbpc90_big.html
source ip address: 192.168.1.51
file timestamp=2012-04-29 12:42:53
file size=14
file crc32=674197143
file url: http://192.168.1.5/group1/M00/00/00/wKgBM0-cxs32qFyYAAAADigvbpc90_big.html
上传成功
试试用
 
http://192.168.1.51/M00/00/00/wKgBM0-cxs32qFyYAAAADigvbpc90_big.html
 
访问看看吧。
 

五、FastDFS常见命令

 
1: 启动FastDFS
          tracker: /usr/local/bin/fdfs_trackered /etc/fdfs/tracker.conf
          storage: /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf
2:关闭FastDFS
          tracker:/usr/local/bin/stop.sh /usr/local/bin/fdfs_tracker
          storage:/usr/local/bin/stop.sh /usr/local/bin/fdfs_storage
        或者 killall fdfs_trackered(storaged)  -------注意,千万不要使用-9强行杀死进程。
3:重启FastDFS
         
tracker:/usr/local/bin/restart.sh /usr/local/bin/fdfs_trackered storage:/usr/local/bin/restart.sh /usr/local/bin/fdfs_storaged
4:查看集群情况
          在任意一台storage(tracker也可以) /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf
5:删除一个storage:
           在任意一台storage(tracker也可以) /usr/local/bin/fdfs_monitor /etc/fdfs/storage.conf delete group2 20.12.1.73

转载地址:http://lmemi.baihongyu.com/

你可能感兴趣的文章
牛客网错题总结
查看>>
编译过程的五个阶段
查看>>
Linux系统中的fork()函数详解
查看>>
TCP/IP总结
查看>>
WireShark使用教程
查看>>
UDP总结
查看>>
在C++中,为了让某个类只能通过new来创建实例(即如果直接创建对象,编译器将报错),怎样做?
查看>>
C++常见面试题30道
查看>>
为什么不能建立引用数组?
查看>>
Union的一个知识点
查看>>
基类析构函数为虚函数的研究
查看>>
函数入栈出栈以及栈帧
查看>>
从RTTI谈C++的向下转型
查看>>
面试心得(BAT)
查看>>
变量初始化规则以及声明和定义
查看>>
深入C++中构造函数、拷贝构造函数、赋值操作符、析构函数的调用过程总结
查看>>
C++中复制构造函数和重载赋值操作符总结
查看>>
C++中对象的赋值与复制操作详细解析
查看>>
C++中赋值运算符与逗号运算符的用法详解
查看>>
解析C++编程中的继承方面的运用
查看>>