Hello,
Well after a long time this is my in length article, the reason I am writing is because of all the stuff I have been gone through building thrift and cassandra-pdo on centOS 6.5
Versions
I will be writing about installing latest version of thrift that at time of writing and RnD was 0.9.1, CentOS is version 6.5 64 bit, php 5.3.3, Apache/2.2.15, Cassandra is at version 2.06 which is most stable version for production at the time of writing.
Prerequisite
Most of the commands will need elevated privileges. You should prefix sudo with every command, I am doing it on test VM so doing it as privileged user root
Packages wget, nano are available if not then yum install them as shown below. Of course if you use vi or other util other than wget to download files then skip this
1 |
yum install wget nano |
Ok so lets get started.
When I started building thrift, or cassandra pdo I was getting all sort of errors such as
1 2 3 4 5 |
./configure: line 16498: syntax error near unexpected token `QT,' ./configure: line 16498: ` PKG_CHECK_MODULES(QT, QtCore >= 4.3, QtNetwork >= 4.3, have_qt=yes, have_qt=no)' ---- YACassandraPDO unable to find thrift installation |
Install Cassandra
Installing cassandra is the simplest one, We will be installing it from rpm provided by datastax
Open datastax.repo for editing with following command
1 |
nano /etc/yum.repos.d/datastax.repo |
paste following content in editor
1 2 3 4 5 6 |
[datastax] name= DataStax Repo for Apache Cassandra baseurl=http://rpm.datastax.com/community enabled=1 gpgcheck=0 |
Install cassandra
1 |
yum install cassandra20 |
Above command will also install openJDK but cassandra guys recommend that we should use latest java from Oracle so lets do that now
Get into opt directory You can actually choose to be any other directory of your liking
1 |
cd /opt/ |
Get RPM path for latest jre from http://www.oracle.com/technetwork/java/javase/downloads/index.html I am using jre 8 from http://www.oracle.com/technetwork/java/javase/downloads/jre8-downloads-2133155.html
1 2 3 4 5 |
wget "PATH TO RPM" yum install jre-8-linux-x64.rpm # get system to use latest java alternatives --install /usr/bin/java java /usr/java/latest/bin/java 200000 alternatives --install /usr/bin/javaws javaws /usr/java/latest/bin/javaws 200000 |
output of java –version would be something like
1 2 3 4 |
$ java -version java version "1.8.0" Java(TM) SE Runtime Environment (build 1.8.0-b132) Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode) |
Lets now install Development tools
1 |
yum groupinstall "Development tools" |
Lets now install all pre-requisites to install thrift without issues
1 |
yum install automake libtool flex bison pkgconfig gcc-c++ boost-devel libevent-devel zlib-devel python-devel ruby-devel php-devel openssl openssl-devel pcre-devel |
Before you proceed you would need autoconf version of atleast 2.65 but we will install latest version of it anyway
1 2 3 4 5 6 7 8 9 |
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz tar xvf autoconf-2.69.tar.gz cd autoconf-2.69 ./configure make make install cd .. rm -rf autoconf-2.69 rm -rf autoconf-2.69.tar.gz |
Build and install apache thrift
Now lets get thrift source from Github as shown below and we will install it too
1 2 3 4 5 6 7 8 9 10 11 12 13 |
wget https://github.com/apache/thrift/archive/0.9.1.zip unzip 0.9.1.zip cd thrift-0.9.1/ ./bootstrap.sh ./configure --help ## PLEASE NOTE THAT i AM BUILDING THRIFT FOR PHP SO I DON'T NEED JAVA, CSHARP AND PYTHON ./configure --with-boost=/usr/lib64/ --without-java --without-mono --without-python make make install whereis thrift ln -s /usr/local/bin/thrift /usr/bin/thrift cd .. rm 0.9.1.zip |
Ok if you don’t see any error at this step we are doing very well and we can proceed with getting and installing YACassandraPDO from github as shown below.
1 2 3 4 5 6 7 8 |
wget https://github.com/Orange-OpenSource/YACassandraPDO/archive/master.zip unzip master.zip cd YACassandraPDO-master/ phpize ./configure make make test make install |
Still no error, awesome, lets proceed with including our compiled package with PHP.
1 |
nano /etc/php.d/pdo_cassandra.ini |
add this line to pdo_cassandra.ini
1 |
extension=pdo_cassandra.so |
Restart Apache
1 |
service httpd restart |
Start Cassandra service
1 |
service cassandra start |
Now you are free to query your cassandra nodes as shown below
1 2 |
$db_handle = new PDO("cassandra:host=192.168.0.74;port=9160;cqlversion=3.0.0", $username, $password); ## replace IP addresses with your own, also make sure that port 9160 is open if you are connecting cross data centers |
More info on connections and queries can be found here
https://github.com/Orange-OpenSource/YACassandraPDO/wiki
Also note that CQL3 is kinda supported with this php PDO driver. if you get php pdo is not found exception while connecting to a cassandra node make sure you have php-pdo installed
1 |
$ yum install php-pdo |
Of course you can leave your comment and possibly someone would be able to help if not me. I look forward to get any feedback or above instructions can be improved. I will make requested edits.
Trying something new isn’t easy sometimes but when it works its a nice feeling…
I hope this article helps you or atleast give you some pointers.
Regards.
We have a project that needs designing that uses speach recognition, can you help?
I would’ve have loved to but I am pretty much taken for next several months. Thanks for the offer though.
Regards,
Jas