Cassandra server in 10 minutesDec 8, 2016
Want to quickly find out how a Cassandra server feels? In this blog post, we’ll
create a single-node Cassandra cluster on an Ubuntu Xenial (16.04) system. It’s
not really a ‘cluster’, but you can access the Cassandra shell
cqlsh and try
out all of its commands. Since we are just looking for a quick start, we’re
installing one of the latest Cassandra versions – version 3.7. Even more, the
steps here are totally scriptable, so you can just blindly paste the lines and
it’ll work! OK let’s get started.
Note: Jump straight to the last portion to get all the commands at one place without explanation
Let’s go to the temporary directory where we’ll download Sun’s Java. Here I am downloading Java’s ‘Server JRE’ file. I have it hosted in Amazon cloud which you can use. You can bring your own JRE or JDK file too. Just make sure you make appropriate replacements in the command.
Now actually download the JRE file
Create the directory where you want to expand this compressed file
sudo mkdir -p /usr/lib/jvm
Now uncompress it
sudo tar -xzvf server-jre-8u101-linux-x64.tar.gz -C /usr/lib/jvm
Now update system’s Java pointers and make this Java the preferred Java to be used
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_101/bin/java" 1 sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_101/bin/java
You can check our Java is the preferred Java by checking Java version.
The output should say something like
java version "1.8.0_101".
Add Cassandra repositories at appropriate place so that our beloved
utility can find the place from where to download Cassandra packages.
echo "deb http://www.apache.org/dist/cassandra/debian 37x main" | sudo tee -a /etc/apt/sources.list echo "deb-src http://www.apache.org/dist/cassandra/debian 37x main" | sudo tee -a /etc/apt/sources.list
Now add the cryptographic keys at proper places. Don’t ask me why do we have to do it :)
gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 749D6EEC0353B12C sudo apt-key add ~/.gnupg/pubring.gpg
Now update repository pointers, and install Cassandra!
sudo apt-get --yes --quiet update sudo apt-get install --yes --quiet cassandra
Cassandra should be installed and running by now. You can check it by checking status of Cassandra service
sudo service cassandra status
q to exit. I don’t know why they make us press
q, but anyway..
Cassandra server is running by now. You can check that by checking the status
sudo nodetool status
The state should be
UN, i.e. ‘U’p and ‘N’ormal. If the output is different,
then wait a few seconds and try again.
There are a few more steps to get the
cqlsh command line utility working.
Let’s get them done too.
pip utility which will install Python packages. If you already have
pip utility, no need to execute this step. Note that this is just one of many
ways to install
sudo apt-get install --yes --quiet python-pip
Now install pip package
cassandra-driver. You can install it in virtual
environment also. You can safely ignore my last sentence if you have never
heard the term ‘Python virtual environments’ before.
sudo pip install cassandra-driver
I wish everything worked after this, but it won’t. Just set this environment
variable and then you should be good to log in into
Now ‘actually’ log into
The output should be something like:
ubuntu@hostname:~$ cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.7 | CQL spec 3.4.2 | Native protocol v4] Use HELP for help. cqlsh>
Voila! Note that you need to export
CQLSH_NO_BUNDLED=true in every terminal
shell from where you want to access
cqlsh. So if you log out of the system
and log back in, you need to re-run this command.
Now you can follow any
cqlsh tutorial to try out commands to create
keyspaces, tables, rows, etc.
Everything at one place
You can just paste these lines in a file and run that file as a script, and it’ll set everything up for you.
cd /tmp wget http://eezydb.s3.amazonaws.com/server-jre-8u101-linux-x64.tar.gz sudo mkdir -p /usr/lib/jvm sudo tar -xzvf server-jre-8u101-linux-x64.tar.gz -C /usr/lib/jvm sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.8.0_101/bin/java" 1 sudo update-alternatives --set java /usr/lib/jvm/jdk1.8.0_101/bin/java echo "deb http://www.apache.org/dist/cassandra/debian 37x main" | sudo tee -a /etc/apt/sources.list echo "deb-src http://www.apache.org/dist/cassandra/debian 37x main" | sudo tee -a /etc/apt/sources.list gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 749D6EEC0353B12C sudo apt-key add ~/.gnupg/pubring.gpg sudo apt-get --yes --quiet update sudo apt-get install --yes --quiet cassandra python-pip sudo pip instlal cassandra-driver export CQLSH_NO_BUNDLED=true cqlsh
If you like this, please share! If you have any suggestions, please comment!
Until next time!