Apache Cassandra is a wide column store NoSQL database management system. Cassandra provides high availability with no single point of failure, robust support for clusters spanning multiple datacenters. Facebook released Cassandra for Facebook inbox search feature. Main features of Apache Cassandra is it is – Distributed, Replication strategies are configurable, Scalable, Fault-tolerant, Has tunable consistency, Provides MapReduce support. Cassandra is a Java-based which can be managed and monitored via Java Management Extensions (JMX). Cassandra uses the Cassandra Query Language (CQL). Which is a simple interface for accessing Cassandra, alternative to the traditional Structured Query Language (SQL). Cassandra Query Language (CQL) provides an abstraction layer and provides native syntax. Example usage :
1 2 3 4 5 6 7 | USE ExampleKeySpace; CREATE COLUMNFAMILY ExampleColumns (id text, Last text, First text, PRIMARY KEY(id)); INSERT INTO ExampleColumns (id, Last, First) VALUES ('1', 'Doe', 'John'); SELECT * FROM ExampleColumns; |
Here Are the Steps on How Install Apache Cassandra on Ubuntu Single Cloud Server Instance. In this guide, we are helping you to go through installing Apache Cassandra, Apache Cassandra on a Ubuntu 16.04 LTS server instance. Commands for Ubuntu 18.04 LTS will be similar. You need a server instance with at least 4GB of memory. Insufficient memory will cause Apache Cassandra to exit. We will install Java on Ubuntu 16.04, then install Apache Cassandra and test Apache Cassandra installation.
Steps on How Install Apache Cassandra on Ubuntu
We will install Java 8 from the PPA repository. We have to install python-software-properties
package :
---
1 2 3 4 5 | apt update -y && apt upgrade -y apt install python-software-properties -y add-apt-repository -y ppa:webupd8team/java ## accept the prompt apt update -y && apt upgrade -y |
You have two options for Java.
Option 1 for Java : Oracle Java from repository
Now you can install Java 8 :
1 | apt install oracle-java8-installer -y |
Accept the ‘Oracle license terms’ prompt. Verify that Java is now installed :
1 | java -version |
Option 2 for Java : OpenJDK JRE (easy)
Optionally, you could install OpenJDK JRE :
1 | apt install openjdk-8-jre -y |
Common Steps
You can create the JAVA_HOME
environment variable with the following commands, $JAVA_HOME
path must match :
1 2 3 | echo "JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")" | sudo tee -a /etc/profile source /etc/profile echo $JAVA_HOME |
Python
Apache Cassandra may requires Python 2.7 (rather than Python 3). Check the existence and version of Python on your machine:
1 | python -v |
You probably need to install Python 2.7 by running :
1 | sudo apt install python -y |
Installing Apache Cassandra
From official site, you’ll get the latest binary of Apache Cassandra as tar ball:
1 | http://cassandra.apache.org/download/ |
Current is Apache Cassandra 3.11 release. For 3.11, we can install from repository :
1 2 3 4 | echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add - apt update -y && apt upgrade -y apt install cassandra -y |
Apache Cassandra’s Debian releases are these :
1 | http://dl.bintray.com/apache/cassandra/ |
You can change our command shown above :
1 | echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list |
…to latest one, with presently imaginary version 3.12
:
1 | echo "deb http://www.apache.org/dist/cassandra/debian 312x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list |
If you get GPG public key error, run the following commands (for 311x in our example) :
1 2 | sudo apt-key adv --keyserver pool.sks-keyservers.net --recv-key A278B781FE4B2BDA sudo apt-get update |
Then run the commands :
1 2 3 4 | apt update -y && apt upgrade -y apt install cassandra -y ## install ntp for correct time of sync in future with other nodes apt install ntp -y |
Start the Apache Cassandra daemon:
1 | sudo service cassandra start |
Make Apache Cassandra automatically start at system boot:
1 2 | sudo update-rc.d cassandra defaults # systemctl enable cassandra |
Get the status of Apache Cassandra on current node:
1 | nodetool status |
You can use the cqlsh shell to interact with Apache Cassandra:
1 | cqlsh localhost |
The cqlsh is the command-line tool written in Python for executing the Cassandra Query Language (CQL) command.
Simply running the cqlsh
command launches it :
1 | cqlsh |
Make a backup of the Cassandra configuration file cassandra.yaml
. Find the file on Ubuntu with (taing that locate program is installed) :
1 2 | sudo updatedb locate cassandra.yaml |
If it is located at /etc/cassandra/cassandra.yaml
, then run :
1 2 | cp /etc/cassandra/cassandra.yaml /etc/cassandra/cassandra.yaml.backup nano /etc/cassandra/cassandra.yaml |
Match the following variables in the file to the values shown below. Properties found in the cassandra.yaml config file should be set based on your project’s particular requirements :
1 2 3 4 5 6 7 | ... authenticator: org.apache.cassandra.auth.PasswordAuthenticator authorizer: org.apache.cassandra.auth.CassandraAuthorizer role_manager: CassandraRoleManager roles_validity_in_ms: 0 permissions_validity_in_ms: 0 ... |
Open the Cassandra command terminal by typing cqlsh :
1 | cqlsh -u cassandra -p cassandra |
Create a new superuser, change example [new_superuser]
, [secure_password]
with real information :
1 | CREATE ROLE [new_superuser] WITH PASSWORD = '[secure_password]' AND SUPERUSER = true AND LOGIN = true; |
Log back as new superuser like MySQL and run:
1 | ALTER ROLE cassandra WITH PASSWORD = 'cassandra' AND SUPERUSER = false AND LOGIN = false; |
And…
1 | REVOKE ALL PERMISSIONS ON ALL KEYSPACES FROM cassandra; |
Grant all permissions to the new superuser account. Replace [superuser]
with your real superuser account username:
1 | GRANT ALL PERMISSIONS ON ALL KEYSPACES TO [superuser]; |
Create cqlshrc
file. If the ~/.cassandra
directory does not exist, create it:
1 2 | sudo mkdir ~/.cassandra sudo nano ~/.cassandra/cqlshrc |
You’ll get information on cqlshrc
here :
1 | https://docs.datastax.com/en/cql/3.3/cql/cql_reference/cqlshUsingCqlshrc.html |
This is sample cqlshrc
from CentOS :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | ;; Options that are common to both COPY TO and COPY FROM [copy] ;; The string placeholder for null values nullval=null ;; For COPY TO, controls whether the first line in the CSV output file will ;; contain the column names. For COPY FROM, specifies whether the first ;; line in the CSV file contains column names. header=true ;; The string literal format for boolean values boolstyle = True,False ;; Input login credentials here to automatically login to the Cassandra command line without entering them each time. When this ;; is enabled, just type "cqlsh" to start Cassandra. [authentication] username=[superuser] password=[password] ;; Uncomment to automatically use a certain keyspace on login ;; keyspace=[keyspace] [ui] color=on datetimeformat=%Y-%m-%d %H:%M:%S%z completekey=tab ;; The number of digits displayed after the decimal point ;; (note that increasing this to large numbers can result in unusual values) float_precision = 5 ;; The encoding used for characters encoding = utf8 |
Save and close the file. Change permissions:
1 2 | sudo chmod 1700 ~/.cassandra/cqlshrc sudo chmod 700 ~/.cassandra |
Login to cqlsh. Replace [example_name] with your new cluster name:
1 | UPDATE system.local SET cluster_name = '[example_name]' WHERE KEY = 'local'; |
Open the cassandra.yaml
file and replace the value in the cluster_name
variable with the new cluster name you just set with above command :
1 | nano /etc/cassandra/cassandra.yaml |
Save changes. Run this command and reboot the instance :
1 2 | nodetool flush system reboot |
We guess, you have successfully installed Apache Cassandra. You understood that guides by many websites are weak at point of security even for testing purpose. Cassandra is like MySQL. Most of the DBMS are like MySQL. They needs to be tweaked, secured.
You’ll get detailed documents on official website :
1 | http://cassandra.apache.org/doc/latest/ |