OSETC TECH

How to Install Apache Cassandra on Ubuntu 16.04 or 18.04

This post will guide you how to install Apache Cassandra on your Ubuntu Linux 18.04 or 16.04. How do I install Cassandra database management system on your Ubuntu Linux system.

What is Apache Cassandra?


Apache Cassandra is a free and open-source, distributed, wide column store, NoSQL database management system designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. Cassandra offers robust support for clusters spanning multiple datacenters, with asynchronous masterless replication allowing low latency operations for all clients.

The Apache Cassandra database is the right choice when you need scalability and high availability without compromising performance. Linear scalability and proven fault-tolerance on commodity hardware or cloud infrastructure make it the perfect platform for mission-critical data. Cassandra’s support for replicating across multiple datacenters is best-in-class, providing lower latency for your users and the peace of mind of knowing that you can survive regional outages.

Prerequisites


$ sudo apt update
$ sudo apt upgrade

Step1: Installing JAVA 8


Apache Cassandra requires JAVA JDK environment or JRE version 7 or above to be installed on your Ubuntu system. You can install either the Oracle JAVA Standard Edition 8 or OpenJDK 8 on the system.

The OpenJDK 8 is already available in the default Ubuntu APT repository. So we try to install the OpenJDK 8 on this guide, just type the following command to update the packages index and installing OpenJDK 8:

$ sudo apt install openjdk-8-jdk

Outputs:

devops@devops:~$ sudo apt install openjdk-8-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ca-certificates-java libxt-dev openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
Suggested packages:
libxt-doc openjdk-8-demo openjdk-8-source visualvm icedtea-8-plugin fonts-ipafont-gothic fonts-ipafont-mincho fonts-wqy-microhei fonts-wqy-zenhei
The following NEW packages will be installed:
ca-certificates-java libxt-dev openjdk-8-jdk openjdk-8-jdk-headless openjdk-8-jre openjdk-8-jre-headless
0 upgraded, 6 newly installed, 0 to remove and 45 not upgraded.
Need to get 37.5 MB/37.5 MB of archives.
After this operation, 143 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y

After JDK package is installed, you can check the installation of JDK package by print the version of JDK installed, type:

$ java -version

Outputs:

devops@devops:~$ java -version
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

Note: If you want to install the Oracle JAVA 8 on your Ubuntu system, just issue the following commands:

$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt update
$ sudo apt install oracle-java8-installer –y

Step2: Installing Apache Cassandra


Once Java is installed on your Ubuntu system, you can begin to install Apache Cassandra. And you can install it by installing the deb package from the official Apache Cassandra site. Or you can also add its official repository into your APT repository, then you can install it by apt command.

Before adding Apache Cassandra repository into your system, you need to import the repository’s GPG key with the following command:

$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -

Outputs:

devops@devops:~$ wget -q -O - https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
OK

Then you can run the following command to add Apache Cassandra repository into a new repo file called Cassandra.list, type:

$ sudo sh -c 'echo "deb http://www.apache.org/dist/cassandra/debian 311x main" > /etc/apt/sources.list.d/cassandra.list'

Once the Apache Cassandra repository is enabled, and you need to update the apt index list and then you can install the latest version of Apache Cassandra to your system, type:

$ sudo apt update
$ sudo apt install cassandra

Outputs:

devops@devops:/etc/apt/sources.list.d$ sudo apt update
Hit:1 http://mirrors.aliyun.com/ubuntu bionic InRelease
Hit:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease
Hit:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease
Hit:4 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease
Hit:5 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease
Get:6 http://dl.bintray.com/apache/cassandra 311x InRelease [3,183 B]
Fetched 3,183 B in 1s (2,274 B/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
127 packages can be upgraded. Run 'apt list --upgradable' to see them.

devops@devops:~$ sudo apt install cassandra
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libopts25 ntp sntp
Suggested packages:
cassandra-tools ntp-doc
The following NEW packages will be installed:
cassandra libopts25 ntp sntp
0 upgraded, 4 newly installed, 0 to remove and 127 not upgraded.
Need to get 30.6 MB of archives.
After this operation, 42.1 MB of additional disk space will be used.
Do you want to continue? [Y/n]Y
……
Preparing to unpack .../cassandra_3.11.4_all.deb ...
Unpacking cassandra (3.11.4) ...
Setting up cassandra (3.11.4) ...
Adding group `cassandra' (GID 131) ...
Done.
vm.max_map_count = 1048575
net.ipv4.tcp_keepalive_time = 300
update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
Processing triggers for ureadahead (0.100.0-21) ...
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.23) ...
Setting up libopts25:amd64 (1:5.18.12-4) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up sntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Setting up ntp (1:4.2.8p10+dfsg-5ubuntu7.1) ...
Created symlink /etc/systemd/system/network-pre.target.wants/ntp-systemd-netif.path → /lib/systemd/system/ntp-systemd-netif.path.
Created symlink /etc/systemd/system/multi-user.target.wants/ntp.service → /lib/systemd/system/ntp.service.
ntp-systemd-netif.service is a disabled or a static unit, not starting it.
Processing triggers for libc-bin (2.27-3ubuntu1) ...
Processing triggers for systemd (237-3ubuntu10.23) ...
Processing triggers for ureadahead (0.100.0-21) ...

Once the installation of Apache Cassandra is complete, and the Cassandra service has been started. And you can verify if the Cassandra server is running by executing the following command:

$ systemctl status Cassandra

Outputs:

devops@devops:~$ systemctl status cassandra
 cassandra.service - LSB: distributed storage system for structured data
Loaded: loaded (/etc/init.d/cassandra; generated)
Active: active (exited) since Wed 2019-08-21 07:22:15 EDT; 58s ago
Docs: man:systemd-sysv-generator(8)
Tasks: 0 (limit: 1123)
CGroup: /system.slice/cassandra.service

Aug 21 07:22:15 devops systemd[1]: Starting LSB: distributed storage system for structured data...
Aug 21 07:22:15 devops systemd[1]: Started LSB: distributed storage system for structured data.

Step3: Start and Enable Apache Cassandra Service


If you need to start the Apache Cassandra service on your Ubuntu system, you can run the following command:

$ sudo systemctl start cassandra

If you want to stop the Apache Cassandra server, you can use the following command:

$ sudo systemctl stop cassandra

If you need to enable the Apache Cassandra on system boot, you can use the command below to enable it, type:

$ sudo systemctl enable cassandra

Conclusion


You should know that how to install Apache Cassandra system on your Ubuntu or Debian Linux. If you want to see more detailed information about Cassandra, you can directly go to its official web site.