Cassandra is a useful NoSQL database management system with praise for its high availability. Let’s demonstrate how to install Cassandra 2.1 on Mac OS X.
Step 1) Install the Oracle Java Development Kit (JDK)
On Macs, you can easily download the corresponding dmg file and install.
After installing, check that you have installed the JDK.
1 | java -version |
Step 2) Install Cassandra
Make a directory for your Cassandra package and change directory into it.
1 | mkdir -p ~/opt/packages && cd $_ |
Download the latest Cassandra tar file into the directory you just made.
http://cassandra.apache.org/download/
At the time of writing, 2.1.6 is the most stable release.
1 | wget http://apache.mirrors.ionfish.org/cassandra/2.1.6/apache-cassandra-2.1.6-bin.tar.gz |
Extract the file.
1 | tar -xvf apache-cassandra-2.1.6-bin.tar.gz |
Set a symbolic link from the newly extracted folder to a conveniently named cassandra folder in your packages directory.
1 | ln -s ~/opt/packages/apache-cassandra-2.1.6 ~/opt/cassandra |
Step 3) Cassandra directory configurations
We’ll use some convenient Cassandra configurations to store logs, data, and cached files.
1 2 3 4 | mkdir -p ~/opt/cassandra/data/data mkdir -p ~/opt/cassandra/data/commitlog mkdir -p ~/opt/cassandra/data/saved_caches mkdir -p ~/opt/cassandra/logs |
1 | cd ~/opt/cassandra |
We will edit the ~/opt/cassandra/conf/cassandra.yaml
file to accommodate the folders that we just created. Configure the following settings. Erase the # on each.
1 | vim conf/cassandra.yaml |
1 2 3 4 | data_file_directories: - ~/opt/cassandra/data/data commitlog_directory: ~/opt/cassandra/data/commitlog saved_caches_directory: ~/opt/cassandra/data/saved_caches |
4) Add Cassandra to PATH
Open the bash profile.
1 | vim ~/.bash_profile |
Add Cassandra to PATH, so you can call cassandra from anywhere.
1 2 3 | if [ -d "$HOME/opt" ]; then PATH="$PATH:$HOME/opt/cassandra/bin" fi |
Load the bash profile.
1 | source ~/.bash_profile |
5) Run Cassandra
Start Cassandra. Cassandra should run with a long log record.
1 | cassandra -f |
CTRL-C
to close Cassandra, but let’s not do that right now. Instead, open a new terminal. You can log into the Cassandra shell in the new terminal as long as Cassandra is running.
1 | cqlsh |
You can run commands within the Cassandra shell, which looks like:
1 2 3 | [cqlsh 5.0.1 | Cassandra 2.1.6 | CQL spec 3.2.0 | Native protocol v3] Use HELP for help. cqlsh> |
Cassandra is successfully installed and usable!