How to Install Cassandra Distributed Database on CentOS 7
This tutorial exists for these OS versions
On this page
Cassandra is a free and open source distributed database management system that can be used to handle large amounts of data across many servers. It is reliable, clusterable and specialy designed to handle very large amounts of structured data. Cassandra also supports replication and multi-data center replication for redundancy, failover, and disaster recovery.
In this tutorial, we will learn how to install and configure Cassandra on CentOS 7.
Prerequisite
- A server running CentOS 7.
- A non-root user with sudo privileges setup on your server.
Getting Started
Before starting, update your system with the latest version with the following command:
sudo yum update -y
Cassandra is written in Java, so you will need to install Java to your system. You can install Java by just running the following command:
sudo yum install java -y
After installing Java, you can verify the version of the Java with the following command:
sudo java -version
You should see the Java version in the following output:
openjdk version "1.8.0_151" OpenJDK Runtime Environment (build 1.8.0_151-b12) OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)
Install Cassandra
By default, Cassandra is not available in CentOS 7 default repository. So you will need to add the official Apache Software Foundation repositories to your system. You can do this by creating cassandra.repo file inside /etc/yum.repos.d directory:
sudo nano /etc/yum.repos.d/cassandra.repo
Add the following line:
[cassandra] name = DataStax Repo for Apache Cassandra baseurl = http://rpm.datastax.com/community enabled = 1 gpgcheck = 0
Save and close the file when you are finished, then update the repository with the following command:
sudo yum update -y
Next, install Cassandra using the following command:
sudo yum install dsc20 -y
After installing Cassandra, start the Cassandra service and enable it to start on boot time with the following command:
sudo systemctl start cassandra
sudo systemctl enable cassandra
You can also check the status of the Cassandra service using the following command:
sudo systemctl status cassandra
If everything is fine, you should see the following output:
? cassandra.service - SYSV: Starts and stops Cassandra Loaded: loaded (/etc/rc.d/init.d/cassandra; bad; vendor preset: disabled) Active: active (exited) since Sun 2017-12-17 17:53:58 IST; 12s ago Docs: man:systemd-sysv-generator(8) Process: 15323 ExecStart=/etc/rc.d/init.d/cassandra start (code=exited, status=0/SUCCESS) Dec 17 17:53:55 centOS-7 systemd[1]: Starting SYSV: Starts and stops Cassandra... Dec 17 17:53:56 centOS-7 su[15332]: (to cassandra) root on none Dec 17 17:53:58 centOS-7 cassandra[15323]: Starting Cassandra: OK Dec 17 17:53:58 centOS-7 systemd[1]: Started SYSV: Starts and stops Cassandra.
Connect and Check Cassandra Cluster
Cassandra is now up and running. It's time to verify and connect Cassandra Cluster.
You can verify the Cassandra Cluster status with the following command:
sudo nodetool status
If everything is fine, you should see the following output:
Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 65.15 KB 256 100.0% 516af85e-2e6a-454a-b27f-6eacafa6b978 rack1
Next, connect the Cassandra Cluster using the cqlsh command as shown below:
cqlsh
You should see the following output:
Connected to Test Cluster at localhost:9160. [cqlsh 4.1.1 | Cassandra 2.0.17 | CQL spec 3.1.1 | Thrift protocol 19.39.0] Use HELP for help. cqlsh>
Next, exit from the Cassandra command line interface with the following command:
cqlsh> exit