安装:
yum install -y libevent-devel pcre-devel zlib-devel
wget http://fastdfs.googlecode.com/files/FastDFS_v4.06.tar.gz
tar zxvf FastDFS_v4.06.tar.gz
cd FastDFS
./make.sh && ./make.sh install
配置tracker:
/etc/fdfs/tracker.conf
base_path=/home/fastdfs #工作目录,记录日志相差信息
bind_addr=0.0.0.0
port=22122
run_by_group=fastdfs
run_by_user=fastdfs
配置storage:
/etc/fdfs/storage.conf
group_name=group1 #服务器所在组,组内服务器数据同步
base_path=/home//fastdfs
store_path0=/home/fastdfs #数据目录
tracker_server=192.168.1.1:22122 #tracker服务器
配置client:
/etc/fdfs/client.conf
tracker_server=192.168.1.1:22122
测试上传:
fdfs_test /etc/fdfs/client.conf upload .bashrc
查看group/storage信息及删除storage:
fdfs_monitor /etc/fdfs/client.conf
fdfs_monitor /etc/fdfs/client.conf delete group1 192.168.1.1
安装配置php客户端:
cd php_client/
./configure
make && make install
cp fastdfs_client.ini /etc/php.d/
#配置调用上面配置的/etc/fdfs/client.conf
使用php上传文件:
<?php
$tracker = fastdfs_tracker_get_connection();
var_dump($tracker);
$storage = fastdfs_tracker_query_storage_store();
var_dump($storage);
$ret = fastdfs_storage_upload_by_filename('fastdfs.spec');
var_dump($ret);
$ret = fastdfs_storage_upload_by_filename1('fastdfs.spec');
var_dump($ret);
$file = file_get_contents("fastdfs.spec");
$ret = fastdfs_storage_upload_by_filebuff($file, 'spec');
var_dump($ret);
$ret = fastdfs_storage_upload_by_filebuff1($file, 'spec');
var_dump($ret);
?>
storage存储安装Nginx模块,用于提供文件下载,文件不存在时通过tracker获取同组内其它storage数据:
wget http://fastdfs.googlecode.com/files/fastdfs-nginx-module_v1.15.tar.gz
./configure --add-module=/root/fastdfs-nginx-module/src
cp mod_fastdfs.conf /etc/fdfs/ #配置文件
插件配置:
tracker_server=192.168.1.1:22122
group_name=group1
url_have_group_name = false #url是否包含组名
response_mode=proxy #向其它storage获取数据方式,代理或重定向
#location /grout0/M00 { #url_have_group_name要设置为true
location /M00 {
root /home/yuqing/fastdfs/data;
ngx_fastdfs_module;
}
直接使用Nginx提供文件访问,不通过tracker:
location /M00 {
alias /home/yuqing/fastdfs/data;
#ngx_fastdfs_module;
}