Thrift安装部署

下载源码包

wget http://apache.fayea.com/thrift/0.9.3/thrift-0.9.3.tar.gz

安装g++

centos:yum install gcc gcc-c++

如果没有安装g++,无法编译

解压Thrift安装包

tar -xvf thrift-0.9.3.tar.gz

安装boost开发工具

  1. 进入thrift-0.9.3目录

  2. 运行命令:yum install boost-devel.x86_64

  3. 运行命令:yum install boost-devel-static

  4. 运行命令:./configure --with-cpp --with-boost --with-python --without-csharp --with-java --without-erlang --without-perl --with-php --without-php_extension --without-ruby --without-haskell --without-go

  5. 编译,命令:make

  6. 编译完成之后安装,命令:make install

  7. 出现thrift命令提示表示Thrift安装成功

测试(python版)

  1. 创建RecSys.thrift文件
service RecSys {
string rec_data(1:string data)
}
  1. 创建server.py文件
#! /usr/bin/env python
# -*- coding: utf-8 -*- import sys
sys.path.append('gen-py') from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
from thrift.server import TServer from RecSys import RecSys
from RecSys.ttypes import * class RecSysHandler(RecSys.Iface):
def rec_data(self, a):
print "Receive: %s" %(a)
return "ok" if __name__ == "__main__": # 实例化handler
handler = RecSysHandler() # 设置processor
processor = RecSys.Processor(handler) # 设置端口
transport = TSocket.TServerSocket('localhost', port=9900) # 设置传输层
tfactory = TTransport.TBufferedTransportFactory() # 设置传输协议
pfactory = TBinaryProtocol.TBinaryProtocolFactory() server = TServer.TThreadedServer(processor, transport, tfactory, pfactory) print 'Starting the server...'
server.serve()
print 'done'
  1. 创建client.py文件
#! /usr/bin/env python
# -*- coding: utf-8 -*- import sys
sys.path.append("gen-py") // 将第4步骤产生的目录加载进来 from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol from RecSys import RecSys
# from demo.ttypes import * try:
# Make Socket
# 建立socket, IP 和port要写对
transport = TSocket.TSocket('localhost', 9900) # Buffering is critical. Raw sockets are very slow
# 选择传输层,这块要和服务器的设置一样
transport = TTransport.TBufferedTransport(transport) # Wrap in a protocol
# 选择传输协议,这个也要和服务器保持一致,负责无法通信
protocol = TBinaryProtocol.TBinaryProtocol(transport) client = RecSys.Client(protocol) # Connect!
transport.open() # Call server services
rst = client.rec_data("are you ok!")
print rst # close transport
transport.close()
except Thrift.TException, ex:
print "%s" % (ex.message)
  1. 运行命令:thrift --gen py RecSys.thrift

    • 运行完之后会在当前目录生成一个gen-py的文件夹,里面有模块的名字之类的东西

    • 运行命令:python server.py,启动服务端

    • 运行命令:python client.py,启动客户端,并能收到服务端发出的信息

【Thrift一】Thrift安装部署的更多相关文章

  1. rpc框架之 thrift 学习 1 - 安装 及 hello world

    thrift是一个facebook开源的高效RPC框架,其主要特点是跨语言及二进制高效传输(当然,除了二进制,也支持json等常用序列化机制),官网地址:http://thrift.apache.or ...

  2. thrift C++ Centos 安装

    1.在官方下载thrift http://thrift.apache.org/download 这里下载thrift-0.11.0.tar.gz版本 2.如果想支持安装Cpp版本就需要先安装boost ...

  3. thrift多平台安装

    thrift支持多语言的RPC,一直都想深入学习了解thrift,最近有空,就上网查了些资料,学习了一下,对它的使用有了一些了解.本篇是写thrift的安装,使用方法会另起一篇来写. 本文使用thri ...

  4. CentOS下SparkR安装部署:hadoop2.7.3+spark2.0.0+scale2.11.8+hive2.1.0

    注:之前本人写了一篇SparkR的安装部署文章:SparkR安装部署及数据分析实例,当时SparkR项目还没正式入主Spark,需要自己下载SparkR安装包,但现在spark已经支持R接口,so更新 ...

  5. 日志采集框架Flume以及Flume的安装部署(一个分布式、可靠、和高可用的海量日志采集、聚合和传输的系统)

    Flume支持众多的source和sink类型,详细手册可参考官方文档,更多source和sink组件 http://flume.apache.org/FlumeUserGuide.html Flum ...

  6. PRESTO安装部署和参数说明(一)

    PRESTO部署和参数说明(一) 一,概要 在部署和使用presto的过程中,在此记录一下部署记录和使用记录以及需要注意的事项.本人使用的presto版本是0.214,3台redhat虚拟机.使用背景 ...

  7. Akka-CQRS(2)- 安装部署cassandra cluster,ubuntu-16.04.1-LTS and MacOS mojave

    对于akka-cluster这样的分布式软件系统来说,选择配套的数据库类型也是比较讲究的,最好也是分布式的,如cassandra,能保证良好的HA特性.前面的例子里示范akka-persistence ...

  8. 一、tars简单介绍 二、tars 安装部署资料准备

    1.github地址https://github.com/Tencent/Tars/ 2.tars是RPC开发框架,目前支持c++,java,nodejs,php 3.tars 在腾讯内部已经使用了快 ...

  9. Hive基础概念、安装部署与基本使用

    1. Hive简介 1.1 什么是Hive Hives是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供类SQL查询功能. 1.2 为什么使用Hive ① 直接使用 ...

随机推荐

  1. 搭建 Spring 2.5.6 开发环境

    1.jar 包准备: spring 2.5.6 的 jar 包(链接: http://pan.baidu.com/s/1skVFfcx 密码: mbiz),如图: commons-logging-1. ...

  2. VS中bin,app_code,app_data,app_browser,app_GlobalResources等文件夹的作用 .

    1.  Bin文件夹 Bin文件夹包含应用程序所需的,用于控件.组件或者需要引用的任何其他代码的可部署程序集.该目录中存在的任何.dll文件将自动地链接到应用程序.如果在该文件夹中留有不用的或过期的文 ...

  3. vscode 显示"没有活动的源代码控制提供程序“处理

    不知为何我的 VS Code 在 1.25 版本开始就一直 ”没有活动的源代码控制提供程序“,找了好几天都没找到,今天终于找到怎么处理了, 切换到插件中找到下图对应的 Git (可以直接再上面搜索框输 ...

  4. python学习笔记(1)----python安装

    1.下载Python for windows 废话不说,直接上网址:https://www.python.org/ftp/python/3.5.1/python-3.5.1.exe 2.安装Pytho ...

  5. 简单记录一下http请求的7个步骤

    1.建立TCP连接 2.客户端发送请求命令 3.客户端发送请求头信息 4.服务端应答请求,返回版本号和状态码 5.服务端应答头信息 6.服务端向客户端发送数据 7.服务器关闭TCP连接(Connect ...

  6. 2.Zabbix 3.0 部署

    请查看我的有道云笔记地址: http://note.youdao.com/noteshare?id=0db90549f9f347faf928b781087b28c9&sub=AAA6CE2FA ...

  7. vue 单页应用中微信支付的坑

    vue 单页应用中微信支付的坑 标签(空格分隔): 微信 支付 坑 vue 场景 在微信H5页面(使用 vue-router2 控制路由的 vue2 单页应用项目)中使用微信 jssdk 进行微信支付 ...

  8. Jmeter入门19 保存测试结果(或从文件读取结果)

    以聚合报告为例,其他监听器有write results to file的类似. 首先 为了避免每次保存的测试报告被覆盖,我们在testplan下添加两个参数:项目名和当前时间(毫秒级) 其次 添加聚合 ...

  9. Android(java)学习笔记56:Android InputMethodManager输入法简介

    参见博客: http://blog.csdn.net/pi9nc/article/details/9196779

  10. 【翻译】苹果官网的命名规范之 Code Naming Basics-General Principles

    苹果官方原文链接:General Principles 代码命名基本原则:通用规范   代码含义清晰 尽可能将代码写的简洁并且明白是最好的,不过代码清晰度不应该因为过度的简洁而受到影响.例如: 代码 ...