How to install Apache Cassandra in Ubuntu

To install Apache Cassandra in Ubuntu

Apache Cassandra is a NoSQL database designed for storing large amounts of data. In this each node acts a 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. The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance.

Installation of Oracle JDK

Utilize the following command to install Oracle JDK.

root@linuxhelp:~# add-apt-repository -y ppa:webupd8team/java 
gpg: keyring `/tmp/tmpyjqbv0pc/secring.gpg'  created
gpg: keyring `/tmp/tmpyjqbv0pc/pubring.gpg'  created
gpg: requesting key EEA14886 from hkp server keyserver.ubuntu.com
gpg: /tmp/tmpyjqbv0pc/trustdb.gpg: trustdb created
gpg: key EEA14886: public key " Launchpad VLC"  imported
gpg: no ultimately trusted keys found
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
OK


After adding the PPA, use the below command to update and install Java.

root@linuxhelp:~# apt-get update 
Get:1 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]
Hit:2 http://in.archive.ubuntu.com/ubuntu xenial InRelease                 
Hit:3 http://ppa.launchpad.net/webupd8team/java/ubuntu xenial InRelease                                 
Hit:4 http://in.archive.ubuntu.com/ubuntu xenial-updates InRelease                                      
Hit:5 http://in.archive.ubuntu.com/ubuntu xenial-backports InRelease                 
Fetched 94.5 kB in 1s (60.6 kB/s)                              
Reading package lists... Done
root@linuxhelp:~# apt-get install oracle-java8-installer 
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following additional packages will be installed:
  gsfonts-x11 java-common
Suggested packages:
  binfmt-support visualvm ttf-baekmuk | ttf-unfonts | ttf-unfonts-core ttf-kochi-gothic
  | ttf-sazanami-gothic ttf-kochi-mincho | ttf-sazanami-mincho ttf-arphic-uming
The following NEW packages will be installed:
  gsfonts-x11 java-common oracle-java8-installer
0 upgraded, 3 newly installed, 0 to remove and 396 not upgraded.
Need to get 38.6 kB of archives.
After this operation, 227 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
.
.
.
Length: 181352138 (173M) [application/x-gzip]
Saving to: ‘ jdk-8u101-linux-x64.tar.gz’ 

     0K ........ ........ ........ ........ ........ ........  1%  249K 11m39s
  3072K ........ ........ ........ ........ ........ ........  3%  361K 9m40s
  6144K ........ ........ ........ ........ ........ ........  5%  370K 8m51s
  9216K ........ ........ ........ ........ ........ ........  6%  197K 10m0s
 12288K ........ ........ ........ ........ ........ ........  8%  146K 11m32s
 15360K ........ ........ ........ ........ ........ ........ 10%  317K 10m49s
 18432K ........ ........ ........ ........ ........ ........ 12%  465K 9m54s
 21504K ........ ........ ........ ........ ........ ........ 13%  239K 9m49s
 24576K ........ ........ ........ ........ ........ ........ 15%  508K 9m6s
 27648K ........ ........ ........ ........ ........ ........ 17%  608K 8m25s
 30720K ........ ........ ........ ........ ........ ........ 19%  468K 7m57s
.
.
.
update-alternatives: using /usr/lib/jvm/java-8-oracle/bin/xjc to provide /usr/bin/xjc (xjc) in auto mode
Oracle JDK 8 installed
update-alternatives: using /usr/lib/jvm/java-8-oracle/jre/lib/amd64/libnpjp2.so to provide /usr/lib/mozilla/plugins/libjavaplugin.so (mozilla-javaplugin.so) in auto mode
Oracle JRE 8 browser plugin installed
Setting up gsfonts-x11 (0.24) ...

Installation of Cassandra

Create a directory inside the location " /opt" and change the current directory as shown below.

root@linuxhelp:~# mkdir -p ~/opt/packages
root@linuxhelp:~# cd ~/opt/packages/ 


After creating the directory, download the Apache Cassandra binary files from the website.

root@linuxhelp:~/opt/packages# wget http://mirrors.koehn.com/apache/cassandra/3.9/apache-cassandra-3.9-bin.tar.gz 
--2016-10-07 15:30:40--  http://mirrors.koehn.com/apache/cassandra/3.9/apache-cassandra-3.9-bin.tar.gz
Resolving mirrors.koehn.com (mirrors.koehn.com)... 74.91.25.210, 2604:4300:a:22::2
Connecting to mirrors.koehn.com (mirrors.koehn.com)|74.91.25.210|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 36719829 (35M) [application/x-gzip]
Saving to: ‘ apache-cassandra-3.9-bin.tar.gz’ 

apache-cassandra-3.9-bin.t 100%[=====================================> ]  35.02M   274KB/s    in 2m 21s  

2016-10-07 15:33:12 (254 KB/s) - ‘ apache-cassandra-3.9-bin.tar.gz’  saved [36719829/36719829]


Extract the downloaded binary files.

root@linuxhelp:~/opt/packages# tar -xzf apache-cassandra-3.9-bin.tar.gz  


Create the soft link for Apache-Cassandra, by running the following command.

root@linuxhelp:~/opt/packages# ln -s ~/opt/packages/apache-cassandra-3.9 ~/opt/cassandra 

Create data directories for Cassandra In this step we need to create several directories that are used by Cassandra. Each directory is used by the following configuration variable in conf/cassandra.yaml:

&bull     data_file_directories: ~/opt/cassandra/data/data
&bull     commitlog_directory: ~/opt/cassandra/data/commitlog
&bull     saved_caches_directory: ~/opt/cassandra/data/saved_caches

The logs directory is used by logback which is configured via the conf/logback.xml file.

root@linuxhelp:~/opt/packages# mkdir -p ~/opt/cassandra/data/data
root@linuxhelp:~/opt/packages# mkdir -p ~/opt/cassandra/data/commitlog
root@linuxhelp:~/opt/packages# mkdir -p ~/opt/cassandra/data/saved_caches
root@linuxhelp:~/opt/packages# mkdir -p ~/opt/cassandra/logs 


Start the Cassandra servers.

root@linuxhelp:~/opt/packages# ~/opt/cassandra/bin/cassandra -f -R 
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.deserializeLargeSubset (Lorg/apache/cassandra/io/util/DataInputPlus Lorg/apache/cassandra/db/Columns I)Lorg/apache/cassandra/db/Columns 
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubset (Ljava/util/Collection ILorg/apache/cassandra/db/Columns ILorg/apache/cassandra/io/util/DataOutputPlus )V
CompilerOracle: dontinline org/apache/cassandra/db/Columns$Serializer.serializeLargeSubsetSize (Ljava/util/Collection ILorg/apache/cassandra/db/Columns I)I
CompilerOracle: dontinline org/apache/cassandra/db/transform/BaseIterator.tryGetMoreContents ()Z
CompilerOracle: dontinline org/apache/cassandra/db/transform/StoppingTransformation.stop ()V
.
.
INFO  10:17:53 Starting listening for CQL clients on localhost/127.0.0.1:9042 (unencrypted)...
INFO  10:17:53 Not starting RPC server as requested. Use JMX (StorageService-> startRPCServer()) or nodetool (enablethrift) to start it

INFO  10:18:02 Scheduling approximate time-check task with a precision of 10 milliseconds


Lets start with Cassandra by login to Cassandra with the CQL shell cqlsh.

user1@linuxhelp:~$ sudo su 
[sudo] password for user1: 
root@linuxhelp:/home/user1# cd
root@linuxhelp:~# pwd 
/root    
root@linuxhelp:~# ~/opt/cassandra/bin/cqlsh 
Connected to Test Cluster at 127.0.0.1:9042.
[cqlsh 5.0.1 | Cassandra 3.9 | CQL spec 3.4.2 | Native protocol v4]
Use HELP for help.
cqlsh> 
cqlsh>  help

Documented shell commands:
===========================
CAPTURE  CLS          COPY  DESCRIBE  EXPAND  LOGIN   SERIAL  SOURCE   UNICODE
CLEAR    CONSISTENCY  DESC  EXIT      HELP    PAGING  SHOW    TRACING

CQL help topics:
================
AGGREGATES               CREATE_KEYSPACE           DROP_TRIGGER      TEXT     
ALTER_KEYSPACE           CREATE_MATERIALIZED_VIEW  DROP_TYPE         TIME     
ALTER_MATERIALIZED_VIEW  CREATE_ROLE               DROP_USER         TIMESTAMP
ALTER_TABLE              CREATE_TABLE              FUNCTIONS         TRUNCATE 
ALTER_TYPE               CREATE_TRIGGER            GRANT             TYPES    
ALTER_USER               CREATE_TYPE               INSERT            UPDATE   
APPLY                    CREATE_USER               INSERT_JSON       USE      
ASCII                    DATE                      INT               UUID     
BATCH                    DELETE                    JSON            
BEGIN                    DROP_AGGREGATE            KEYWORDS        
BLOB                     DROP_COLUMNFAMILY         LIST_PERMISSIONS
BOOLEAN                  DROP_FUNCTION             LIST_ROLES      
COUNTER                  DROP_INDEX                LIST_USERS      
CREATE_AGGREGATE         DROP_KEYSPACE             PERMISSIONS     
CREATE_COLUMNFAMILY      DROP_MATERIALIZED_VIEW    REVOKE          
CREATE_FUNCTION          DROP_ROLE                 SELECT          
CREATE_INDEX             DROP_TABLE                SELECT_JSON     
cqlsh> 
Tag : Cassandra
Comment
Gokul
Sep 10 2018
Could you please post the Complete Error
akashmusale
Sep 10 2018
No appropriate python interpreter found. please solve the error
Add a comment
FAQ
Q
What is Apache Cassandra?
A
*Apache Cassandra is a NoSQL database designed for storing large amounts of data
* The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance
Q
How can we start the cassendra server?
A
Let's start with Cassandra by login to Cassandra with the CQL shell cqlsh
Q
How to Create the soft link for Apache-Cassandra in Ubuntu?
A
by run the following command
# ln -s ~/opt/packages/apache-cassandra-3.9 ~/opt/cassandra
Q
Why bootstrapping a new node fails with a “Stream failed” error?
A
the GC may be creating long pauses disrupting the streaming process
compactions happening in the background hold streaming long enough that the TCP connection fails

In the first case, regular GC tuning advices apply. In the second case, you need to set TCP keepalive to a lower value (default is very high on Linux). Try to just run the following:

$ sudo /sbin/sysctl -w net.ipv4.tcp_keepalive_time=60 net.ipv4.tcp_keepalive_intvl=60 net.ipv4.tcp_keepalive_probes=5
Q
Nodetool says “Connection refused to host: 127.0.1.1” for any remote host. What gives?
A
If you are not using DNS, then make sure that your /etc/hosts files are accurate on both ends. If that fails, try setting the -Djava.rmi.server.hostname= JVM option near the bottom of cassandra-env.sh to an interface that you can reach from the remote machine.