Main Reference https://thrift.apache.org/docs/install/centos
sudo yum install -y autoconf automake libtool flex bison pkgconfig
sudo yum -y groupinstall "Development Tools"
sudo yum install -y wget
Build and Install the Apache Thrift IDL Compiler
git clone https://git-wip-us.apache.org/repos/asf/thrift.git cd thrift ./bootstrap.sh ./configure --with-lua=no
Python 2
Configure Thrift
./configure --with-lua=noBy default only Python available on Linux CentOS 7.2 after ./configure
thrift 1.0.0-dev
Building Plugin Support ...... : no
Building C++ Library ......... : no
Building C (GLib) Library .... : no
Building Java Library ........ : no
Building C# Library .......... : no
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no
Make and Install Thrift
echo "note: make takes 10 minutes to complete" make sudo make install
This will build the compiler (thrift/compiler/cpp/thrift --version) and any language libraries supported. The make install step installs the compiler on the path: /usr/local/bin/thrift You can use the ./configure --enable-libs=no switch to build the Apache Thrift IDL Compiler only without lib builds. To run tests use "make check".
[ricky@thrift2 thrift]$ thrift --version
Thrift version 1.0.0-dev
Using CentOS 7.2 default python 2.7.5 to run the Thrift server.py
[ricky@thrift2 cal]$ python --version
Python 2.7.5
[ricky@thrift2 cal]$ python server.py
Traceback (most recent call last):
File "server.py", line 6, in <module>
from thrift.protocol import TBinaryProtocol
File "/usr/lib/python2.7/site-packages/thrift/protocol/TBinaryProtocol.py", line 20, in <module>
from .TProtocol import TType, TProtocolBase, TProtocolException
File "/usr/lib/python2.7/site-packages/thrift/protocol/TProtocol.py", line 24, in <module>
import six
ImportError: No module named six
[ricky@thrift2 cal]$ sudo yum install -y python-six
[ricky@thrift2 cal]$ python server.py
running...
Python 3 (No Solution yet on 12/21/2016 found!)
Install Anaconda 3
wget https://repo.continuum.io/archive/Anaconda3-4.2.0-Linux-x86_64.sh
chomd +x Anaconda3-4.2.0-Linux-x86_64.sh
./Anaconda3-4.2.0-Linux-x86_64.sh
[ricky@thrift2 ~]$ python --version
Python 3.5.2 :: Anaconda 4.2.0 (64-bit)
Error 1: ImportError: No module named 'thrift'
[ricky@thrift2 cal]$ python server.py
Traceback (most recent call last):
File "server.py", line 4, in <module>
from thrift.transport import TSocket
ImportError: No module named 'thrift'
So, you must use pip to install thrift (only works for Windows but not Linux)
pip install --upgrade pip
pip install thrift
Error 2: ImportError: cannot import name 'TFrozenDict'
[ricky@thrift2 cal]$ python server.py
Traceback (most recent call last):
File "server.py", line 8, in <module>
from cal import sumservice
File "./gen-py/cal/sumservice.py", line 9, in <module>
from thrift.Thrift import TType, TMessageType, TFrozenDict, TException, TApplicationException
ImportError: cannot import name 'TFrozenDict'
No Solution yet on 12/21/2016 found! Now for me I can only use Python 2 with Thrift, but not Python 3.
JAVA
Installing Java 8 by RPM and ant
wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u111-b14/jdk-8u111-linux-x64.rpm
sudo rpm -ivh jdk-8u111-linux-x64.rpm
sudo yum install -y ant
Check JDK Version
[ricky@thrift2 ~]$ java -version
java version "1.8.0_111"
Java(TM) SE Runtime Environment (build 1.8.0_111-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.111-b14, mixed mode)
[ricky@thrift2 thrift]$ javac -version
javac 1.8.0_111
Configure Thrift
./configure --with-lua=no
thrift 1.0.0-dev
Building Plugin Support ...... : no
Building C++ Library ......... : no
Building C (GLib) Library .... : no
Building Java Library ........ : yes
Building C# Library .......... : no
Building Python Library ...... : yes
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Dart Library ........ : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no
Java Library:
Using javac ............... : javac
Using java ................ : java
Using ant ................. : /usr/bin/ant
Make and Install Thrift
echo "note: make takes 10 minutes to complete" make sudo make install
Add Optional C++ Language Library Dependencies
Install C++ Lib Dependencies
sudo yum -y install gcc-c++ libevent-devel zlib-devel openssl-devel
Upgrade 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
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的安装和简单示例
http://blog.csdn.net/anonymalias/article/details/26154405
g++ -o server server_types.cpp server_constants.cpp serDemo.cpp serDemo_server.skeleton.cpp -lthrift
g++ -o client server_types.cpp server_constants.cpp serDemo.cpp client.cpp -lthrift
// client has no no serDemo_server.skeleton.cpp
error while loading shared libraries: libthrift-1.0.0-dev.so: cannot open shared object file: No such file or directory
Then add below to ~/.bash_profile
export LD_LIBRARY_PATH=/usr/local/lib/:${LD_LIBRARY_PATH}thrift 0.9.3 on Centos 7.2
yum install boost-devel
cd /root/test/thrift/thrift-0.9.3
./configure
if configure: error: "Error: libcrypto required."
yum install openssl-devel
Download the thrift.tar
tar zxvf thrift.tar
./configure
Then you will see
Building C++ Library ......... : yes
Building C (GLib) Library .... : no
Building Java Library ........ : no
Building C# Library .......... : no
Building Python Library ...... : no
Building Ruby Library ........ : no
Building Haxe Library ........ : no
Building Haskell Library ..... : no
Building Perl Library ........ : no
Building PHP Library ......... : no
Building Erlang Library ...... : no
Building Go Library .......... : no
Building D Library ........... : no
Building NodeJS Library ...... : no
Building Lua Library ......... : no
C++ Library:
Build TZlibTransport ...... : yes
Build TNonblockingServer .. : no
Build TQTcpServer (Qt4) .... : no
Build TQTcpServer (Qt5) .... : no
沒有留言:
張貼留言