Kudu 部署指南与 Kudu Python 客户端使用

kudu

1. kudu 部署指南(centos)

1. 安装 lsb 依赖

先安装 lsb 依赖:sudo rpm redhat-lsb

2. 安装 kudu

推荐手动安装,因为 cloudera 的源非常不稳定,在 kudu 下载页面 下载以下四个安装包:

1
2
3
4
5
6
7
8
9
10
kudu-client0-1.4.0+cdh5.12.2+0-1.cdh5.12.2.p0.8.el6.x86_64.rpm


kudu-client-devel-1.4.0+cdh5.12.2+0-1.cdh5.12.2.p0.8.el6.x86_64.rpm


kudu-master-1.4.0+cdh5.12.2+0-1.cdh5.12.2.p0.8.el6.x86_64.rpm


kudu-1.4.0+cdh5.12.2+0-1.cdh5.12.2.p0.8.el6.x86_64.rpm

在集群中的一台机器安装 master 和 t-server,其余只安装 t-server。

3. 创建 kudu 文件夹

根据空间考虑 kudu 位置:sudo mkdir -p /data8/kudu && sudo chown kudu:kudu /data8/kudu

4. 配置文件设置

master 和 server 的配置文件设置。

master 设置

1
2
3
--fs_wal_dir=/data8/kudu/master
--fs_data_dirs=/data8/kudu/master
--default_num_replicas=1

t-server 设置

1
2
3
4
5
--fs_wal_dir=/data8/kudu/tserver
--fs_data_dirs=/data8/kudu/tserver

--tserver_master_addrs=xxx.xxx.xxx.xxx:7051
--default_num_replicas=1

5. 启动 kudu

1
2
sudo service kudu-master start
sudo service kudu-tserver start

6. 安装 kudu-python 模块

一定要确保 pip 是最新版本!!!,并且 Cython 已经安装好,安装 kudu-python 的 1.2.0 版本。

1
2
3
sudo pip install --upgrade pip
sudo pip install -i https://pypi.douban.com/simple Cython
sudo pip install -i https://pypi.douban.com/simple kudu-python==1.2.0

7. kudu 部署参考资料

  1. http://kudu.apache.org/docs/installation.html#install_packages
  2. http://www.cnblogs.com/zlslch/p/7607700.html
  3. kudu python 使用教程(最新)
  4. kudu python 教程
  5. 程序园:Kudu Configuration Reference
  6. hadoop生态圈列式存储系统—kudu介绍及安装配置
  7. Install kudu on Ubuntu

2. kudu 的 Python 客户端使用

在 Python 下连接使用 Kudu 的方法少得可怜,并且也并非官方宣传的那般快速。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import kudu
from kudu.client import Partitioning
from datetime import datetime

# Connect to Kudu master server
# 连接 kudu master 服务
client = kudu.connect(host='kudu.master', port=7051)

# Define a schema for a new table
# 为表定义一个模式
builder = kudu.schema_builder()
builder.add_column('key').type(kudu.int64).nullable(False).primary_key()
builder.add_column('ts_val', type_=kudu.unixtime_micros, nullable=False, compression='lz4')
schema = builder.build()

# Define partitioning schema
partitioning = Partitioning().add_hash_partitions(column_names=['key'], num_buckets=3)

# Create new table
client.create_table('python-example', schema, partitioning)

# Open a table
table = client.table('python-example')

# Create a new session so that we can apply write operations
session = client.new_session()

# Insert a row
# 往表里面插入一行数据
op = table.new_insert({'key': 1, 'ts_val': datetime.utcnow()})
session.apply(op)

# Upsert a row
op = table.new_upsert({'key': 2, 'ts_val': "2016-01-01T00:00:00.000000"})
session.apply(op)

# Updating a row
op = table.new_update({'key': 1, 'ts_val': ("2017-01-01", "%Y-%m-%d")})
session.apply(op)

# Delete a row
op = table.new_delete({'key': 2})
session.apply(op)

# Flush write operations, if failures occur, capture print them.
try:
session.flush()
except kudu.KuduBadStatus as e:
print(session.get_pending_errors())

# Create a scanner and add a predicate
# 先创建一个 scanner,然后再读取表中的数据
# 表中的数据太多,你还需要添加一个所谓的 predicate 只读取规定区间内的数据
scanner = table.scanner()
scanner.add_predicate(table['ts_val'] == datetime(2017, 1, 1))

# Open Scanner and read all tuples
# Note: This doesn't scale for large scans
result = scanner.open().read_all_tuples()

参考资源

  1. python中使用kudu:https://kudu.apache.org/docs/developing.html#_kudu_python_client
    理解kudu与impala之间的联系:https://blog.csdn.net/cdxxx5708/article/details/79074489
  2. kudu踩坑:https://www.2cto.com/kf/201707/653572.html
  3. https://blog.cloudera.com/blog/2016/01/interactive-analytics-on-dynamic-big-data-in-python-using-kudu-impala-and-ibis/
------本文结束,欢迎收藏本站、分享、评论或联系作者!------
点击查看
赠人玫瑰 手有余香
0%