Apache Cassandra is an open-source NoSQL database with no single point of failure, providing linear scalability and high availability without compromising performance. In Cassandra, records are structured in a similar way as in the relational database with tables, rows, and columns. Apache Cassandra is used by a number of organizations including Apple, NetFlix, eBay, and Easou.
This tutorial describes how to install Apache Cassandra on CentOS 7.
The user you are logged in as must have sudo privileges to be able to install packages.
Installing Apache Cassandra
The recommended way to install Apache Cassandra on CentOS 7 is by installing the rpm package from the official Apache Cassandra repository.
At the time of writing this article, the latest version of Apache Cassandra is
3.11 and requires OpenJDK 8 to be installed on the system.
To install OpenJDK, on your system type:
sudo yum install java-1.8.0-openjdk-devel
Verify the Java installation by running the following command which will print the Java version:
The output should look something like this:
openjdk version "1.8.0_201" OpenJDK Runtime Environment (build 1.8.0_201-b09) OpenJDK 64-Bit Server VM (build 25.201-b09, mixed mode)
Now that Java is installed, the next step is to add the Apache Cassandra repository.
Open your editor of choice and create the following repository file:
sudo nano /etc/yum.repos.d/cassandra.repo
Paste the following content into the file:
[cassandra] name=Apache Cassandra baseurl=https://www.apache.org/dist/cassandra/redhat/311x/ gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.apache.org/dist/cassandra/KEYS
Once the repository is enabled, install the latest version of Apache Cassandra by typing:
sudo yum install cassandra
Start and enable the Cassandra service:
sudo systemctl enable cassandra
Verify that Cassandra is running by typing:
You should see something similar to this:
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 103.68 KiB 256 100.0% 129a9437-377d-415b-b6b2-5dc46b73a763 rack1
At this point, Apache Cassandra has been installed on your CentOS server.
Configuring Apache Cassandra
Apache Cassandra data is stored in the
/var/lib/cassandra directory, configuration files are located in
/etc/cassandra and Java start-up options can be configured in the
By default, Cassandra is configured to listen on localhost only. If the client connecting to the database is also running on the same host you don’t need to change the default configuration file.
To interact with Cassandra through CQL (the Cassandra Query Language) you can use a command line utility named
cqlsh that is shipped with the Cassandra package.
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.4 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
Renaming Apache Cassandra Cluster
By default, the Cassandra cluster is named “Test Cluster”. Follow the steps bellow if you want to change the cluster name:
Login to the Cassandra CQL terminal with
The following command will change the cluster name to “Linuxize Cluster”:
UPDATE system.local SET cluster_name = 'Linuxize Cluster' WHERE KEY = 'local';
Replace “Linuxize Cluster” with your desired name. Once done type
exit to exit the console.
cassandra.yaml configuration file and enter your new cluster name./etc/cassandra/default.conf/cassandra.yaml
cluster_name: 'Linuxize Cluster'
Run the following command to clear the system cache:
nodetool flush system
Finally restart the Cassandra service:
sudo systemctl restart cassandra
You have successfully installed Apache Cassandra on your CentOS 7. You can now visit the official Apache Cassandra Documentation page and learn how to get started with Cassandra.
If you hit a problem or have feedback, leave a comment below.