hadoop组件---面向列的开源数据库(三)---hbase的接口thrift简介和安装

thrift简介

Thrift server是HBase中的一种服务,主要用于对多语言API的支持。基于Apache Thrift(多语言支持的通信框架)开发,目前有两种版本thrift和thrift2。

thrift2是当时为了适应新的Java API,提出来的。由于种种原因,thrift2没有完美兼容并替代thrift,所有就留下了两个版本。

Thrift 和 Thrift2 的区别

接口设计上Thrift2要比Thrfit更优雅,或者说和现在的API更贴近。比如两者的get接口:

在这里插入图片描述
在这里插入图片描述

Thrift2没有DDL方面的接口,所以现在Hue还是用Thrift的接口。如果你只想读写数据,建议用Thrift2。

Thrift server原理

在这里插入图片描述

Thrfit其实就是个代理,你的请求发到Thrift server上后,server通过Java API再帮你访问HBase。
Thrift实现类是org.apache.hadoop.hbase.thrift.ThriftServer
thrift2的实现类是org.apache.hadoop.hbase.thrift2.ThriftServer
它们访问HBase使用的也是普通的HBase client API,所以当你的请求到达Thrift server后,它通过client API去帮你定位数据,然后读取数据。这么来看,Thrift Server比较灵活,我们可以部署在客户机上,也可以独立部署一个thrift集群。

Thrift server 参数选择

TServer的选择

这是Thrift框架server端处理模型的选择。有三种,TNonblockingServer,THsHaServer,TThreadPoolServer。可以通过启动命令参数指定,具体运行./bin/hbase thrift可以看到命令帮助(or ./bin/hbase thrift2)。默认是用TThreadPoolServer,建议就不用改了,除非你特别了解你的场景。

hbase.regionserver.thrift.compact

是否使用Thrift TCompactProtocol,默认false。如果你每列数据比较大,可以试着开启,减少带宽。

hbase.thrift.connection.cleanup-interval

server清理与HBase连接的周期,与HBase的是一个长连接,默认10秒

hbase.thrift.connection.max-idletime

如果与HBase的长连接超过这个时间没有被使用,则会被清理,默认10分钟

hbase.thrift.minWorkerThreads

TThreadPoolServer的线程池中的corePoolSize,也就是即便空闲时候保持的线程数,默认16。

hbase.thrift.maxWorkerThreads

TThreadPoolServer的线程池中的maximumPoolSize,默认1000。这个会影响server最大处理能力,需要根据硬件衡量。

hbase.thrift.maxQueuedRequests

TThreadPoolServer的线程池队列长度上限,超过这个值时会去创建一个新的线程处理请求(前提是没有达到maxWorkerThreads,否则拒绝请求)

注:上述最后三个值对thrift2无效。1.3之前的版本中,thrift2无法设定这些值。2.0版本中在thrift2启动命令里通过指定’w’选项来设置maxWorkerThreads。具体可以运行上文中提到的命令,查看是否支持’w’选项,如果不支持,默认max=int最大值。

Thrift部署模式

集群模式

在这里插入图片描述

这是最常见的模式,集群模式中的thrift建议不要和RS或者DN混部署。并且如果你使用集群模式的部署方案,你的client端不要去维护长连接。因为如果你维护一个长连接,负载均衡就会失效,如果thrift集群重启,大部分连接会连上第一个起来的thrfit server。

本地模式

在这里插入图片描述

本地模式就是在每个节点上起一个thrift,这个节点独享一个thrift。优点是部署简单,网络开销少。并且这种模式可以使用长连接,自己维护TTransport池。对于持续的写入或者读取,效果要比短连接好很多。HBase IPC本身也是维护一个长连接。缺点是,可靠性略差,如果thrift server挂了的话。但本身如果是多Client,其实也无所谓。

启动和停止thrift

hbase本身已经集成了thrift服务端,使用以下命令开启hbase thrift的服务器端。关闭是将start修改为stop即可。默认情况下监听9090端口。
使用命令

hbase  thrift2 start
hbase  thrift start
hbase  thrift2 stop
hbase  thrift stop

但这种启动方式一把当前窗口关闭则 thirift服务停止,所以一般我们使用后台方式启动

nohup hbase thrift2 start &

检查系统进程
使用命令可以查看ThriftServer是否启动

jps

在这里插入图片描述

配置Thrift端口

端口默认是9090,可以在cdh操作后台中hbase–》配置—》搜索参数hbase.regionserver.thrift.port进行修改。

在这里插入图片描述

也可以在配置文件中修改。
修改hbase-site.xml配置文件中的hbase.thrift.info.port和hbase.regionserver.thrift.port。

第二种方法,启动的时候使用参数指定

hbase  start thrift --infoport 9095 -p 9090

thift客户端安装

thrift官网http://thrift.apache.org/

下载镜像地址选择页面
http://www.apache.org/dyn/closer.cgi?path=/thrift/0.11.0/thrift-0.11.0.tar.gz

安装参考
http://thrift.apache.org/docs/install/

http://thrift.apache.org/docs/install/centos

Thrift的编译器使用C++编写的,在安装编译器之前,首先应该保证操作系统基本环境支持C++的编译,安装相关依赖的软件包,如下所示
使用命令
更新系统环境

sudo yum -y update

更新开发工具

sudo yum -y groupinstall "Development Tools"

更新底层依赖组件

sudo yum install -y wget
cd /usr

更新autoconf

wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
tar xvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure --prefix=/usr
make
sudo make install
cd ..

更新 automake

wget http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
tar xvf automake-1.14.tar.gz
cd automake-1.14
./configure --prefix=/usr
make
sudo make install
cd ..

更新 bison

wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
tar xvf bison-2.5.1.tar.gz
cd bison-2.5.1
./configure --prefix=/usr
make
sudo make install
cd ..

增加lib依赖

sudo yum -y install libevent-devel zlib-devel openssl-devel

更新Boost到1.53

wget http://sourceforge.net/projects/boost/files/boost/1.53.0/boost_1_53_0.tar.gz
tar xvf boost_1_53_0.tar.gz
cd boost_1_53_0
./bootstrap.sh
sudo ./b2 install

安装Thrift

使用命令查看gcc版本

[zzq@host252 thrift-0.10.0]$ gcc --version
gcc (GCC) 4.8.1
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

如果gcc版本比较低建议安装 0.10以下的版本

wget http://apache.fayea.com/thrift/0.10.0/thrift-0.10.0.tar.gz 
tar -xvf thrift-0.10.0.tar.gz 
cd thrift-0.10.0 
sudo ./configure --with-lua=no --with-cpp=no
make && make install

如果gcc版本在 4.9以上才能安装比较新的版本,否则会报错A compiler with support for C++11 language features is required.

git clone https://git-wip-us.apache.org/repos/asf/thrift.git
cd thrift
./bootstrap.sh
./configure --with-lua=no
make
sudo make install

或者

cd /usr/local/
sudo wget  http://mirrors.tuna.tsinghua.edu.cn/apache/thrift/0.11.0/thrift-0.11.0.tar.gz
sudo tar -zvxf  thrift-0.11.0.tar.gz
cd ./thrift-0.11.0
sudo ./configure --prefix=/usr/local/thrift
sudo make && sudo make install

configure时会输出包含的环境路径

在这里插入图片描述

增加到环境变量

export  PATH=$PATH:/usr/local/thrift/bin

加到PATH里
需要注意是要写安装文件的完整路径 …/bin 而不是到thift的根目录
否则提示failed error: /bin/sh: thrift: command not found。

立即生效

source /etc/profile

查看环境变量

env

配置好了thift直接在命令行下输入 thrift就可以看到提示信息,否则直接报找不到。

安装成功校验

[zzq@host252 thrift-0.10.0]$ thrift --version
Thrift version 0.10.0

可能遇到的问题 -Bison版本低

error: Bison version 2.5 or higher must be installed on the system

查看bison版本使用命令

bison --version

在这里插入图片描述
如果是使用sudo执行的话,也需要注意sudo的bison版本

sudo bison --version

在这里插入图片描述

解决方式

cd /usr/local/
sudo wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
sudo tar xvf bison-2.5.1.tar.gz
cd bison-2.5.1
sudo ./configure
sudo make && sudo make install

如果出现sudo --version与 --version版本不一致的情况,则需要进入root角色进行安装
使用命令如下:

sudo -s
cd /usr/local/
wget http://ftp.gnu.org/gnu/bison/bison-2.5.1.tar.gz
tar xvf bison-2.5.1.tar.gz
cd bison-2.5.1
./configure
make
make install

如果在多个路径都有bison路径 注意环境变量 使用命令调整如下:

whereis bison

ls -l /usr/bin/bison

/usr/bin/bison -version

/usr/local/bin/bison --version

sudo mv /usr/bin/bison /usr/bin/bison2.4.1

sudo ln -s /usr/local/bin/bison  /usr/bin/bison

可能遇到的问题–gcc版本过低

报错如下:

configure: error: *** A compiler with support for C++11 language features is required.

原因

是因为编译器版本不支持c++11,所以需要安装高版本gcc编译器以支持c++11,下面采用编译源码方式安装。
在编译安装高版本gcc编译器时,碰到“gcc configure: error: Building GCC requires GMP 4.2+, MPFR 2.3.1+ and MPC 0.8.0”,所以索性把所有依赖重新安装一遍。

解决方式

预装环境

$ yum install -y gcc gcc-c++

把源码包上传到/usr/local/software目录

gcc 4.9.4 源码包下载
链接:https://pan.baidu.com/s/1AuS6e7bgKSWj9phVxpDn3A
提取码:8yfl

安装gmp

$ cd /usr/local/software
$ tar -zxvf gmp-5.0.2.tar.gz 
$ cd gmp-5.0.2
$ ./configure --prefix=/usr/local/ && make && make install && echo "sayok "

安装mpfr

$ cd ..
$ tar -zxvf mpfr-3.1.2.tar.gz 
$ cd mpfr-3.1.2
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ && make && make install && echo "say ok"

安装mpc

$ cd ..
$ tar -zxvf mpc-0.9.tar.gz 
$ cd mpc-0.9
$ ./configure --prefix=/usr/local/ --with-gmp=/usr/local/ --with-mpfr=/usr/local/ && make && make install && echo "say ok"

安装gcc

$ cd ..
$ tar -zxvf gcc-4.9.4.tar.gz
$ cd gcc-4.9.4
$ ./configure --prefix=/usr/local/gcc-4.9.4 --enable-threads=posix --disable-checking --disable-multilib --enable-languages=c,c++ --with-gmp=/usr/local --with-mpfr=/usr/local --with-mpc=/usr/local
$ make && make install && echo "say ok"

编译安装过程一个多小时
卸载旧版本编译器

$ yum remove gcc gcc-c++
$ ln -s /usr/local/gcc-4.9.4/bin/c++ /usr/bin/c++
$ ln -s /usr/local/gcc-4.9.4/bin/g++ /usr/bin/g++
$ ln -s /usr/local/gcc-4.9.4/bin/gcc /usr/bin/gcc

添加环境变量,修改profile文件,在最末添加如下两句

$ vim /etc/profile
LD_LIBRARY_PATH=/usr/local/gcc-4.9.4/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH
$ source /etc/profile

更多参考资料
https://github.com/ZhijiaYang/HbaseHelper
https://wiki.apache.org/hadoop/Hbase/ThriftApi

发布了805 篇原创文章 · 获赞 897 · 访问量 524万+

猜你喜欢

转载自blog.csdn.net/q383965374/article/details/102747725
今日推荐