通过OneBox体验Tera

为了最快速度体验Tera,Tera提供一个OneBox方式布署,利用本地存储代替DFS,利用本地文件模拟ZK,单机多进程运行master、tabletnode。此模式下可正常使用Tera的全部功能,包括(不限于):

  • 表格新建(create)、schema修改(update)、删除(drop)、卸载(disable)、加载(enable)等
  • 数据写入(put)、删除(delete)、随机读(get)、顺序读(scan)等
  • 数据分片分裂(split)、合并(merge)、负载均衡(move)等

准备工作

  1. 完成Tera的编译,请参考:https://github.com/baidu/tera/wiki/Build-Manual
  2. 将编译生成的tera_master, tabletserver, teracli三个二进制文件放入example/onebox/bin
  3. 如有需要,通过修改example/onebox/bin/config中的选项配置tabletnode个数
  4. 进入example/onebox/bin/目录

启动、停止Tera

  • 执行./launch_tera.sh即可启动Tera
    1. [tera@localhost bin]$ sh launch_tera.sh
    2. launching tabletnode 1...
    3. launching tabletnode 2...
    4. launching tabletnode 3...
    5. launching master...
  • 执行./kill_tera.sh即可停止Tera

体验开始!

如果启动正常,尝试查看集群基本信息: ./teracli show

  1. [tera@localhost bin]$ ./teracli show
  2. tablename status size lg_size tablet notready
  3. -----------------------------------------------------------------
  4. 0 meta_table kTableEnable 4.01K 4.01K 1 0
  5. 1 stat_table kTableEnable 4K 4K 1 0
  6. - total - 8.01K - 2 0

查看更详细的表格信息:./teracli showx

  1. [tera@localhost bin]$ ./teracli showx
  2. tablename status size lg_size tablet notready lread read rmax rspeed write wmax wspeed scan smax sspeed
  3. --------------------------------------------------------------------------------------------------------------------------------------
  4. 0 meta_table kTableEnable 4.01K 4.01K 1 0 0 0 0 0B/s 0 0 0B/s 0 0 0B/s
  5. 1 stat_table kTableEnable 28.06K 28.06K 1 0 0 0 0 0B/s 0 0 0B/s 0 0 0B/s
  6. - total - 32.07K - 2 0 0 0 - 0B/s 0 - 0B/s 0 - 0B/s

查看当前有哪些存活的tabletnode: ./teracli showts

  1. [tera@localhost bin]$ ./teracli showts
  2. address status workload tablet load busy
  3. -----------------------------------------------------------
  4. 0 127.0.0.1:7701 kReady 4.01K 1 0 0
  5. 1 127.0.0.1:7702 kReady 32.06K 1 0 0
  6. 2 127.0.0.1:7703 kReady 0 0 0 0

查看更详细的tabletnode信息:./teracli showtsx

  1. [tera@localhost bin]$ ./teracli showtsx
  2. address status size num lread r rspd w wspd s sspd rdly rp wp sp ld bs mem cpu net_tx net_rx dfs_r dfs_w
  3. -------------------------------------------------------------------------------------------------------------------------------------------------
  4. 0 127.0.0.1:7701 kReady 4.01K 1 0 0 0B 0 0B 0 0B 0ms 0 0 0 0 0 12.10M 0 12.11K 5.57K 0 0
  5. 1 127.0.0.1:7702 kReady 32.06K 1 0 0 0B 0 0B 0 0B 0ms 0 0 0 0 0 11.83M 0 12.11K 5.57K 0 0
  6. 2 127.0.0.1:7703 kReady 0 0 0 0 0B 0 0B 0 0B 0ms 0 0 0 0 0 11.08M 0 12.11K 5.57K 0 0

新建一个表格hello,包含两个列族cf0和cf1: ./teracli create 'hello{cf0,cf1}'

  1. [tera@localhost bin]$ ./teracli create 'hello{cf0,cf1}'
  2. hello <splitsize=512,mergesize=0> {
  3. lg0 <storage=disk> {
  4. cf0,
  5. cf1,
  6. },
  7. }
  8. [tera@localhost bin]$ ./teracli show
  9. tablename status size lg_size tablet notready
  10. ------------------------------------------------------------------
  11. 0 hello kTableEnable 4.01K 4.01K 1 0
  12. 1 meta_table kTableEnable 4.01K 4.01K 1 0
  13. 2 stat_table kTableEnable 44.12K 44.12K 1 0
  14. - total - 52.14K - 3 0

写入一条数据(列族是cf0,列是column1): ./teracli put hello row1 cf0:column1 value1

随机读出刚写入的数据: ./teracli get hello row1

  1. [tera@localhost bin]$ ./teracli get hello row1
  2. row1:cf0:column1:1477367889042685:value1

多写一些数据:

  1. [tera@localhost bin]$ ./teracli put hello row2 cf1:column0 value2
  2. [tera@localhost bin]$ ./teracli put hello row2 cf1:column1 value3
  3. [tera@localhost bin]$ ./teracli put hello row0 cf1:column1 value0

顺序读出整个表格的数据: ./teracli scan hello "" ""

  1. [tera@localhost bin]$ ./teracli scan hello "" ""
  2. row0:cf1:column1:1477368174895134:value0
  3. row1:cf0:column1:1477367889042685:value1
  4. row2:cf1:column0:1477368164358077:value2
  5. row2:cf1:column1:1477368169176632:value3

卸载表格: ./teracli disable hello

  1. [tera@localhost bin]$ ./teracli disable hello
  2. >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 100% 1.000 1.000/s 00:00:01
  3. [tera@localhost bin]$ ./teracli show
  4. tablename status size lg_size tablet notready
  5. -------------------------------------------------------------------
  6. 0 hello kTableDisable 4.01K 4.01K 1 0
  7. 1 meta_table kTableEnable 4.01K 4.01K 1 0
  8. 2 stat_table kTableEnable 44.12K 44.12K 1 0
  9. - total - 52.14K - 3 0

删除表格: ./teracli drop hello

  1. [tera@localhost bin]$ ./teracli drop hello
  2. [tera@localhost bin]$ ./teracli show
  3. tablename status size lg_size tablet notready
  4. ------------------------------------------------------------------
  5. 0 meta_table kTableEnable 4.01K 4.01K 1 0
  6. 1 stat_table kTableEnable 44.12K 44.12K 1 0
  7. - total - 48.13K - 2 0

写在最后

Tera onebox模式可以体验几乎所有的功能特性,希望通过上面的介绍可以让大家对Tera有一个初步的认识。