- 浏览: 330405 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
lvyuan1234:
lvyuan1234 写道lvyuan1234 写道lvyua ...
java解析mp3工具 -
lvyuan1234:
lvyuan1234 写道lvyuan1234 写道怎么一直报 ...
java解析mp3工具 -
lvyuan1234:
lvyuan1234 写道怎么一直报找不到文件?找到原因了,e ...
java解析mp3工具 -
lvyuan1234:
怎么一直报找不到文件?
java解析mp3工具 -
Cy0941:
...
org.apache.catalina.connector.RequestFacade cannot be cast to org.springframewor
先引用一下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
上传
package com.gary.test; import java.io.File; import java.io.FileInputStream; import org.csource.common.NameValuePair; import org.csource.fastdfs.ClientGlobal; import org.csource.fastdfs.ServerInfo; import org.csource.fastdfs.StorageClient; import org.csource.fastdfs.StorageServer; import org.csource.fastdfs.TrackerClient; import org.csource.fastdfs.TrackerServer; /** * 测试上传 * @author gary * */ public class TestUpload { public static void main(String[] args) throws Exception{ String classPath = new File(TestUpload.class.getResource("/").getFile()).getCanonicalPath(); String configFilePath = classPath + File.separator + "fdfs_client.conf"; System.out.println("配置文件:" + configFilePath); ClientGlobal.init(configFilePath); TrackerClient trackerClient = new TrackerClient(); TrackerServer trackerServer = trackerClient.getConnection(); StorageServer storageServer = null; StorageClient storageClient = new StorageClient(trackerServer, storageServer); NameValuePair[] meta_list = new NameValuePair[3]; meta_list[0] = new NameValuePair("width", "120"); meta_list[1] = new NameValuePair("heigth", "120"); meta_list[2] = new NameValuePair("author", "gary"); // byte[] file_buff = "F:\\pic.jpg".getBytes(ClientGlobal.g_charset); File file = new File("F:\\pic.jpg"); FileInputStream fis = new FileInputStream(file); byte[] file_buff = null; if(fis != null){ int len = fis.available(); file_buff = new byte[len]; fis.read(file_buff); } System.out.println("file length: " + file_buff.length); String group_name = null; StorageServer[] storageServers = trackerClient.getStoreStorages(trackerServer, group_name); if (storageServers == null) { System.err.println("get store storage servers fail, error code: " + storageClient.getErrorCode()); }else{ System.err.println("store storage servers count: " + storageServers.length); for (int k = 0; k < storageServers.length; k++){ System.err.println(k + 1 + ". " + storageServers[k].getInetSocketAddress().getAddress().getHostAddress() + ":" + storageServers[k].getInetSocketAddress().getPort()); } System.err.println(""); } long startTime = System.currentTimeMillis(); String[] results = storageClient.upload_file(file_buff, "jpg", meta_list); System.out.println("upload_file time used: " + (System.currentTimeMillis() - startTime) + " ms"); if (results == null){ System.err.println("upload file fail, error code: " + storageClient.getErrorCode()); return; } group_name = results[0]; String remote_filename = results[1]; System.err.println("group_name: " + group_name + ", remote_filename: " + remote_filename); System.err.println(storageClient.get_file_info(group_name, remote_filename)); ServerInfo[] servers = trackerClient.getFetchStorages(trackerServer, group_name, remote_filename); if (servers == null){ System.err.println("get storage servers fail, error code: " + trackerClient.getErrorCode()); } else { System.err.println("storage servers count: " + servers.length); for (int k = 0; k < servers.length; k++){ System.err.println(k + 1 + ". " + servers[k].getIpAddr() + ":" + servers[k].getPort()); } System.err.println(""); } } }
console输出:
配置文件:D:\AEclipse2\workspace\myeclipse\testFastDFS\bin\fdfs_client.conf file length: 10 store storage servers count: 1 1. 192.168.49.130:23000 upload_file time used: 29 ms group_name: group1, remote_filename: M00/00/00/wKgxgk5HbLvfP86RAAAAChd9X1Y736.jpg source_ip_addr = 192.168.49.130, file_size = 10, create_timestamp = 2011-08-14 14:35:39, crc32 = 394092374 storage servers count: 1 1. 192.168.49.130:23000
上传成功后可以打开浏览器使用http方式访问此文件,ip+port+group+filename,
例如 http://192.168.49.130:8001/group1/M00/00/00/wKgxgk5HcFCwvS9QAAANWIusP08057.jpg
获取文件信息
package com.gary.test; import java.io.File; import org.csource.fastdfs.ClientGlobal; import org.csource.fastdfs.FileInfo; import org.csource.fastdfs.StorageClient; import org.csource.fastdfs.StorageServer; import org.csource.fastdfs.TrackerClient; import org.csource.fastdfs.TrackerServer; /** * 获取文件信息 * @author gary * */ public class TestGet { public static void main(String[] args) throws Exception { String classPath = new File(TestGet.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/wKgxgk5HcFCwvS9QAAANWIusP08057.jpg"; FileInfo fi = storageClient.get_file_info(group_name, remote_filename); String sourceIpAddr = fi.getSourceIpAddr(); long size = fi.getFileSize(); System.out.println("ip:" + sourceIpAddr + ",size:" + size); } }
console输出
ip:192.168.49.130,size:3416
删除
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项目源代码
评论
我也是上传报这个错误。。。。求解
为什么删除不了呢?求解
发表评论
-
解决activiti生成的PNG乱码
2012-02-01 11:26 3202使用的版本为activiti5.8 修改org.act ... -
tomcat启动报错Socket accept failed
2011-08-11 21:11 4882tomcat启动时,报错如下: 2011-8-11 2 ... -
URL工具类
2011-05-11 23:21 2773package ssh.util; import jav ... -
HTML工具类
2011-05-11 23:19 1339package ssh.util; import ... -
利用Spring AOP记录Hibernate统计信息
2011-03-19 08:41 1679在Hibernate的属性里设置hibernate.gener ... -
搭建liferay-portal6.0.6
2011-03-09 19:48 2867首先在http://sourceforge.net/proje ... -
Quartz在Spring中的使用
2011-03-08 17:43 2116Quartz项目主页http://www.quartz-sch ... -
使用httpclient模拟表单提交
2011-01-31 22:19 15412文件类型使用FileBody,字符串类型使用StringBod ... -
懒人专用,方便调试:反射生成hibernate映射类的toString方法
2011-01-04 21:28 1532...不知道有没有和我一样懒的,表的列太多,一个一个弄太麻烦, ... -
用junit测试SSH项目以及常见错误解决方法
2011-01-01 21:42 3285public static BeanFactory f ... -
log4j配置详解,附带hibernate
2010-12-31 18:53 9157log4j.properties # For JBoss: ... -
导入导出Excel工具,支持XML和properties配置(二)
2010-12-25 08:49 2318XMLUtil.java package ssh.ut ... -
导入导出Excel工具,支持XML和properties配置(一)
2010-12-25 08:46 2338需要jxl.jar,dom4j.jar JXLUtil.j ... -
java读取rss
2010-12-24 13:51 5043用到的jar包为jdom.jar, rome-1.0.jar( ... -
log4j:ERROR LogMananger.repositorySelector was null
2010-12-23 15:32 1456排除log4j版本问题后,仍出现此问题,解决方法:设置org. ... -
log4j.properties配置文件模板
2010-12-23 10:36 1500# For JBoss: Avoid to setup ...
相关推荐
fastdfs 安装配置过程,经过测试,java 客户端成功调用。
storage/group1--group2,mod_fastdfs.conf;master/backup--keepalived.conf,nginx.conf,nginx_check.sh
FastDFS 安装和配置.docx。• 安装 libfastcommon-1.0.7.tar.gz o 解压:tar zxvf libfastcommon-1.0.7.tar.gz o 进入解压后目录:cd libfastcommon-1.0.7/ o 编译:./make.sh o 安装:./make.sh install o ...
fastdfs一键安装脚本,可以0配置!!!个人如果需要优化,可以自行修改配置文件
Ubuntu下安装配置FastDFS文件存储服务器的详细文档教程
其中包括FastDFS安装包,各个配置文件的配置,以及Java客户端操作FastDFS的使用。
fastdfs_client; fastdfs_client_java._v1.25.tar.gz; ...分布式文件系统FastDFS架构剖析及配置优化.pdf; FASTdfs-入门-1.0.docx; 分布式存储 CentOS6.5虚拟机环境搭建FastDFS-5.0.5集群.pdf;
个人在世界的工作中整理的FastDFS 文件分布式存储配置,服务器采用ubuntu。并实现了java的调用demo
存储系统由一个或多个卷组成,卷与卷之间的文件是相互独立的,所有卷的文件容量累加就是整个存储系统中的文件容量。一个卷可以由一台或多台存储服务器组成,一个卷下的存储服务器中的文件都是相同的,卷中的多台存储...
fastdfs客户端单元测试及Java客户端配置文件,项目中需要fastdfs-client依赖
一、Fastdfs 添加分组测试服务器:两台 A(39.106.136.45) B(39.107.238.105)基本配置A 服务器有一个tracker 三个S
用于上传到文件服务器的jar,里面不含配置文件,如果要上传源码,配置文件
FastDFS是一款开源的轻量级分布式文件系统 纯C实现,支持Linux、FreeBSD等UNIX系统 类google FS,不是通用的文件系统,只能通过专有API访问,目前提供了C、Java和PHP API 为互联网应用量身定做,解决大容量文件存储...
上传到文件服务器的jar,里面不含配置文件,如果要上传源码,配置文件,调用,jar全套的话见http://download.csdn.net/download/it_java_shuai/9960309
FastDFS单点安装: 包含安装包和配置文件 java客户端Jar 包
通常,我们以fastdfs_client.conf方式使用fastdfs java客户端。 它运行良好,直到我们开始使用spring boot。 配置文件方式不能满足Spring Boot的活动配置文件,例如: dev , test , pro ,我们希望客户端以Spring...
实现了在ubuntu上fastDFS 的安装和配置,并附带一个java的上传demo
FastDFS总结文档,全网比较全的资料整理,包括服务器搭建,常用问题,应用开发,常用配置等,几乎包括的所有FastDFS相关知识点。