Tarantool安装及基本使用
1.前言
Features
- A drop-in replacement for Lua 5.1, based on LuaJIT 2.1;
simply use #!/usr/bin/tarantool instead of #!/usr/bin/lua in your script - Lua packages for non-blocking I/O, fibers and HTTP
- MessagePack data format and MessagePack based client-server protocol
- a built-in database with two data engines: 100% in-memory with optional persistence and a 2-level disk-based B-tree, to use with large data sets
- secondary key and index iterators support
- asynchronous master-master replication
- authentication and access contro
- 上述是引用官方的介绍,总的来说Tarantool是一个高性能的key/value存储服务器
- http://tarantool.org/ 官网地址
下面开始Tarantool之旅
2.环境准备
- CentOS 6.5 虚机一台
3.开始安装
添加yum源在 /etc/yum.repos.d/ 下创建文件 tarantool.repo并写入以下内容
[tarantool] name=CentOS-$releasever - Tarantool baseurl=http://tarantool.org/dist/master/centos/$releasever/os/$basearch/ enabled=1 gpgcheck=0
执行yum安装命令
sudo yum install tarantool.
待命令执行完毕Tarantool就安装完毕了。
4.启动运行Tarantool
创建数据库工作目录如:
mkdir ~/swq_tarantool_box cd ~/swq_tarantool_box
启动Tarantool
/usr/bin/tarantool /usr/bin/tarantool: version 1.6.7-463-gfc14541 type 'help' for interactive help
到目前为止我们已近启动起来了tarantool,tarantool与redis或者其他可能不一样,他是没有配置文件的,现在我们只是进入到了tarantool的交互环境而已,下一步我们将启动数据库
配置Tarantool
box.cfg{listen=3301,log_level=5, logger='tarantool.txt'}
执行上述命令后我们已经启动起来了Tarantool,3301为监听端口,日志等级为5info级别,输出文件为当前目录下载的tarantool.txt。下面我们看下日志文件的内容。
注:日志文件每次是增量append的。2016-01-26 17:33:01.573 [6381] main/101/interactive I> mapping 1073741824 bytes for tuple arena... 2016-01-26 17:33:01.575 [6381] main/101/interactive I> recovery start 2016-01-26 17:33:01.575 [6381] main/101/interactive I> recovering from `./00000000000000000000.snap' 2016-01-26 17:33:01.579 [6381] main/101/interactive I> recover from `./00000000000000000000.xlog' 2016-01-26 17:33:01.580 [6381] main/101/interactive recovery.cc:211 W> file `./00000000000000000000.xlog` wasn't correctly closed 2016-01-26 17:33:01.580 [6381] main/101/interactive I> recover from `./00000000000000000112.xlog' 2016-01-26 17:33:01.813 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:02.052 [6381] main/101/interactive I> 0.2M rows processed 2016-01-26 17:33:02.251 [6381] main/101/interactive I> 0.3M rows processed 2016-01-26 17:33:02.567 [6381] main/101/interactive I> 0.4M rows processed 2016-01-26 17:33:02.841 [6381] main/101/interactive I> 0.5M rows processed 2016-01-26 17:33:02.841 [6381] main/101/interactive I> done `./00000000000000000112.xlog' 2016-01-26 17:33:02.841 [6381] main/101/interactive I> recover from `./00000000000000500112.xlog' 2016-01-26 17:33:03.126 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:03.369 [6381] main/101/interactive I> 0.2M rows processed 2016-01-26 17:33:03.600 [6381] main/101/interactive I> 0.3M rows processed 2016-01-26 17:33:03.836 [6381] main/101/interactive I> 0.4M rows processed 2016-01-26 17:33:04.153 [6381] main/101/interactive I> 0.5M rows processed 2016-01-26 17:33:04.153 [6381] main/101/interactive I> done `./00000000000000500112.xlog' 2016-01-26 17:33:04.153 [6381] main/101/interactive I> recover from `./00000000000001000112.xlog' 2016-01-26 17:33:04.357 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:04.388 [6381] main/101/interactive I> done `./00000000000001000112.xlog' 2016-01-26 17:33:04.388 [6381] main/101/interactive I> recover from `./00000000000001110148.xlog' 2016-01-26 17:33:04.606 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:04.795 [6381] main/101/interactive I> 0.2M rows processed 2016-01-26 17:33:04.967 [6381] main/101/interactive I> 0.3M rows processed 2016-01-26 17:33:05.158 [6381] main/101/interactive I> 0.4M rows processed 2016-01-26 17:33:05.314 [6381] main/101/interactive I> 0.5M rows processed 2016-01-26 17:33:05.315 [6381] main/101/interactive I> done `./00000000000001110148.xlog' 2016-01-26 17:33:05.315 [6381] main/101/interactive I> recover from `./00000000000001610148.xlog' 2016-01-26 17:33:05.495 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:05.698 [6381] main/101/interactive I> 0.2M rows processed 2016-01-26 17:33:05.883 [6381] main/101/interactive I> 0.3M rows processed 2016-01-26 17:33:06.062 [6381] main/101/interactive I> 0.4M rows processed 2016-01-26 17:33:06.252 [6381] main/101/interactive I> 0.5M rows processed 2016-01-26 17:33:06.252 [6381] main/101/interactive I> done `./00000000000001610148.xlog' 2016-01-26 17:33:06.252 [6381] main/101/interactive I> recover from `./00000000000002110148.xlog' 2016-01-26 17:33:06.420 [6381] main/101/interactive I> 0.1M rows processed 2016-01-26 17:33:06.439 [6381] main/101/interactive recovery.cc:211 W> file `./00000000000002110148.xlog` wasn't correctly closed 2016-01-26 17:33:06.439 [6381] main/102/hot_standby I> recover from `./00000000000002110148.xlog' 2016-01-26 17:33:06.497 [6381] main/102/hot_standby I> 0.1M rows processed 2016-01-26 17:33:06.505 [6381] iproto I> binary: started 2016-01-26 17:33:06.506 [6381] iproto I> binary: bound to 0.0.0.0:3301 2016-01-26 17:33:06.506 [6381] main/101/interactive recovery.cc:211 W> file `./00000000000002110148.xlog` wasn't correctly closed 2016-01-26 17:33:06.509 [6381] main/101/interactive I> ready to accept requests
可从上述日志看到tarantool从下述文件进行了数据恢复
注:类似redis的持久文件恢复,但是这些只是Tarantool的操作变动日志,并不是磁盘的持久化数据./00000000000000000000.snap ./00000000000000000112.xlog ./00000000000000500112.xlog ./00000000000001000112.xlog ./00000000000001110148.xlog ./00000000000001610148.xlog ./00000000000002110148.xlog
上述文件保存当前目录下tarantool的所有数据信息,如space,索引,每个space的记录等等,这些文件是我测试遗留下的。这里稍微扩展下:一个Tarantool可对应多个space,每个space有两种数据存储引擎可选,分别是memtx和sophia其实就是内存与磁盘,然后每个space下对应了具体的kv值了。使用过Redis的肯定知道space有点像redis的db概念,又对应了关系数据库的表概念,总之上手理解很快。具体相关信息大家可以查看官方文档。
5.Tarantool基本命令使用
创建空间
s = box.schema.space.create('swq_test') 注:s为引用别名
创建主键
i = s:create_index('primary', {type = 'hash', parts = {1, 'NUM'}})
insert
s:insert{123} s:insert{456,123123} s:insert{789,123123,'hello tarantool'}
select
s:select{}
delete
s:delete{123}
此篇到此结束,具体详细的使用及更多特性参看官网。