How To Install Apache Cassandra on AlmaLinux 9
Apache Cassandra is a highly scalable, distributed NoSQL database management system designed to handle large amounts of structured data across multiple commodity servers. Known for its exceptional performance, fault tolerance, and ability to handle big data workloads, Cassandra has become a popular choice for organizations dealing with massive datasets and high-traffic applications.
AlmaLinux 9, a free and open-source enterprise-grade Linux distribution, provides a stable and secure platform for running Apache Cassandra. Its compatibility with Red Hat Enterprise Linux (RHEL) makes it an excellent choice for deploying Cassandra in production environments.
In this comprehensive guide, we’ll walk you through the process of installing Apache Cassandra on AlmaLinux 9, from preparing your system to configuring and securing your Cassandra instance.
Prerequisites
Before we begin the installation process, ensure that your system meets the following requirements:
- A server running AlmaLinux 9 with at least 2 GB of RAM and 2 CPU cores
- Root or sudo access to the server
- A stable internet connection for downloading packages
- Basic familiarity with Linux command-line operations
It’s important to note that while these are the minimum requirements, for production environments, you should consider allocating more resources based on your specific workload and performance needs.
Preparing the System
Let’s start by updating your AlmaLinux 9 system and installing necessary dependencies:
- Update the system packages:
sudo dnf update -y
- Install essential tools:
sudo dnf install -y wget curl nano
Next, configure the firewall to allow Cassandra traffic. Cassandra uses several ports for communication, but the most important ones are 7000 (inter-node communication) and 9042 (client API):
sudo firewall-cmd --permanent --add-port=7000/tcp
sudo firewall-cmd --permanent --add-port=9042/tcp
sudo firewall-cmd --reload
These commands open the necessary ports and reload the firewall configuration to apply the changes.
Installing Java
Apache Cassandra requires Java to run. While Cassandra supports various Java versions, it’s recommended to use OpenJDK 8 or 11 for optimal performance and compatibility. Let’s install OpenJDK 11:
sudo dnf install -y java-11-openjdk-devel
After the installation, verify the Java version:
java -version
You should see output indicating that Java 11 is installed.
Next, set up the JAVA_HOME environment variable. Add the following line to your ~/.bashrc file:
export JAVA_HOME=$(dirname $(dirname $(readlink $(readlink $(which javac)))))
export PATH=$PATH:$JAVA_HOME/bin
Apply the changes by running:
source ~/.bashrc
Verify that JAVA_HOME is set correctly:
echo $JAVA_HOME
Adding Cassandra Repository
To install Apache Cassandra on AlmaLinux 9, we need to add the official Cassandra repository. First, import the Cassandra GPG key:
sudo rpm --import https://www.apache.org/dist/cassandra/KEYS
Now, create a new repository file for Cassandra:
sudo nano /etc/yum.repos.d/cassandra.repo
Add the following content to the file:
[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
Save the file and exit the editor.
Installing Apache Cassandra
With the repository set up, we can now install Apache Cassandra:
sudo dnf install -y cassandra
This command will download and install Cassandra along with its dependencies. Once the installation is complete, start the Cassandra service and enable it to start on boot:
sudo systemctl start cassandra
sudo systemctl enable cassandra
Verify that Cassandra is running:
sudo systemctl status cassandra
You should see output indicating that the Cassandra service is active and running.
Configuring Cassandra
The main configuration file for Cassandra is /etc/cassandra/conf/cassandra.yaml
. Let’s make some basic configurations to get started:
- Open the configuration file:
sudo nano /etc/cassandra/conf/cassandra.yaml
- Set the cluster name (replace “My Cluster” with your desired name):
cluster_name: 'My Cluster'
- Configure the seeds (for a single-node setup, use the server’s IP address):
seeds: "127.0.0.1"
- Set the listen address and RPC address to the server’s IP:
listen_address: your_server_ip rpc_address: your_server_ip
- Adjust the data directory if needed:
data_file_directories: - /var/lib/cassandra/data
Save the changes and exit the editor. After making these changes, restart Cassandra:
sudo systemctl restart cassandra
Securing Cassandra
By default, Cassandra doesn’t have authentication enabled. To secure your installation, follow these steps:
- Open the
cassandra.yaml
file:sudo nano /etc/cassandra/conf/cassandra.yaml
- Find the authenticator option and change it to PasswordAuthenticator:
authenticator: PasswordAuthenticator
- Save the file and restart Cassandra:
sudo systemctl restart cassandra
Now, let’s create a superuser account:
cqlsh -u cassandra -p cassandra
Once connected, create a new superuser and disable the default cassandra user:
CREATE USER admin WITH PASSWORD 'your_strong_password' SUPERUSER;
ALTER USER cassandra WITH PASSWORD 'disable_me_please' NOSUPERUSER;
Exit cqlsh and reconnect using the new admin account:
cqlsh -u admin -p your_strong_password
Testing the Cassandra Installation
Let’s verify that Cassandra is working correctly by creating a keyspace and table, and performing some basic operations:
CREATE KEYSPACE test_keyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1};
USE test_keyspace;
CREATE TABLE users (
id UUID PRIMARY KEY,
username TEXT,
email TEXT
);
INSERT INTO users (id, username, email) VALUES (uuid(), 'john_doe', 'john@example.com');
SELECT * FROM users;
If you see the inserted data when running the SELECT query, congratulations! Your Cassandra installation is working correctly.
Troubleshooting Common Issues
While installing and configuring Cassandra, you might encounter some issues. Here are some common problems and their solutions:
Address Binding Problems
If Cassandra fails to start due to address binding issues, ensure that the listen_address and rpc_address in cassandra.yaml are set to your server’s IP address or 0.0.0.0 for all interfaces.
Java-related Issues
If you encounter Java-related errors, verify that JAVA_HOME is set correctly and that the installed Java version is compatible with your Cassandra version.
Connectivity Problems
If you can’t connect to Cassandra from remote clients, check your firewall settings and ensure that the necessary ports (7000 and 9042) are open.
Performance Tuning
For optimal performance, consider adjusting the following settings in cassandra.yaml
:
concurrent_reads and concurrent_writes
: Set these to 8 times the number of CPU cores.memtable_allocation_type
: Set to offheap_buffers for better memory management.file_cache_size_in_mb
: Adjust based on your available system memory.
Congratulations! You have successfully installed Apache Cassandra. Thanks for using this tutorial for installing Apache Cassandra on your AlmaLinux 9 system. For additional help or useful information, we recommend you check the official Apache website.