FastDFS是一个开源的轻量级分布式文件系统,它对文件进行管理,功能包括:文件存储、文件同步、文件访问(文件上传、文件下载)等,解决了大容量存储和负载均衡的问题。特别适合以文件为载体的在线服务,如相册网站、视频网站等等。FastDFS本身具备web服务器功能,但是在5.0版本以上的HTTP模式已被取消。nginx模块也很久未有更新。现在很多人都采用主流的七牛或者又拍云服务,个人觉得无论在速度还是时间上,又拍云完胜七牛。
接下来主要介绍一下FastDFS自带的http服务,在小型服务器上,这个还是简单好用的。注意下版本选择,需要在5.0一下版本才有此功能。
FastDFS 安装配置
[root@vanedev2 ~] wget –no-check-certificate https://github.com/downloads/libevent/libevent/libevent-2.0.20-stable.tar.gz
[root@vanedev2 ~] tar zxvf libevent-2.0.20-stable.tar.gz
[root@vanedev2 ~] cd libevent-2.0.20-stable/
[root@vanedev2 ~] ./configure –prefix=/usr/local/libevent
[root@vanedev2 ~] make -j8 && make install
[root@vanedev2 ~] echo “/usr/local/libevent/lib” >> /etc/ld.so.conf
[root@vanedev2 ~] ldconfig
[root@vanedev2 ~] wget https://fastdfs.googlecode.com/files/FastDFS_v3.11.tar.gz
[root@vanedev2 ~] cd FastDFS_v3.11.tar.gz
[root@vanedev2 ~] vi make.sh
开启http及linux服务支持(修改make.sh文件)
去掉注释# WITH_HTTPD=1
去掉注释# WITH_LINUX_SERVICE=1
修改安装目录:TARGET_PREFIX=/usr/local/fastdfs
[root@vanedev2 ~] ./make.sh C_INCLUDE_PATH=/usr/local/libevent/include LIBRARY_PATH=/usr/local/libevent/lib
[root@vanedev2 ~] ./make.sh install
修改tracker.conf文件,修改如下
|
|
修改storage.conf文件,修改如下:
|
|
启动服务:
[root@vanedev2 ~] /usr/local/fastdfs/bin/fdfs_trackerd /etc/fdfs/tracker.conf
[root@vanedev2 ~] /usr/local/fastdfs/bin/fdfs_storaged /etc/fdfs/storage.conf
上传文件测试:
[root@vanedev2 bin]# /usr/local/fastdfs/bin/fdfs_test /etc/fdfs/client.conf upload 1.txt
This is FastDFS client test program v3.11
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.[2015-01-21 14:15:05] INFO – base_path=/data/fastdfs, 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.19, port=23000group_name=group1, ip_addr=192.168.1.19, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBE1S_Q-ngef-pAAAAB9kK7Ok111.txt
source ip address: 192.168.1.19
file timestamp=2015-01-21 14:15:05
file size=7
file crc32=3641371881
file url: http://192.168.1.19:8080/group1/M00/00/00/wKgBE1S_Q-ngef-pAAAAB9kK7Ok111.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgBE1S_Q-ngef-pAAAAB9kK7Ok111_big.txt
source ip address: 192.168.1.19
file timestamp=2015-01-21 14:15:05
file size=7
file crc32=3641371881
file url: http://192.168.1.19:8080/group1/M00/00/00/wKgBE1S_Q-ngef-pAAAAB9kK7Ok111_big.txt
访问方式
通过访问链接http://192.168.1.19:8080/group1/M00/00/00/wKgBE1S_Q-ngef-pAAAAB9kK7Ok111_big.txt就可以查看文件内容。