In this article, we want to teach you how to Set up and Configure Apache Cassandra on Centos 7.
Apache Cassandra is a highly scalable, high-performance distributed database designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It is a type of NoSQL database.
Set up and Configure Apache Cassandra on Centos 7
You need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article about the Initial Server Setup with Centos 7.
To install Apache Cassandra on Centos 7, follow the steps below.
Install Apache Cassandra on Centos 7
First, update the local package index with the following command:
sudo yum update
The Apache Cassandra requires OpenJDK to be installed on your Centos 7. To install it run the following command:
sudo yum install java-1.8.0-openjdk-devel
Verify your installation by checking the Java version:
Output openjdk version "1.8.0_312" OpenJDK Runtime Environment (build 1.8.0_312-b07) OpenJDK 64-Bit Server VM (build 25.312-b07, mixed mode)
Now you need to add the Apache Cassandra repository on Centos 7.
Create the repository file with your favorite text editor, here we use vi:
sudo vi /etc/yum.repos.d/cassandra.repo
Then, 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
When are done, save and close the file.
Here you can install Apache Cassandra with the following command:
sudo yum install cassandra
Now start the Cassandra service on Centos 7 with the following command:
sudo service cassandra start
In your output you will see:
Output Starting cassandra (via systemctl): [ OK ]
If you want to enable the Cassandra service to start at boot, run the following command:
sudo chkconfig cassandra on
To verify that Apache Cassandra is active on Centos 7, you can use the nodetool program:
Your output should similar to this:
Output Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 103.65 KiB 256 100.0% e977023b-7dd7-4e89-9ee7-aaa4c45df51c rack1
Now you have Cassandra service up and running on your server.
Configure Apache Cassandra
Apache Cassandra’s configuration files are located in /etc/cassandra.
Cassandra is configured to listen on localhost.
If the client connecting to the database is also running on the same host you don’t need to change the default configuration file.
You can use a command-line utility that comes with the Cassandra to interact with it:
In your output you will see:
Output Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
Note: If you run the cqlsh and face with the below error and something similar to this:
Traceback (most recent call last): File "/usr/bin/cqlsh.py", line 169, in <module> from cqlshlib import cql3handling, cqlhandling, pylexotron, sslhandling, cqlshhandling ImportError: No module named cqlshlib
First, you need to find the path where cqlshlib exists:
find /usr/lib/ -name cqlshlib
The path obtained (in my case) is:
Export the path using the below variable name:
Now you can run the cqlsh again and connect to the test cluster.
you can rename your Apache Cassandra cluster on Centos 7.
From the Cassandra CQL terminal, run the following command to change the cluster name:
cqlsh> UPDATE system.local SET cluster_name = 'Orcacore Cluster' WHERE KEY = 'local';
Here we use Orcacore Cluster, you can replace it with your own name.
Type exit to quit from the Cassandra:
Now you need to edit the Cassandra configuration file on Centos 7.
Open the file with your favorite text editor:
sudo vi /etc/cassandra/default.conf/cassandra.yaml
Search for the Cluster_name line and change it to:
cluster_name: 'Orcacore Cluster'
Save and close the file when you are finished.
Clear the system cache with the following command:
nodetool flush system
Restart the Apache Cassandra on Centos 7 to apply the changes:
sudo systemctl restart cassandra
Now you can access the Cassandra CQL terminal again:
In your output you will see that your cluster name is changed:
Connected to Orcacore Cluster at localhost:9042. [cqlsh 5.0.1 | Cassandra 3.11.11 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
Type exit to exit from the cluster.
At this point, you learn to Install and Configure Apache Cassandra on Centos 7.
Hope you enjoy using it.