TFS使用简介

背景:项目中可能会大量存储50K左右的htm小文件,估计每天产生1亿个左右;那么规划三年的存储总量将超千亿,加上俩份备份,总存储将达到15P,如果每台server总磁盘16T,总计需要1000台左右。显然,这么大规模的小文件存储,只能选择taobao的TFS。

1 tfs综述
http://blog.yunnotes.net/index.php/tfs_user_faq/

2 安装
http://blog.yunnotes.net/index.php/install_document_for_tfs/

3 部署
http://blog.yunnotes.net/index.php/deploy_document_for_tfs/

4 调用
http://code.taobao.org/p/tfs/wiki/jclient/
http://code.taobao.org/p/tfs-client-java/wiki/index/


5 下面重点说说碰到的问题
我是在本机的ubuntu13.04 64位上安装tfs2.2.16
首先apt-get安装依赖包automake,libtool,realine,libz-devel,uuid-devel,tcmalloc没遇上啥问题。

其次,下载源码安装tb-common-utils的俩个库也没遇上大问题。

然后,下载tfs源码编译安装遇到了很多问题,总之就是缺这个库缺那个库,具体见下面:
1  configure问题
在./configure 命令之后提示下面的错误: configure: error: C++ compiler cannot create executables

这是因为gcc环境不全,按这篇文章解决http://www.cnblogs.com/Dreama/articles/2114435.html

2  make&make install错误
由于taobao是用gcc早期版本4.1.2编译的,而我本机gcc是4.7.3版本,因此很多地方报错
a:configure加上--with-release参数:./configure --prefix=path_to_tfs --with-release

b:make时uuid相关错误
undefined reference to `uuid_generate‘ 

undefined reference to `uuid_unparse'
到 src/tools/nameserver中修改Makefile
或者报错的其他模块中,修改Makefile
LIBS = -lmysqlclient -lrt -lpthread -lm -ldl -lc  加   -lz -luuid

具体参见这篇文章:http://www.cnblogs.com/zhy113/archive/2013/03/20/2971267.html


千辛万苦终于安装成功了,配置ns.conf,ds.conf 参见源码部分:http://code.taobao.org/p/tfs/src/trunk/conf/  不同的版本启动ns,ds需要的参数可能不太一样。

启动nameserver和dataserver,如果成功会打印出相应的pid


终于启动成功啦,用tfstool put一个文件,显示成功,但返回null文件名,google后好像是tfstool的问题。先不管它,下面用javaclient来调用:
我一开始自己下tfs-client-java源码打包成jar,版本是2.3.2,但是配置过程中发现2.1.4后需要rcserver,所以放弃高版本重新下载2.1.1版本;另外高版本的tfs-client-java 测试代码还需要tair这个jar,你得下载tair和tairjavaclient,实在依赖太多太麻烦了。因此我选择了低版本,然后自己写测试代码。

taobao的开源产品最大问题就是文档不太全,然后内部依赖太多,从TFS,TDDL等都是这样,依赖太多也导致产品的开源和推广进度会受到较大影响。说实话,很多人在编译和安装过程中遇到那么多error,8成人可能都放弃了。

现在终于OK啦:
调用代码如下:
package cn.com.dbapp.bas.tfs;

import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.taobao.common.tfs.DefaultTfsManager;
import com.taobao.common.tfs.TfsManager;

public class TfsjavaclientTest {
	public static void main(String[] args){
		ClassPathXmlApplicationContext appContext = new ClassPathXmlApplicationContext(new String[] { "tfs.xml" }); 
		TfsManager tfsManager = (DefaultTfsManager) appContext.getBean("tfsManager");
		//String localfile = "/opt/tfs/testfile";
		//不传入suffix和tfsname
		
		//String tfsname = tfsManager.saveFile(localfile, null, null);
		//System.out.println("save with no parameters " + tfsname);
		
		//String tfsname2 = tfsManager.saveFile("testfile".getBytes(), null, null);
		//System.out.println("save with bytes " + tfsname2);
		//return was as below
		//save with no parameters T1ItETByJT1RCvBVdK
		//save with bytes T1xaETByJT1RCvBVdK
		//String tmp1="/opt/tfs/tmpfile";
		//String tmp2="/opt/tfs/bytesfile";
		//String tfsname3= tfsManager.saveFile("Hello TFS!!".getBytes(), null, ".html");
		//System.out.println("save with bytes " + tfsname3);
		tfsManager.fetchFile("T1xRETByJT1RXx1p6K", ".html","/opt/tfs/tfs.html");
		
		//tfsManager.fetchFile("T1ItETByJT1RCvBVdK", null, tmp1);
		//tfsManager.fetchFile("T1xaETByJT1RCvBVdK", null, tmp2);
		System.out.println("Fectch file finished...");

}
}


tfs.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
    <bean id="tfsManager" class="com.taobao.common.tfs.DefaultTfsManager" init-method="init" >
      <!-- 整个进程中系统最多等待多少个请求,取决于你有多少个线程并发的请求TFS -->
       <property name="maxWaitThread">
        <value>100</value>
      </property>
      <!-- 单个请求最大的等待时间(ms) 超过这个时间放弃这次请求-->
      <property name="timeout">
        <value>2000</value>
      </property>
      <!-- Tfs master nameserver ip address -->
      <property name="nsip">
        <value>10.0.2.15:8100</value>
      </property>
      <!-- TFS 集群的编号,这个编号只是一种参考,系统初始化的时候会从ns上取,取不到才用本地设置的.!-->
      <property name="tfsClusterIndex">
        <value>1</value>
      </property>
      <!-- TFS在读取文件的时候会缓存block所在的数据服务器ip,这个参数配置了最多缓存的记录个数!-->
      <property name="maxCacheItemCount">
        <value>10000</value>
      </property>
      <!-- 上一项缓存最大有效的时间(ms)!-->
      <property name="maxCacheTime">
        <value>5000</value>
      </property>
       <!-- 不需要排重功能时,下面配置项可以不设置 -->
       <!-- tair排重数据库的serverlist -->
      
       <!-- tair排重数据库的groupName -->
     
       <!-- tair排重数据库的namespace -->
      
   </bean>
</beans>


BTW, 由于网络问题,我的vbox不能选择桥接,只能用NAT,使得我的win7不能访问ubuntu的ip,我的调用代码是在ubuntu虚拟机上eclipse写的,在安装tfs过程中,也顺便安装了maven,svn等;加上去年装的hadoop,tomcat,hbase,hive,原先开的20G空间 ,1G ram已经不太够用啦。

猜你喜欢

转载自jd2bs.iteye.com/blog/2066310
TFS
今日推荐