1.2 fastDFS安装和使用

1.2.1 libevent

老版本的fastDFS是基于libevent写的,但是最新版的fastDFS最终网络IO这部分重新用epoll实现了。

所以如果是fastDFS是2.0之前,请先安装好libevent环境。 之后就不用了。

1.2.2 libfastcommon

git下载地址:

https://github.com/happyfish100/libfastcommon.git

./make.sh
sudo ./make.sh install

确认make没有错误后,执行安装,64位系统默认会复制到/usr/lib64下。

这时候需要设置环境变量或者创建软链接

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/


ln -s /usr/lib64/libfastcommon.so /usr/lib/libfastcommon.so

1.2.3 安装fastDFS

下载 FastDFS 源程序,下载地址 http://code.google.com/p/fastdfs/downloads/list

也可以用github下载。

https://github.com/happyfish100/fastdfs.git

这里我们下的是V5.05版本。

tar -zxvf fastdfs-5.05.tar.gz
./make.sh

sudo ./make.sh install

确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。

1.2.4 修改配置文件

首先将三个文件的名字去掉sample,暂时只修改以下几点,先让fastdfs跑起来,其余参数调优的时候再考虑。

也可以考虑将三个文件备份一下。

tracker.conf 中修改

base_path=/usr/fastdfs/tracker #用于存放日志。

注意 确保/usr/fastdfs/tracker 目录存在

storage.conf 中修改

base_path=/usr/fastdfs/storage #用于存放日志。
store_path0=/usr/fastdfs/fastdfs0 #存放数据,若不设置默认为前面那个。
tracker_server=192.168.2.105:22122 #指定tracker服务器地址。不能是127.0.0.1

注意 确保/usr/fastdfs/storage、 /usr/fastdfs/fastdfs0目录存在

client.conf 中同样要修改

base_path=/usr/fastdfs/client #用于存放日志。
tracker_server=192.168.2.105:22122 #指定tracker服务器地址。

注意 确保/usr/fastdfs/client 目录存在

1.2.5 启动tracker和storage

/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf

检查进程

root@ubuntu:~# ps -ef |grep fdfs
root       7819      1  0 15:24 ?        00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root       8046      1  0 15:36 ?        00:00:01 fdfs_storaged /etc/fdfs/storage.conf start

表示启动ok了,若有错误,可以在/usr/fastdfs/tracker/logs 目录下检查日志。

1.2.6 上传、删除测试

上传文件:

使用自带的fdfs_test来测试,使用格式如下:

fdfs_test /etc/fdfs/client.conf upload abcd.txt
his is FastDFS client test program v5.05

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.

[2016-07-25 13:03:09] DEBUG - base_path=/usr/fastdfs, connect_timeout=30, network_timeout=60, tracker_server_count=1, anti_steal_token=0, anti_steal_secret_key length=0, use_connection_pool=0, g_connection_pool_max_idle_time=3600s, use_storage_id=0, storage server id count: 0

tracker_query_storage_store_list_without_group: 
        server 1. group_name=, ip_addr=192.168.2.105, port=23000

group_name=group1, ip_addr=192.168.2.105, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgCaVeVnY2AcveAAAAAFDGtH6s805.txt
source ip address: 192.168.2.105
file timestamp=2016-07-25 13:03:09
file size=20
file crc32=833429419
example file url: http://192.168.2.105/group1/M00/00/00/wKgCaVeVnY2AcveAAAAAFDGtH6s805.txt
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgCaVeVnY2AcveAAAAAFDGtH6s805_big.txt
source ip address: 192.168.2.105
file timestamp=2016-07-25 13:03:09
file size=20
file crc32=833429419
example file url: http://192.168.2.105/group1/M00/00/00/wKgCaVeVnY2AcveAAAAAFDGtH6s805_big.txt

删除文件

fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgCaVeVnY2AcveAAAAAFDGtH6s805_big.txt

可以看到,上传ok了,这里会生成两个文件,这是fastdfs的主/从文件特性,以后再介绍。example file url是不能在浏览器中直接打开的,除非配合nginx使用,这里我不需要了。删除文件需要完整的group_name和remote_filename。

一些其他的指令均在fastdfs/client目录中。

包括指令:

fdfs_appender_test
fdfs_append_file
fdfs_delete_file
fdfs_file_info        
fdfs_storaged         
fdfs_test1            
fdfs_upload_appender  
fdfs_appender_test1   
fdfs_crc32            
fdfs_download_file    
fdfs_monitor          
fdfs_test             
fdfs_trackerd         
fdfs_upload_file

results matching ""

    No results matching ""