server端分为两个部分,一个是tracker,一个是storage。前者调度管理,负载均衡,后者则是实际的存储节点。两个都能做成集群,以防止单点故障。以前的4.x版本依赖libevent, FastDFS_v5.05依赖libfastcommon,只需安装libfastcommon即可。
以下安装最新版本,下载地址:http://sourceforge.net/projects/fastdfs/files
一、安装
mv libfastcommon-master libfastcommon
cd libfastcommon/
./make.sh
./make.sh install
确认make没有错误后,执行安装,64位系统默认会复制到/usr/lib64下。
这时候需要设置环境变量或者创建软链接
export LD_LIBRARY_PATH=/usr/lib64/
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
2.安装FastDFS
wget https://github.com/happyfish100/fastdfs/archive/master.zip
unzip master.zip
mv fastdfs-master fastdfs
./make.sh
./make.sh install
确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。
二、配置
简单配置,测试使用,关于集群等后续再讲解。
1.tracker
cp tracker.conf.sample tracker.conf
修改:
base_path=/home/fastdfs/tracker #用于存放日志
2.storage
cp storage.conf.sample storage.conf
修改:
base_path=/home/fastdfs/storage #用于存放日志
store_path0=/home/fastdfs/storage0 #存放数据,若不设置默认为前面那个。
tracker_server=192.168.18.178:22122 #指定tracker服务器地址。
三、启动服务
1.启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
2.启动storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
检查启动进程:
修改/etc/fdfs/client.conf
base_path=/home/fastdfs/client
tracker_server=192.168.18.178:22122
使用自带的fdfs_test来测试,使用格式如下:
使用fdfs_delete_file来删除文件,使用格式如下:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687_big.jpg
以下安装最新版本,下载地址:http://sourceforge.net/projects/fastdfs/files
一、安装
1.安装libfastcomm
wget https://github.com/happyfish100/libfastcommon/archive/master.zip
mv libfastcommon-master libfastcommon
cd libfastcommon/
./make.sh
./make.sh install
确认make没有错误后,执行安装,64位系统默认会复制到/usr/lib64下。
这时候需要设置环境变量或者创建软链接
export LD_LIBRARY_PATH=/usr/lib64/
ln -s /usr/lib64/libfastcommon.so /usr/local/lib/libfastcommon.so
2.安装FastDFS
wget https://github.com/happyfish100/fastdfs/archive/master.zip
unzip master.zip
mv fastdfs-master fastdfs
./make.sh
./make.sh install
确认make没有错误后,执行安装,默认会安装到/usr/bin中,并在/etc/fdfs中添加三个配置文件。
二、配置
简单配置,测试使用,关于集群等后续再讲解。
1.tracker
cp tracker.conf.sample tracker.conf
修改:
base_path=/home/fastdfs/tracker #用于存放日志
2.storage
cp storage.conf.sample storage.conf
修改:
base_path=/home/fastdfs/storage #用于存放日志
store_path0=/home/fastdfs/storage0 #存放数据,若不设置默认为前面那个。
tracker_server=192.168.18.178:22122 #指定tracker服务器地址。
三、启动服务
1.启动tracker
/usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
2.启动storage
/usr/bin/fdfs_storaged /etc/fdfs/storage.conf
检查启动进程:
ps -ef | grep fdfs
root 60894 1 0 01:04 ? 00:00:00 /usr/bin/fdfs_trackerd /etc/fdfs/tracker.conf
root 60971 1 0 01:07 ? 00:00:00 /usr/bin/fdfs_storaged /etc/fdfs/storage.conf
root 60985 43839 0 01:08 pts/0 00:00:00 grep fdfs
检查启动端口:
netstat -aopn | grep fdfs
tcp 0 0 0.0.0.0:23000 0.0.0.0:* LISTEN 60971/fdfs_storaged off (0.00/0/0)
tcp 0 0 0.0.0.0:22122 0.0.0.0:* LISTEN 60894/fdfs_trackerd off (0.00/0/0)
tcp 0 0 192.168.18.178:22122 192.168.18.178:42090 ESTABLISHED 60894/fdfs_trackerd keepalive (61.00/0/0)
tcp 0 0 192.168.18.178:42090 192.168.18.178:22122 ESTABLISHED 60971/fdfs_storaged keepalive (61.00/0/0)
四、上传/删除测试
修改/etc/fdfs/client.conf
base_path=/home/fastdfs/client
tracker_server=192.168.18.178:22122
使用自带的fdfs_test来测试,使用格式如下:
fdfs_test /etc/fdfs/client.conf upload /home/fastdfs/7.jpg
This is FastDFS client test program v5.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.
[2015-05-26 01:18:27] DEBUG - base_path=/home/fastdfs/client, 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.18.178, port=23000
group_name=group1, ip_addr=192.168.18.178, port=23000
storage_upload_by_filename
group_name=group1, remote_filename=M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687.jpg
source ip address: 192.168.18.178
file timestamp=2015-05-26 01:18:27
file size=57151
file crc32=1950923670
example file url: http://192.168.18.178/group1/M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687.jpg
storage_upload_slave_by_filename
group_name=group1, remote_filename=M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687_big.jpg
source ip address: 192.168.18.178
file timestamp=2015-05-26 01:18:27
file size=57151
file crc32=1950923670
example file url: http://192.168.18.178/group1/M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687_big.jpg
example file url是不能在浏览器中直接打开的,除非配合nginx使用。
使用fdfs_delete_file来删除文件,使用格式如下:
fdfs_delete_file /etc/fdfs/client.conf group1/M00/00/00/wKgSslVkLFOAWOw_AADfP3RIu5Y687_big.jpg
删除文件需要完整的group_name和remote_filename。
配置参考文章:
1.FastDFS配置详解之Tracker配置
2.FastDFS配置详解之Storage配置
3.FastDFS 使用经验分享