

How to Install Apache Cassandra on AlmaLinux / Rocky Linux 8
source link: https://www.howtoforge.com/how-to-install-apache-cassandra-on-almalinux-rocky-linux-8/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

How to Install Apache Cassandra on AlmaLinux / Rocky Linux 8
Apache Cassandra is an open-source NoSQL distributed database management system. Cassandra can be scaled horizontally by adding more nodes across which data is replicated automatically. Nodes can be added or removed without any downtime. The nodes can be organized logically as a cluster or a ring and set up across multiple data centers to improve speed and reliability for high-performance applications.
In this tutorial, we will learn how to install Apache Cassandra on AlmaLinux and Rocky Linux 8 OS. The commands for both the Operating systems will be identical unless specified otherwise.
Prerequisites
-
A Server running AlmaLinux or Rocky Linux with a minimum of 2GB of RAM.
-
A non-sudo user with root privileges.
-
Everything is updated.
$ sudo dnf update
Step 1 - Install Java
Apache Cassandra requires Java 8 to function. The latest version of Cassandra includes experimental support for Java 11, but for our tutorial, we will stick to using Java 8.
$ sudo dnf install java-1.8.0-openjdk java-1.8.0-openjdk-devel
Confirm the Java installation.
$ java -version 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)
Step 2 - Install Apache Cassandra
The first step is to add Cassandra's official repository.
Run the following command to create the repository file /etc/yum.repos.d/cassandra.repo
and enter the details.
$ sudo tee /etc/yum.repos.d/cassandra.repo <<EOF > [cassandra] > name=Apache Cassandra > baseurl=https://www.apache.org/dist/cassandra/redhat/40x/ > gpgcheck=1 > repo_gpgcheck=1 > gpgkey=https://www.apache.org/dist/cassandra/KEYS > EOF
Now that the repo file is created install, Cassandra.
$ sudo dnf install cassandra -y
Step 3 - Install Cqlsh
We will use the CQL Shell (cqlsh) tool to interact with Cassandra. The tool is compatible with Python 2.7 or Python 3.6+. For our tutorial, we will be using Python 3.8. Install Python 3.8.
$ sudo dnf install python38
Set Python 3.8 as the default Python version.
$ sudo update-alternatives --config python There are 3 programs which provide 'python'. Selection Command ----------------------------------------------- *+ 1 /usr/libexec/no-python 2 /usr/bin/python3 3 /usr/bin/python3.8 Enter to keep the current selection[+], or type selection number: 3
You will be presented with multiple options. We will choose number 3 to set Python 3.8 as the default version in our case.
Confirm the Python installation.
$ python --version Python 3.8.8
After using the update-alternatives
utility, you don't need to use the python3
command.
Install cqlsh using pip Python package manager.
$ pip3 install --user cqlsh
Confirm the cqlsh install.
$ cqlsh --version cqlsh 6.0.0
Step 4 - Create a Systemd Unit file for Cassandra
Create and open the /etc/systemd/system/cassandra.service
for editing.
$ sudo nano /etc/systemd/system/cassandra.service
Paste the following code in it.
[Unit] Description=Apache Cassandra After=network.target [Service] PIDFile=/var/run/cassandra/cassandra.pid User=cassandra Group=cassandra ExecStart=/usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid Restart=always [Install] WantedBy=multi-user.target
Save the file by pressing Ctrl + X and entering Y when prompted.
Reload the service daemon.
$ sudo systemctl daemon-reload
Enable and start the Cassandra service.
$ sudo systemctl enable cassandra --now
Check the status of the service.
$ sudo systemctl status cassandra ? cassandra.service - Apache Cassandra Loaded: loaded (/etc/systemd/system/cassandra.service; enabled; vendor preset: disabled) Active: active (running) since Thu 2021-12-30 11:07:43 UTC; 12s ago Main PID: 4679 (java) Tasks: 48 (limit: 23696) Memory: 1.3G CGroup: /system.slice/cassandra.service ??4679 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOutOfMemoryError -Xss256>
You can also verify the status using the nodetool
command.
$ nodetool status Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 69.09 KiB 16 100.0% 2fe7ccae-2af9-4841-9bff-bffa29f10dc5 rack1
Step 5 - Configure Cassandra
The default location of configuration files for Cassandra is at /etc/cassandra
. The default location for the log and data directories is /var/log/cassandra
and /var/lib/cassandra
.
JVM level settings such as heap size can be set via the /etc/cassandra/conf/cassandra-env.sh
file. You can pass additional JVM command-line arguments to the JVM_OPTS
variable. The arguments are passed to Cassandra when it starts.
5.1 Enable User Authentication
To enable user authentication, first, take a backup of the /etc/cassandra/conf/cassandra.yaml
file.
$ sudo cp /etc/cassandra/conf/cassandra.yaml /etc/cassandra/conf/cassandra.yaml.backup
Open the cassandra.yaml
file for editing.Advertisement
$ sudo nano /etc/cassandra/conf/cassandra.yaml
Locate the following parameters in this file.
authenticator: AllowAllAuthenticator authorizer: AllowAllAuthorizer roles_validity_in_ms: 2000 permissions_validity_in_ms: 2000
Change the values of the parameters as given below.
. . . authenticator: org.apache.cassandra.auth.PasswordAuthenticator authorizer: org.apache.cassandra.auth.CassandraAuthorizer roles_validity_in_ms: 0 permissions_validity_in_ms: 0 . . .
You can configure other settings based on your requirements. If they are commented, then uncomment them out.
Once finished, save the file by pressing Ctrl + X and entering Y when prompted.
Restart Cassandra to enable the changed settings.
$ sudo systemctl restart cassandra
5.1.1 - Add an Administrator Superuser
Now that we have enabled authentication, we need to create a user. To do that, we will use the Cassandra Command shell utility. Log in with the credentials for the default user cassandra
.
$ cqlsh -u cassandra -p cassandra
Create a new superuser. Replace [username]
and [yourpassword]
with your credentials.
cassandra@cqlsh> CREATE ROLE [username] WITH PASSWORD = '[yourpassword]' AND SUPERUSER = true AND LOGIN = true;
Log out.
cassandra@cqlsh> exit
Log back in with the new superuser account.
$ cqlsh -u username -p yourpassword
Remove the elevated permissions from the default cassandra
account.
username@cqlsh> ALTER ROLE cassandra WITH PASSWORD = 'cassandra' AND SUPERUSER = false AND LOGIN = false; username@cqlsh> REVOKE ALL PERMISSIONS ON ALL KEYSPACES FROM cassandra;
Grant all permissions to the superuser account.
username@cqlsh> GRANT ALL PERMISSIONS ON ALL KEYSPACES TO '[username]';
Log out.
username@cqlsh> exit
5.2 - Edit the Console Configuration File
If you want to customize the Cassandra Shell, you can do so by editing the cqlshrc
file. The default location for the file is in the ~/.cassandra
directory. If you want to load it from a different directory, you can pass the argument --cqlshrc /customdirectory
to the cqlsh
tool while running.
You can find a sample file at /etc/cassandra/conf/cqlshrc.sample
containing all the settings you can configure regarding the Cassandra Shell.
Copy and rename the example file to the ~/.cassandra
directory.
$ sudo cp /etc/cassandra/conf/cqlshrc.sample ~/.cassandra/cqlshrc
Update the cqlshrc
file with the required permissions.
$ sudo chmod 600 ~/.cassandra/cqlshrc $ sudo chown $USER:$USER ~/.cassandra/cqlshrc
Open the file for editing.
$ nano ~/.cassandra/cqlshrc
We will configure the shell to automatically log in with the superuser credentials. Find the following section and fill it in with your username and password.
.... [authentication] ;; If Cassandra has auth enabled, fill out these options username = [superuser] password = [password] ....
Edit any other settings you want to change. Some of the settings are commented using ;;
. Uncomment them by removing double semi-colons and then make the change.
Once finished, save the file by pressing Ctrl + X and entering Y when prompted.
Login to the Cassandra shell with your new changes.
$ cqlsh Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5] Use HELP for help. username@cqlsh>
5.3 - Rename the Cluster
Finally, we will rename the cluster name from Test Cluster to your chosen name.
Log into the cqlsh
terminal.
$ cqlsh
Replace the [clustername]
with your new cluster name in the command below.
username@cqlsh> UPDATE system.local SET cluster_name = '[new_name]' WHERE KEY = 'local';
Exit the shell
username@cqlsh> exit
Open the file /etc/cassandra/conf/cassandra.yaml
for editing.
$ sudo nano /etc/cassandra/conf/cassandra.yaml
Replace the value of the variable cluster_name
with the name of your choosing.
... # The name of the cluster. This is mainly used to prevent machines in # one logical cluster from joining another. cluster_name: '[new_name]' ...
Once finished, save the file by pressing Ctrl + X and entering Y when prompted.
Clear the Cassandra system cache.
$ nodetool flush system
Restart Cassandra.
$ sudo systemctl restart cassandra
Log in to the shell to see the new name.
$ cqlsh Connected to HowtoForge Cluster at 127.0.0.1:9042 [cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5] Use HELP for help. username@cqlsh>
Conclusion
In this tutorial, you learned how to install Apache Cassandra on an AlmaLinux or Rocky Linux server. You also learned how to add user authentication and perform some basic configurations. To learn more, visit the official Cassandra documentation. If you have any questions, post them in the comments below.
Recommend
-
41
Install OpenProject on CentOS 8|Rocky Linux 8|AlmaLinux 8OpenProject is a very powerful project management suite to support project teams throughout the entire project life cycle. This guide will discuss how you can install OpenProject CE on...
-
5
Install PostGIS on Rocky Linux 8|CentOS 8|AlmaLinux 8Search ComputingForGeeksThis guide will walk you throug...
-
51
Install Open vSwitch on Rocky Linux 8If you’ve been in Linux ecosystem for a while, the term OVS or Open vSwitch should ring a bell. In Virtualization and Cloud Computing environments such as OpenStack, Open vSwitch is a key component in Netw...
-
34
How To Install oVirt Engine on Rocky Linux 8|AlmaLinux 8Virtualization allows for the partitioning of a single compute machine into multiple virtual computers, each with its own operating system. The Virtual Machines created through Virtualiz...
-
98
Install Zimbra 9 Mail Server on Rocky Linux 8|AlmaLinux 8|RHEL 8Search ComputingForGeeksZimbra
-
7
<?xml encoding="utf-8" ??>If you're looking for a powerful open-source distributed database system, but don't want to spend hours configuring and installing it, then Cassandra is the right solution for yo...
-
6
How To Install Terraform On AlmaLinux 8, CentOS 8 and Rocky Linux 8 Terraform is a tool for building and maintaining a virtual server infrastructure; it supports multiple cloud providers in one project. Terraform achieves state mana...
-
5
Install Apache Cassandra on AlmaLinux 8|Oracle Linux 8Many organizations handling large unstructured data require a highly scalable and available tool. Apache Cassandra is the most popular tool for this task.Apache Cassandra
-
7
Install and Use Bacula Backup on Rocky Linux 8|AlmaLinux 8Bacula can be defined as a set of programs used to manage backup, restoration, and verification of data over a network. This open-source tool allows one to create backups and restore t...
-
20
Install Tesseract OCR 5 on Rocky Linux 8|AlmaLinux 8In day-to-day activities, we encounter situations where we need to extract text from documents. This is where OCR software comes in. OCR (Optical Character Recognition) is a technology used...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK