Welcome

首页 / 软件开发 / C# / C#和.NET中如何利用FastDFS打造分布式文件系统

C#和.NET中如何利用FastDFS打造分布式文件系统2014-10-05背景

海量存储、系统负载的迁移、服务器吞吐的瓶颈等等 让文件系统独立于业务系统 提高整个项目的扩展性以及可维护性

目前主流的方案 MFS FASTDFS GFS LUSTRE HADOOP等等

我选择的是FASTDFS 用一句广告语来说 “免费、快速、找得到”。FASTDFS的作者是淘宝的资深架构师余庆,很诙谐、很有爱!!!其他方案还没玩过 暂不评论。

简介

FastDFS是一款开源的轻量级分布式文件系统纯C实现,支持Linux、FreeBSD等UNIX系统类google FS,不是通用的文件系统,只能通过专有API访问,目前官方提供了C、Java和PHP API为互联网应用量身定做,追求高性能和高扩展性,FastDFS可以看做是基于文件的key value pair存储系统,称作分布式文件存储服务更为合适。

特点:

分组存储,灵活简洁

对等结构,不存在单点

文件ID由FastDFS生成,作为文件访问凭证。FastDFS不需要传统的name server

和流行的web server无缝衔接,FastDFS已提供apache和nginx扩展模块

大中小文件均可以很好支持,支持海量小文件存储

存储服务器上可以保存文件附加属性

名词解释:

Tracker Server:跟踪服务器,主要做调度工作,在访问上起负载均衡的作用。在内存中记录集群中group和storage server的状态信息,是连接Client和Storage server的枢纽。 因为相关信息全部在内存中,Tracker server的性能非常高,一个较大的集群(比如上百个group)中有3台就足够了。

Storage Server:存储服务器,文件和文件属性(meta data)都保存到存储服务器上。

实践-服务端

系统:ubuntu

开发工具:vim

web服务:nginx

基于socket自定义通信协议

服务端的安装参考官方文档 有不懂的可以联系虫子 这里说下问题比较多的2个地方 一个是libevent的版本问题 另一个是ubuntu最新版本中对于libpthread等库文件的存放位置问题

安装完fastdfs以后 假设你的服务端程序安装在/usr/local目录

我们会在bin目录下找到以下文件

storage服务器启动命令 /usr/local/bin/fdfs_storaged /FastDFS/conf/storage.conf

tracker服务器启动命令 /usr/local/bin/fdfs_trackerd /FastDFS/conf/tracker.conf

我们运行monitor查看下配置信息

group count: 1 Group 1:group name = testfree space = 5 GBstorage server count = 2active server count = 2storage_port = 23000storage_http_port = 0store path count = 1subdir count per path= 3current write server index = 0 Host 1:ip_addr = 192.168.234.139 (ubuntu)ACTIVEtotal storage = 9GBfree storage = 5GBtotal_upload_count = 2success_upload_count = 2total_set_meta_count = 0success_set_meta_count = 0total_delete_count = 0success_delete_count = 0total_download_count = 0success_download_count = 0total_get_meta_count = 0success_get_meta_count = 0total_create_link_count = 0success_create_link_count = 0total_delete_link_count = 0success_delete_link_count = 0last_heart_beat_time = 2012-01-05 18:45:50last_source_update = 2012-01-05 01:20:28last_sync_update = 1969-12-31 16:00:00last_synced_timestamp= 1969-12-31 16:00:00Host 2:ip_addr = 192.168.234.140ACTIVEtotal storage = 18GBfree storage = 12GBtotal_upload_count = 16success_upload_count = 16total_set_meta_count = 0success_set_meta_count = 0total_delete_count = 0success_delete_count = 0total_download_count = 0success_download_count = 0total_get_meta_count = 0success_get_meta_count = 0total_create_link_count = 0success_create_link_count = 0total_delete_link_count = 0success_delete_link_count = 0last_heart_beat_time = 2012-01-05 18:45:50last_source_update = 2012-01-05 01:54:02last_sync_update = 1969-12-31 16:00:00last_synced_timestamp= 1969-12-31 16:00:00
本文URL地址:http://www.bianceng.cn/Programming/csharp/201410/45480.htm