Apache Cassandra is a NoSQL database intended for storing large amounts of data in a decentralized, highly available cluster. NoSQL refers to a database with a data model other than the tabular relations used in relational databases such as MySQL, PostgreSQL, and Microsoft SQL.
Pre-requisite
Stable version of Oracle/Sun Java 7 or higher version installed . Check to see if your server already has Java installed by running the following command:
java -version
1. Add the DataStax Community Repository
Add datastax Cassandra repo to install Apache Cassandra ( DataStax community edition)
vim /etc/yum.repos.d/datastax.repo
Add the following information to the file you’ve created, using i to insert:
[datastax]
name = DataStax Repo for Apache Cassandra
baseurl = http://rpm.datastax.com/community
enabled = 1
gpgcheck = 0
Then exit and save the file with the command :wq
2. Install Apache Cassandra 2
Installing Cassandra is as simple as running just one command:
yum -y install dsc20
Output
You should see something similar to following
[root@ranjeet ~]# yum -y install dsc20
Loaded plugins: fastestmirror
Determining fastest mirrors
epel/metalink | 4.3 kB 00:00
* base: centosmirror.go4hosting.in
* epel: ftp.riken.jp
* extras: centosmirror.go4hosting.in
* updates: centosmirror.go4hosting.in
base | 3.7 kB 00:00
datastax | 2.5 kB 00:00
datastax/primary_db | 130 kB 00:01
epel | 4.3 kB 00:00
epel/primary_db | 5.9 MB 00:04
extras | 3.4 kB 00:00
extras/primary_db | 37 kB 00:00
mongodb-org-3.2 | 2.5 kB 00:00
mongodb-org-3.2/primary_db | 45 kB 00:00
updates | 3.4 kB 00:00
updates/primary_db | 2.0 MB 00:01
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package dsc20.noarch 0:2.0.17-1 will be installed
--> Processing Dependency: cassandra20 = 2.0.17 for package: dsc20-2.0.17-1.noarch
--> Running transaction check
---> Package cassandra20.noarch 0:2.0.17-1 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
==============================================================================================================================
Package Arch Version Repository Size
==============================================================================================================================
Installing:
dsc20 noarch 2.0.17-1 datastax 1.9 k
Installing for dependencies:
cassandra20 noarch 2.0.17-1 datastax 17 M
Transaction Summary
==============================================================================================================================
Install 2 Package(s)
Total download size: 17 M
Installed size: 20 M
Downloading Packages:
(1/2): cassandra20-2.0.17-1.noarch.rpm | 17 MB 00:11
(2/2): dsc20-2.0.17-1.noarch.rpm | 1.9 kB 00:00
------------------------------------------------------------------------------------------------------------------------------
Total 1.4 MB/s | 17 MB 00:12
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Warning: RPMDB altered outside of yum.
Installing : cassandra20-2.0.17-1.noarch 1/2
Installing : dsc20-2.0.17-1.noarch 2/2
Verifying : cassandra20-2.0.17-1.noarch 1/2
Verifying : dsc20-2.0.17-1.noarch 2/2
Installed:
dsc20.noarch 0:2.0.17-1
Dependency Installed:
cassandra20.noarch 0:2.0.17-1
Complete!
3. Get Cassandra Running
Start-Up Cassandra
systemctl start cassandra
or
service cassandra start
Check Cassandra Service Status
systemctl status cassandra
or
service cassandra status
check CQL
cqlsh
The cqlsh interface should look similar to:
Connected to Test Cluster at localhost:9160.
[cqlsh 4.1.1 | Cassandra 2.0.10 | CQL spec 3.1.1 | Thrift protocol 19.39.0]
Use HELP for help.
cqlsh>
Check Cassandra Node Status
nodetool status
[root@ranjeet ~]# service cassandra status
cassandra is stopped
[root@ranjeet ~]# service cassandra start
Starting Cassandra: OK
[root@ranjeet ~]# nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 127.0.0.1 46.18 KB 256 100.0% 4cfd1047-75c9-403f-ac15-8f00b4636fd1 rack1
[root@ranjeet ~]#
If you get an error such as: ‘Failed to connect to ’127.0.0.1:7199′: Connection refused’
vim /etc/cassandra/default.conf/cassandra-env.sh
change following line in /etc/cassandra/default.conf/cassandra-env.sh , to your
# add this if you’re having trouble connecting:
# JVM_OPTS=”$JVM_OPTS -Djava.rmi.server.hostname=”
Restart Cassandra
service cassandra restart
Shutdown Cassandra
service cassandra stop
okey