fastdfs安装
1.编译安装 libevent-1.4.14b-stable
$./configure
$ make
# make install
2.FastDFS v3.05
$./make.sh
#./make.sh install
FastDFS安装使用实战二(配置篇)
1.
cd /etc/fdfs/
修改tracker.conf文件,修改如下
2.
base_path=/home/liguojun/fastdfs_tracker
3.
http.server_port=8080 -> http.server_port=8090
(http端口)
4.
##include http.conf -> #include http.conf
(http支持)
5.
reserved_storage_space = 4GB -> reserved_storage_space = 1GB
6.
port=22122
(tracker server对storage server供服务的端口)
7.
cd /usr/local/bin/
8.
fdfs_trackerd /etc/fdfs/tracker.conf
(启动tracker服务器)
9.
cat /home/liguojun/fastdfs_tracker/logs/trackerd.log
查看日志
配置及启动Storage Server
1.
cd /etc/fdfs
修改storage.conf文件,修改如下
2.
base_path=/home/yuqing/fastdfs -> /home/liguojun/fastdfs_storge
#文件的存储位置,在一台storage server上可以指定多个存储位置
#
store_path0=/home/yuqing/fastdfs -> store_path0=/home/liguojun/fastdfs_storge
3.
group_name=group1
4.
tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122
5.
##include http.conf ->#include http.conf
6.
cd /usr/local/bin/
7.
fdfs_storaged /etc/fdfs/storage.conf
8.
cat /home/liguojun/fastdfs_storge/logs/storaged.log
查看日志
FastDFS安装使用实战三(使用篇)
1.
cd /etc/fdfs
修改client.conf文件,修改如下
2.
base_path=/home/yuqing/fastdfs-> base_path=/home/soar/fastdfs_tracker
3.
tracker_server=192.168.209.121:22122 -> tracker_server=10.0.2.15:22122
4.
http.tracker_server_port=8080 ->http.tracker_server_port=8090
5.
##include http.conf ->#include http.conf
6.
cd /usr/local/bin/
7.
fdfs_test /etc/fdfs/conf/client.conf upload /home/liguojun/a.txt
上传:
package com.jd.fastdfs.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("/home/liguojun/图片/image/head.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("");
}
}
}
下载
package com.jd.fastdfs.test;
import java.io.File;
import java.io.FileOutputStream;
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/Cgr5w09wUsmIsSZvAABvCbsGaKM946.jpg";
FileInfo fi = storageClient.get_file_info(group_name, remote_filename);
byte[] b = storageClient.download_file(group_name, remote_filename);
FileOutputStream os = new FileOutputStream( "/home/liguojun/filename");
os.write(b);
os.close();
System.out.println("--->"+fi.getCreateTimestamp());
String sourceIpAddr = fi.getSourceIpAddr();
long size = fi.getFileSize();
System.out.println("ip:" + sourceIpAddr + ",size:" + size);
}
}
删除
package com.jd.fastdfs.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/Cgr5w09wUMvgS6TXAABvCbsGaKM547.jpg";
storageClient.delete_file(group_name, remote_filename);
System.out.println("删除成功");
}
}
分享到:
相关推荐
FastDFS学习笔记和课件,欢迎学习爱好者下载资源,共同学习。。
FastDFS(Fast Distributed File System)是一个开源的轻量级分布式文件系统,它是以C语言实现的,主要用于存储大规模文件的分布式存储系统。FastDFS 的设计目标是高性能、高可靠性和易扩展。 FastDFS 的核心组件...
fastdfs安装的指南,有需要的拿去,
fastdfs学习笔记
FastDFS的学习资料,包含一个代码示例以及详细的Word文档介绍
由于FastDFS集群搭建非常复杂,对于初期学习FastDFS来说,搭建个单机版的作为入门更为实际一些。
该文件为学习FastDFS必备的安装包以及jar包,同时包含一个测试demo
python3学习,django项目用到的FastDFS分布式存储服务器安装教程。
自我搭建是全部fastdfs全教程,帮助喜欢学习的小伙伴
在学习分布式集群的时候发现好多文档有问题,不能完整的部署环境,决定自己写一个大杂烩 Mysql、Redis、Zookeeper、Nginx、FastDFS集合
此代码为JAVA语言编写,实现了对FastDFS最基本的操作,即上传、下载,删除及搜索。开发工具为Eclipse,代码通俗易懂,适合FastDFS的初学者进行学习与研究
FastDFS介绍,系统架构介绍,学习分布式文件存储和对象存储的参考。
在Centos7的环境下完成FastDFS的环境搭建,提供完整的操作步骤手册及所需要的资源包,仅供大家学习参考
文件中提供了在ubuntu中使用的Docker安装源码, FastDFS的的python客户端以及美多商城项目需要存储到FastDFS中的文件内容
本人最近学习了传智播客的一个电商项目,把里面用到的工具和大家分享一下,方便大家的javaweb的学习。-fasdfs分布式文件系统
本源码项目是基于Java的FastDFS大文件上传与断点续传设计,包含36个...通过该项目,开发者可以学习并实践Java技术的应用,为后续的Web开发奠定基础。系统界面友好,易于操作,适合用于各类大文件上传与断点续传场景。
基于FastDFS实现分布式存储的上传下载等操作,并将程序封装成工具类方便直接使用。有需要的同学可学习源码。整体项目实现分解成下文5个步骤。
FastDFS上传文件系统,供新手学习使用
通过这个demo可以学习到如果在springboot中接入fastdfs
Laravel-fastdfs是分布式文件存储系统FastDFS的通用composer组件,支持常见的php框架,如laravel,yii2,thinkphp5等. 软件开发设计:应用软件开发、系统软件开发、移动应用开发、网站开发C++、Java、python、web、...