This is a patch for happybase to support kerberos when connect to hbase thrift server with the following extra features:
KerberosConnectionPool
support multiple specify multiple hosts as destination to connection as a support to high avaliableKerberosConnectionPool
will auto connect to the next host if current is unavailable even in the outermost with statement- Using
pykerberos
instead ofkerberos
which has memory leaking issue
The patch now support python 2.7
, python 3.5
, python 3.6
, python 3.7
.
The project is base on happybase https://github.com/python-happybase/happybase
In order to use kerberos, the following packages is required:
- python-devel or python3-devel (depend on which you use)
- krb5-lib5
- krb-workstation
For example, in redhat install by the follow commands:
yum install python-devel
yum -y install krb5-libs krb5-workstation
For example, in ubuntu install by the follow commands:
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libkrb5-dev
In China for higher installation speed could use "-i https://pypi.tuna.tsinghua.edu.cn/simple"
pip install -U git+https://github.com/littlebear-xbz/happybase-kerberos-patch.git -i https://pypi.tuna.tsinghua.edu.cn/simple
from happybase_kerberos_patch import KerberosConnection, KerberosConnectionPool
connection = KerberosConnection('HOST_TO_THRIFT_SERVER', protocol='compact', use_kerberos=True)
test_table = connection.table('test')
# insert
test_table.put('row_key_1', {'f1:q1':'v1'})
# get data
print test_table.row('row_key_1')
pool = KerberosConnectionPool(size=3, host='...', protocol='compact', use_kerberos=True)
with pool.connection() as connection:
test = connection.table('test')
print test_table.row('row_key_1')
# multiple thrift servers high avaliable
pool = KerberosConnectionPool(size=3, hosts=['thrift1', 'thrift2'], protocol='compact', use_kerberos=True)
with pool.connection() as connection:
test = connection.table('test')
print test_table.row('row_key_1')
- Only support "compact" protocol and "buffered" transport
- Only support happybase>=1.2.0