Cassandra, or Apache Cassandra, is a highly scalable open source database system, achieving great performance on multi-node setups. In this tutorial, you’ll learn how to install Cassandra, the Oracle Java VM, which is highly recommended for Cassandra, and how to run your first test single-node cluster.
Make a temporary folder on your home directory to install Java.
mkdir ~/temp cd ~/temp
The Cassandra documentation highly recommends the Oracle Java VM 8, so you’ll have to download it from Oracle’s website. It requires a free account, which you can register here. After you’ve created your account, download either the 32-bit or the 64-bit (recommended) version of Java 8. Once you’ve downloaded it, transfer it to your VPS using FTP or any other tool. You can find a tutorial on how to setup an FTP server here.
Now extract the contents of the archive:
tar -zxf jdk-8u65-linux-x64.tar.gz
You should now move it to the proper folder:
sudo mkdir /usr/local/java sudo mv jdk1.8.0_65/ /usr/local/java
To make it the default Java VM on your VPS, add these lines to the /etc/profile file:
JAVA_HOME=/usr/local/java/jdk1.8.0_65 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin JRE_HOME=/usr/local/java/jdk1.8.0_65 PATH=$PATH:$HOME/bin:$JRE_HOME/bin export JAVA_HOME export JRE_HOME export PATH
by scrolling down after running:
sudo nano /etc/profile
and pasting it at the end of the file, like so:
After you’ve done this, press CTRL+O to save and CTRL+X to exit. Next, run the following lines so when the command “java” is called, it’s done so by the right VM.
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_65/bin/java" 1 sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_65/bin/javac" 1 sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_65/bin/javaws" 1 sudo update-alternatives --set java /usr/local/java/jdk1.8.0_65/bin/java sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_65/bin/javac sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_65/bin/javaws
You should now reboot your VPS so everything is updated:
sudo reboot
When establishing a SSH connection again, test to see if everything is set properly by running:
java -version echo $JAVA_HOME
If everything went OK, you should see this:
To install Cassandra, download the binary files from the website, unpack them and move it to your personal folder:
cd ~/temp wget http://mirror.cc.columbia.edu/pub/software/apache/cassandra/2.2.3/apache-cassandra-2.2.3-bin.tar.gz tar -zxf apache-cassandra-2.2.3-bin.tar.gz mv apache-cassandra-2.2.3 ~/cassandra
Next, make sure that the folders Cassandra accesses, such as the log folder, exists and that Cassandra has the right to write on it:
sudo mkdir /var/lib/cassandra sudo mkdir /var/log/cassandra sudo chown -R $USER:$GROUP /var/lib/cassandra sudo chown -R $USER:$GROUP /var/log/cassandra
Now set Cassandra’s variables by running:
export CASSANDRA_HOME=~/cassandra export PATH=$PATH:$CASSANDRA_HOME/bin
To run a single-node test cluster of Cassandra, you aren’t going to need to change anything on the cassandra.yaml file. Simply run:
sudo sh ~/cassandra/bin/cassandra
and then run:
sudo sh ~/cassandra/bin/cqlsh
and if it says "Connected to: 'Test Cluster'" as it does below, you are now running your single-node cluster.
root@cassandra:~# sudo sh ~/cassandra/bin/cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 2.2.3 | CQL spec 3.3.1 | Native protocol v4] Use HELP for help. cqlsh>
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
wget on cassandra version 1.2.8 doesn’t work but using 1.2.9 does wget http://www.us.apache.org/dist/cassandra/1.2.9/apache-cassandra-1.2.9-bin.tar.gz
@yodit: Thanks, I’ve updated the article.
I highly recommend using this to get Cassandra going under Ubuntu:
http://www.datastax.com/documentation/gettingstarted/getting_started/gettingStartedDeb_t.html
Cassandra 1.2.9 link not working, for this moment works http://www.us.apache.org/dist/cassandra/1.2.12/apache-cassandra-1.2.12-bin.tar.gz
Instead of using 1.2.9 or any other version go to http://www.us.apache.org/dist/cassandra and replace the version with the latest, in my case I used http://www.us.apache.org/dist/cassandra/2.0.4/apache-cassandra-2.0.4-bin.tar.gz
This is a very simple method for installing Oracle JDK 7 on the server which is needed for the latest versions of Cassandra
I can’t get this to work on Ubuntu 12.04. It seems that everything installs, but when I load the cli, it tells me that it cannot connect to the database. Everything says I’m doing it correct. This article needs updating too because cassandra has moved to 2.0.x and requires java 7. (The Java links above are broken.)
super to users
Very old procedure, Please update this.
I’ve updated the download URL to point to the latest release of Cassandra’s 1.2.x branch.