Installing Cassandra

Installation Methods

There are two metods of installing Cassandra; Package Manager and Tarball.

Package Manager

With an external internet connection, Cassandra can be installed using a package manager. This method requires root permissions and will install the binaries and configuration files as the cassandra OS user.

Options are:

  • APT for Debian and Ubuntu systems
  • YUM for RHEL systems.

Tarball Installation

Without external internet access a tarball is the only option for installation. The tarball is placed on the server then files are unpacked into a single location with binaries and configuration files. The tarball installation does not require root permissions

Installation

Select the appropriate installation instructions from below based on the OS

Debian and Ubuntu Installation

  1. Verify the version of Java installed. For example:
java -version
  1. Add the Apache repository of Cassandra to the file cassandra.sources.list.
echo "deb http://www.apache.org/dist/cassandra/debian 311x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
  1. Add the Apache Cassandra repository keys to the list of trusted keys on the server:
curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
  1. Update the package index from sources:
sudo apt-get update
  1. Install Cassandra with APT:
sudo apt-get install cassandra

Validation

NOTE: A new Linux user cassandra will get created as part of the installation. The Cassandra service will also be run as this user.

The Cassandra service gets started automatically after installation. Monitor the progress of the startup with:

tail -f /var/log/cassandra/system.log

Cassandra is ready when you see an entry like this in the system.log:

INFO  [main] 2019-12-17 03:03:37,526 Server.java:156 - Starting listening for CQL clients on localhost/127.0.0.1:9042 (unencrypted)...

Check the status of Cassandra:

nodetool status

The status column in the output should report UN which stands for “Up/Normal”.

Install the Optional Tools

sudo apt-get install cassandra-tools=3.11.x.x 

Clear the Default Cluster

Because the Debian packages start the Cassandra service automatically, you must stop the server and clear the data. Doing this removes the default cluster_name (Test Cluster) from the system table. All nodes must use the same cluster name.

sudo service cassandra stop
sudo rm -rf /var/lib/cassandra/*

Configure Cassandra (see next section)

Optional: To change the location of the default directories (/var/lib/cassandra), see the following in /etc/cassandra/conf/cassandra.yaml:

data_file_directories
commitlog_directory
saved_caches_directory

Optional: To change the location of the log files (/var/log/cassandra), replace the path to the log directory in /usr/sbin/cassandra:

if [ -z "$CASSANDRA_LOG_DIR" ]; then
CASSANDRA_LOG_DIR=/var/log/cassandra
fi

RHEL Installation

  1. Verify the version of Java installed. For example:
java -version
  1. Add the Apache repository of Cassandra to the file /etc/yum.repos.d/cassandra.repo (as the root user).
    The example installs the latest version of 3.11
[cassandra]
name=Apache Cassandra
baseurl=https://downloads.apache.org/cassandra/redhat/311x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=[https://downloads.apache.org/cassandra/KEYS](https://downloads.apache.org/cassandra/KEYS)
  1. Update the package index from sources:
sudo yum update
  1. Install Cassandra with YUM:
sudo yum install cassandra

NOTE: A new Linux user cassandra will get created as part of the installation. The Cassandra service will also be run as this user.

  1. Start the Cassandra service:
$ sudo service cassandra start
  1. Monitor the progress of the startup with:
tail -f /var/log/cassandra/system.log

Validation

Cassandra is ready when you see an entry like this in the system.log:

INFO  [main] 2019-12-17 03:03:37,526 Server.java:156 - Starting listening for CQL clients on localhost/127.0.0.1:9042 (unencrypted)...

Check the status of Cassandra:

nodetool status

The status column in the output should report UN which stands for "Up/Normal".

Configure Cassandra (see next section)

Binary Tarball Installation

This installation method is needed when package installers cannot be used or the server doesn't have a connection to the external internet.

  1. Verify the version of Java installed. For example:
java -version
  1. Download or copy the tarball to each server (Version 3.11.10 in this example)

NOTE: When the server does not have internet the files must be downloaded onto anohter computer then tranfered to the server.

Web:

[http://archive.apache.org/dist/cassandra/3.11.10/](http://archive.apache.org/dist/cassandra/3.11.10/)

OR
curl:

curl  -OL  http://archive.apache.org/dist/cassandra/3.11.10/apache-cassandra-3.11.10-bin.tar.gz
  1. Create a directory for the Cassandra installation. A common choice is /opt/cassandra
    (The directory you select must be on a filesystem that has a least 250GB of free space.)
mkdir -p /opt/cassandra
  1. Move the tar file to a directory you just created:
mv xzvf apache-cassandra-3.11.10-bin.tar.gz   /opt/cassandra/.
  1. Unpack the tarball to a directory of your choice:
tar xzvf apache-Cassandra-3.11.10-bin.tar.gz 
  1. The file will be unpacked to a subdirectory named apache-cassandra-3.11.10 If you used /opt/cassandra as the starting directory, then you will end up with your Cassandra folders and files located in _/opt/cassandra/apache-cassandra-3.11.10_

  2. This is your install_directory. Under this directory you will find the following sub-directories:

Directory Description
bin/ Utilities and start scripts.
conf/ Configuration files and environment settings.
data/ directory containing files for commtlog, data, and saved_caches unless changes in the cassandra.yaml file.
interface/ Thrift legacy API (obsolete)
javadoc/ Cassandra Java API documentation
lib/ JAR and license files
tools/ Cassandra tools and sample cassandra.yaml file for stress testing

Create a dedicated user and group.

Recommended is cassandra:cassandra.

Make cassandra:cassandra owns all /opt/cassandra files and folder. (if that’s where it is installed)

chown -R cassandra:cassandra  /opt/cassandra 

Configure Cassandra (see next section)
DO NOT START Cassandra until this step is completed.