Apache Cassandra is an open source code with high performance NoSQL database management system without any single error. Apache Cassandra uses a cluster model instead using the table model seen in MySQL / PostgreSQL. Cassandra is suitable for applications that cannot afford to lose data. Data is automatically replicated to multiple nodes for fault tolerance. Failed nodes can be replaced automatically without downtime.
Apache Cassandra is the best choice for you if you are looking for scalability, high availability and high performance.
In this tutorial, we will show you how to install Apache Cassandra on CentOS 8.
- A server running CentOS 8 with at least 2 GB of RAM.
- A root password is set on your system.
Before you begin, it is recommended that you update your server to the latest stable version. You can update your server with the following command:
Once the server is updated, restart it to apply the changes.
Apache Cassandra requires OpenJDK 8 and Python2 to be installed on the system. You can install OpenJDK 8 and Python2 with the following command:
dnf install java-1.8.0-openjdk-devel python2
After both packages are installed, you can verify the Java version with the following command:
You should see the following output:
openjdk version "1.8.0_232" OpenJDK Runtime Environment (build 1.8.0_232-b09) OpenJDK 64-bit server VM (build 25.232-b09, mixed mode)
Installing Apache Cassandra
By default, Apache Cassandra is not available in the CentOS 8 repository. So you have to create a repo for that. You can create a new repo file /etc/yum.repos.d/cassandra.repo as shown below:
nano /etc/yum.repos.d/cassandra.repo Chapter19659010 ?? Add the following lines:[cassandra] name = DataStax Repo for Apache Cassandra baseurl = http://rpm.datastax.com/community enabled = 1 gpgcheck = 0
Save and close the file, then install Apache Cassandra with the following command:
dnf install dsc20
When you are done with the installation, you can proceed to the next step
Create a Systemd device file for Cassandra  By default, the Apache Cassandra package cannot generate a service file for itself. So you need to create a systemd service file to manage the Cassandra service. You can create it with the following command:
nano /etc/systemd/system/cassandra.service tu 1919919919 Add the following lines:[Unit] Description = Apache Cassandra After = network. Goal [Service] PidFile = / var / run / cassandra / cassandra.pid User = cassandra The group = cassandra ExecStart = / usr / sbin / cassandra -f -p /var/run/cassandra/cassandra.pid Restart = always [Install] WantedBy = multi-user.target
Save and close the file. Then reload the system daemon with the following command:
Then start the Cassandra service and enable it to restart after system startup with the following command:
systemctl start cassandra
systemctl enable cassandra
You can also check the status of the Cassandra service with the following command:
systemctl status cassandra
You should see the following output:? cassandra.service - Apache Loaded: loaded (/etc/systemd/system/cassandra.service; disabled; vendor setting: disabled) Active: active (running) since Sat 2019-12-07 01:25:26 EST; 1min 51s ago Main PID: 1888 (java) Details: 53 (limit: 25044) Memory: 272.7M CGroup: /system.slice/cassandra.service ?? 1888 java -ea -javaagent: /usr/share/cassandra/lib/jamm-0.2.5.jar -XX: + CMSKlassUnloading Enabled -XX: + UseThreadPriorities -XX: Threa> Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,054 Writing [email protected] (10104/101040 serialized / live bytes, 259 ops) Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,118 Completed flushing /var/lib/cassandra/data/system/local/system-local-jb-4-Data.db> Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,124 Compacting [SSTableReader (path = & # 39; / var / lib / cassandra / data / system / local / system-local-> December 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,169 Node localhost / 127.0.0.1 state jumps to normal Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,294 Compacted 4 stables for [/var/lib/cassandra/data/system/local/system-local-jb-5,].> Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,322 Starts listening to CQL clients at localhost / 127.0.0.1: 9042 ... December 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,376 Using TFramedTransport with a maximum frame size of 15728640 bytes. Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,378 Binding thrift to localhost / 127.0.0.1: 9160 Dec 7 01:25:29 centos8 cassandra : INFO 01: 25: 29,391 Using synchronous / threadpool thrift server at localhost: 9160 Dec 07 01:25:29 centos8 cassandra : INFO 01: 25: 29,422 Listening to frugal customers ...
Test Apache Cassandra Installation
Apache Cassandra is now installed and running on your server. You can verify whether it is running or not with the following command:
You should see the following command:Datacenter: datacenter1 ======================= Status = Up / Down | / State = Normal / Leaving / Joining / Moving - Address load tags own (effective) host ID racks UN 127.0.0.1 46.11 KB 256 100.0% 2a680007-8c30-4bde-9a3f-9fa212b96d11 rack1
Configuring Apache Cassandra
By default, Cassandra is configured to accept the connection only from localhost.
You can also log in to Cassandra through Cassandra Query Language. To access the CQL shell, run the following command:
You should see the following output:Connected to Test Cluster on 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>
In the above output you should see that the Cassandra cluster is called "Test Cluster". You can also change this default cluster name.
To do so, log on to the CQL shell with the following command:
Then run the following command to change the cluster name to "HowtoForge Cluster" shown below:
cqlsh> UPDATE system. local SET cluster_name = & # 39; HowtoForge Cluster & # 39; WHERE KEY = & # 39; local & # 39 ;;
Then exit from the shell with the following command:
Then you must also edit the cassandra.yaml configuration file and define your new cluster name:
nano /etc/cassandra/default.conf/cassandra.yamlebrit19659010 MinnesotaEdit the following line:cluster_name: "HowtoForge Cluster"
Save and close the file when you are done. Then clear the system cache with the following command:
nodetool flush system
Finally, restart the Apache Cassandra service to apply the new configuration:
systemctl restart cassandra
Log in to the CQL shell with the following command:  cqlsh
You should see that the cluster name is now changed to "HowtoForge Cluster":Connected to HowtoForge 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>
Congratulations! you have installed and configured Apache Cassandra with success on CentOS 8. Please ask me if you have any questions.