本文主要是介绍CentOS6.5final下TFS的安装和使用,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
安装环境:CentOS6.5final 安装目录/opt 下载目录:/home/downloads
一:安装依赖包
[root@promote ~]# yum -y install automake
[root@promote ~]# yum -y install libtool
[root@promote ~]# yum -y install readline readline-devel
[root@promote ~]# yum -y install libuuid-devel
[root@promote ~]# yum -y install zlib-devel
[root@promote ~]# yum -y install mysql-devel
[root@promote ~]# cd /home/downloads/
[root@promote downloads]# wget http://www.canonware.com/download/jemalloc/jemalloc-3.5.0.tar.bz2
[root@promote downloads]# tar jxvf jemalloc-3.5.0.tar.bz2
[root@promote downloads]# cd jemalloc-3.5.0
[root@promote jemalloc-3.5.0]# ./configure --prefix=/usr/local
[root@promote jemalloc-3.5.0]# make && make install
二、TFS依赖于底层开发包tbnet,这里要先安装tbsys和tbnet
[root@promote downloads]# yum install subversion
[root@promote downloads]# svn checkout -r 18 http://code.taobao.org/svn/tb-common-utils/trunk/ tb-common-utils
[root@promote downloads]# cd tb-common-utils
[root@promote tb-common-utils]# mkdir -p /opt/tblib/
[root@promote tb-common-utils]# vim /etc/profile
按i进入编辑,在最后加上
export TBLIB_ROOT=/opt/tblib/
:wq保存
下一步使修改立即生效
[root@promote tb-common-utils]# source /etc/profile
[root@promote tb-common-utils]# yum install gcc-c++
[root@promote tb-common-utils]# sh build.sh
三、对GCC降级
[root@promote tb-common-utils]# cd /home/downloads/
[root@promote downloads]# wget http://www.mirrorservice.org/sites/sources.redhat.com/pub/gcc/releases/gcc-4.1.2/gcc-4.1.2.tar.bz2
[root@promote downloads]# tar xjvf gcc-4.1.2.tar.bz2
[root@promote downloads]# cd gcc-4.1.2
[root@promote gcc-4.1.2]# mkdir -p /opt/gcc-4.1.2/
[root@promote gcc-4.1.2]# ./configure --prefix=/opt/gcc-4.1.2/
[root@promote gcc-4.1.2]# yum install texinfo
[root@promote gcc-4.1.2]# which makeinfo结果为/usr/bin/makeinfo
[root@promote gcc-4.1.2]# cd /home/downloads/gcc-4.1.2
[root@promote gcc-4.1.2]# vim Makefile将MAKEINFO = MAKEINFO = /home/downloads/gcc-4.1.2/missing makeinfo
修改为MAKEINFO = /usr/bin/makeinfo
在258行,wq保存退出[root@promote gcc-4.1.2]# yum -y install glibc-devel.i686 glibc-devel
[root@promote gcc-4.1.2]# make -j4&&make install[root@localhost gcc-4.1.2]# mv /usr/bin/gcc /usr/bin/gccold[root@localhost gcc-4.1.2]# ln -s /opt/gcc-4.1.2/bin/gcc /usr/bin/gcc[root@localhost gcc-4.1.2]# mv /usr/bin/g++ /usr/bin/g++old[root@localhost gcc-4.1.2]# ln -s /opt/gcc-4.1.2/bin/g++ /usr/bin/g++
[root@localhost src]# gcc -v结果为:
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: ./configure --prefix=/opt/gcc-4.1.2/
Thread model: posix
gcc version 4.1.2
gcc降级成功!
四、安装TFS
[root@promote lmy]# cd /home/downloads/
[root@promote downloads]# svn co http://code.taobao.org/svn/tfs/tags/release-2.2.16
[root@promote downloads]# cd release-2.2.16
[root@promote release-2.2.16]# mkdir /opt/tfs-2.2.16
[root@promote release-2.2.16]# sh build.sh init
[root@promote release-2.2.16]# ./configure --prefix=/opt/tfs-2.2.16/ --without-tcmalloc --with-release
[root@promote release-2.2.16]# make && make install
安装完成之后,在安装目录下的/opt/tfs-2.2.16/conf下可能没有配置文件,此时需要从下载的源文件的解压文件中的conf目录中拷贝。
[root@promote conf]# cp /home/downloads/release-2.2.16/conf/{ns.conf,ds.conf,ads.conf} /opt/tfs-2.2.16/conf
四、配置TFS
ns.conf
需要修改的地方我都用下划线标注了,修改的时候注意自己的安装目录和IP地址。配置参考淘宝TFS分布式文件系统 + php接口
[public]
#log file size default 1GB
log_size=1073741824#log file num default 64
log_num = 64 #log file level default debuglog_level=error
---------------#main queue size default 10240
task_max_queue_size = 10240#listen portport = 8888
-----------#work directoy 工作目录,也就是tfs的安装目录work_dir=/opt/tfs-2.2.16
------------------------#device name 网络设备,即通信网卡dev_name= eth0
--------------#work thread count default 4
thread_count =4 #ip addr(vip) 本机IP地址(vip),配置ha时为vip,没配置可以为主ns的ipip_addr = 192.168.190.133
-------------------------[nameserver]safe_mode_time = 360#nameserver IP地址列表(master, salve的ip地址,只能以'|'分隔)
#单台nameserver时,另一个ip配置为无效ip即可ip_addr_list = 192.168.190.133|192.168.0.2
------------------------------------------group_mask = 255.255.255.255#second
max_write_timeout = 3#max_task_in_machine_nums = 14#cleanup_write_timeout_threshold = 40960# cluster id defalut 1
cluster_id = 1 # block use ratio
block_max_use_ratio = 98# bytes
#Block size的最大值, 单位(字节)
#这个值到底怎么配置好,有待实验。 必须 >= dataserver的mainblock_size,推荐设置一致。 block_max_size = 7549747
------------------------#单台dataserver时,需要配置为1max_replication = 1
-------------------# block lost, replicate ratio
replicate_ratio = 50max_write_filecount = 64 # use capacity ratio
use_capacity_ratio = 96#heart interval time(seconds)
heart_interval = 4# object dead max time(seconds) default
object_dead_max_time = 300#
object_clear_max_time = 180 heart_thread_count = 4 heart_max_queue_size = 2048report_block_thread_count = 6report_block_max_queue_size = 32report_block_hour_range = 2~4#day
report_block_time_interval = 1#heart_interval * 2
#report_block_expired_time = 4#replicate block wait time
repl_wait_time = 180compact_delete_ratio = 10 compact_max_load = 200compact_hour_range = 1~10dump_stat_info_interval = 60000000 balance_percent = 0.05add_primary_block_count = 3task_percent_sec_size = 200 oplog_sync_max_slots_num = 1024oplog_sync_thread_num = 1group_count = 1group_seq = 0discard_newblk_safe_mode_time = 360 choose_target_server_random_max_num = 128#task_expired_time = 120
ds.conf
[public]
#log file size default 1GB
log_size=1073741824#log file num default 64
log_num = 4 #log file level default debuglog_level=error
---------------#main queue size default 10240
task_max_queue_size = 10240#listen portport = 9998
-----------#work directoywork_dir=/opt/tfs-2.2.16
------------------------#device namedev_name= eth0
--------------#work thread count default 4
thread_count = 4 #ip addr
#本机IP地址
ip_addr = 192.168.190.133
-------------------------[dataserver]#nameserver ip addr(vip)
#NameServer 地址 如果有ha,用ha的vip地址
ip_addr = 192.168.190.133
-------------------------
#nameserver IP地址列表(master, salve的ip地址,只能以'|'分隔) nameserver主从IPip_addr_list = 192.168.190.133|192.168.0.2
------------------------------------------#nameserver portport = 8888
-----------# slave cluster ns ip:port
# slave_nsip = 192.168.0.10:8100#heart interval time(seconds)
heart_interval = 2check_interval = 2#expire_datafile_time = 90#expire_clonedblock_time = 180#expire_compactblock_time = 600replicate_threadcount = 1#write_sync_flag = 1#block 最大size
block_max_size = 7549747 dump_visit_stat_interval = 60#max_io_warning_time = 0backup_type = 1#备份路径
backup_path = /mnt
------------------#max_data_file_nums = 50#max_crc_error_nums = 4#max_eio_error_nums_ = 6#expire_checkblock_time = 86000#max_cpu_usage = 60#dump_stat_info_interval = 60000000#mount路径 很关键,一定要写对,不用加id号 如hda1挂载在/data/tfs1,也就是格式化成ext4的磁盘挂载点
mount_name = /data/tfs# KB
mount_maxsize = 3000000base_filesystem_type = 1superblock_reserve = 0# bytes
avg_file_size = 15360#主块的大小, 单位(字节) 重点,需要与nameserver的配置一样或者比它小
# bytes
mainblock_size = 7549747 # bytes
extblock_size = 4194304block_ratio = 0.5hash_slot_ratio = 0.5
ads.conf
[public]
#log file size default 1GB
log_size=1073741824#log file num default 64
log_num = 4 #log file level default debuglog_level=error
---------------#main queue size default 10240
task_max_queue_size = 10240#listen portport = 12000
------------#work directoywork_dir=/opt/tfs-2.2.16
------------------------#device namedev_name= eth0
--------------#work thread count default 4
thread_count = 4ip_addr = 192.168.190.133
-------------------------[adminserver]# check interval
check_interval = 5
# check count
check_count = 5
# warn threshhold
warn_dead_count = 3
# wait time before kill ds
ds_fkill_waittime = 15
# ds start base cmdds_script = /opt/tfs-2.2.16/bin/dataserver -f /opt/tfs-2.2.16/conf/ds.conf -d
------------------------------------------------------------------------# ds index list
ds_index_list = 1,2,3[nameserver]ip_addr = 192.168.190.133
-------------------------port = 8888
-----------[dataserver]port = 9998
-----------lock_file = /opt/tfs-2.2.16/logs/dataserver
-------------------------------------------mount_name = /data/tfs
---------------------
启动nameserver
[root@localhost conf]# cd /opt/tfs-2.2.16/scripts/
[root@localhost scripts]# ./tfs start_ns结果为:nameserver is up SUCCESSFULLY pid: 2548 查看监听端口:
[root@localhost scripts]# netstat -tnlpnameserver启动成功
启动dataserver
首先需要格式化一个分区为ext4文件系统,并挂载到/data/tfs1至/data/tfs(i),其中i为磁盘号。注意上面的 mount_name = /data/tfs 没有加(i)
假设你是用虚拟机,添加一个硬盘hda,添加硬盘的方式见链接
按照链接的方式做到第七步即可,即添加完成硬盘。
然后挂载硬盘
[root@promote conf]# mkfs.ext4 /dev/sdb1
[root@promote conf]# mkdir -p /data/tfs1
[root@promote conf]# mount /dev/sdb1 /data/tfs1
[root@promote scripts]# ./stfs format 1format ds 1 SUCCESSFULLY
[root@promote scripts]# ./tfs start_ds 1dataserver 1 is up SUCCESSFULLY pid: 2688
至此,dataserver启动成功。
如果启动ds的时候提示error while loading shared libraries: libjemalloc.so.1: cannot open shared object file: No such file or directory
做一下软链接就可以了
ln -s /usr/local/lib/libjemalloc.so.1 /usr/lib64/libjemalloc.so.1
下面进行上传和下载文件测试:
上传文件:[root@promote opt]# /opt/tfs-2.2.16/bin/tfstool -s 192.168.190.134:8888
TFS> put /opt/a.txt
可以看到
*put /opt/a.txt => T10RJTByJT1RCvBVdK success
说明上传文件成功,同时在打印出来的日志中可以看到blockID,例如此时我的日志中blockid: 341*下载文件:
[root@promote opt]# /opt/tfs-2.2.16/bin/ds_client -d 192.168.190.134:9998下面的这个命令是查看blockID=341下的文件
DataServer> list_file 341下面的这个命令是将blockID=341下的第一个文件下载存为1.txt
DataServer> read_file_data 341 1 /opt/1.txtdownload tfs file 341, 1 to local file /opt/1.txt success.下载文件成功!
这篇关于CentOS6.5final下TFS的安装和使用的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!