读书人

FastDFS的装配,配置与使用(java)

发布时间: 2012-06-27 14:20:09 作者: rapoo

FastDFS的安装,配置与使用(java)

先引用一下FastDFS的介绍:

FastDFS is an open source high performance distributed file system. It's major functions include: file storing, file syncing and file accessing (file uploading and file downloading), and it can resolve the high capacity and load balancing problem. FastDFS should meet the requirement of the website whose service based on files such as photo sharing site and vidio sharing site.

FastDFS has two roles: tracker and storage. The tracker takes charge of scheduling and load balancing for file access. The storage store files and it's function is file management including: file storing, file syncing, providing file access interface. It also manage the meta data which are attributes representing as key value pair of the file. For example: width=1024, the key is "width" and the value is "1024".

?

?

开始安装:

1. 在http://code.google.com/p/fastdfs/downloads/list下载所需文件,此外还需先安装好libevent


2. tar xzf FastDFS_v2.11.tar.gz


3. cd FastDFS
如果支持HTTP, vi make.sh, 使用/WITH_HTTPD查找到这一行,输入i进入编辑模式,删除掉前面的注释#,:wq保存退出,如果需要安装成服务,则把下面一行也解开
./make.sh
./make.sh install


4. 使用netstat -an | grep 端口号, 找几个空闲的端口


5. 根据实际情况修改/etc/fdfs下的配置文件,每个上面都有注释说明,如果需要HTTP,别忘了解开最下面的#include http.conf,要带一个#


6. 启动tracker:?/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf


7. 启动storage:?/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf如果出现错误,可以到步骤5修改配置文件时设置的目录的log目录下查看具体错误原因,我就是因为多删了一#导致变量无法导入,总是空.


8. 到此安装配置完毕


上传文件:/usr/local/bin/fdfs_upload_file ?<config_file> <local_filename>

下载文件:/usr/local/bin/fdfs_download_file <config_file> <file_id> [local_filename]

删除文件:/usr/local/bin/fdfs_delete_file <config_file> <file_id>

monitor:?/usr/local/bin/fdfs_monitor /etc/fdfs/client.conf

关闭:

killall fdfs_trackerd

killall fdfs_storaged

/usr/local/bin/stop.sh /usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/local/bin/stop.sh /usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf


重启:

/usr/local/bin/restart.sh?/usr/local/bin/fdfs_trackerd /etc/fdfs/tracker.conf

/usr/local/bin/restart.sh?/usr/local/bin/fdfs_storaged /etc/fdfs/storage.conf


9.java client

上传

?console输出:

?获取文件信息

?console输出

package com.gary.test;import java.io.File;import org.csource.fastdfs.ClientGlobal;import org.csource.fastdfs.StorageClient;import org.csource.fastdfs.StorageServer;import org.csource.fastdfs.TrackerClient;import org.csource.fastdfs.TrackerServer;/** * 删除文件 * @author gary * */public class TestDelete {public static void main(String[] args) throws Exception {String classPath = new File(TestDelete.class.getResource("/").getFile()).getCanonicalPath();String configFilePath = classPath + File.separator + "fdfs_client.conf";ClientGlobal.init(configFilePath);TrackerClient trackerClient = new TrackerClient();    TrackerServer trackerServer = trackerClient.getConnection();    StorageServer storageServer = null;    StorageClient storageClient = new StorageClient(trackerServer, storageServer);        String group_name = "group1";    String remote_filename = "M00/00/00/wKgxgk5HbLvfP86RAAAAChd9X1Y736.jpg";    storageClient.delete_file(group_name, remote_filename);    System.out.println("删除成功");}}
?

附件为配置文件和myeclipse项目源代码

读书人网 >软件架构设计

热点推荐