
Apache Cassandra is a high-performance open-source distributed NoSQL database that handles large amounts of structured data with high availability and scalability. When you Install Apache Cassandra, it offers flexibility beyond traditional databases, as it does not rely on schema and efficiently manages structured, semi-structured, and unstructured data while providing operational simplicity using nodes.
This article explains how to install and configure Apache Cassandra on Debian 12. You will create a new single-node Cassandra cluster and enable access to the Cassandra query language shell (CQLSH) to manage the database server.
Before you begin:
4GB RAM and enable the limited user login feature.Apache Cassandra is not available in the default package repositories on Debian 12 and requires the Java Open JDK 11 package as a dependency to run. Follow the steps below to install all dependency packages and Cassandra repository sources using the APT package manager on your server.
Update the server's package information index.
Open the /etc/apt/source.list file.
Add the following directive at the end of the file.
Save and close the file.
Update the server's package information index to load the new repository.
Install the Open JDK 11 package.
View the Java version.
Output:
Add the Apache Cassandra repository to your APT sources.
Download the Apache Cassandra repository signing key.
Update your server's package information index to apply the new Cassandra repository.
Install Apache Cassandra.
View the cassandra system service status and verify that it's running.
Output:
The Cassandra service is active and running on your server based on the above output.
Query the Cassandra cluster node status and verify it's up.
Output:
Explore the Cassandra Python guide to seamlessly integrate the Apache Cassandra driver into your Python applications.
Apache Cassandra runs in a single-node cluster mode unless you modify the /etc/cassandra/cassandra.yaml main configuration file to detect new nodes and listen for connection requests on a specific address. Follow the steps below to configure Apache Cassandra and set up a new cluster on your server.
Stop the Cassandra service.
Remove all data directories to clear the default TestCluster files.
Open the cassandra.yaml Cassandra configuration file using a text editor like nano.
Find the cluster_name directive and replace TestCluster with your desired cluster name like MyCluster.
Find the seeds section and verify that it's set to your localhost node address 127.0.0.1:7000.
Cassandra uses seed nodes to bootstrap new nodes joining the cluster. Modify the seeds directive to include the IP addresses of other Cassandra nodes to connect to your cluster.
Find the listen_address directive and verify it's set to localhost.
The listen_address directive enables Cassandra to communicate with other nodes in a cluster. localhost enables Cassandra to only listen for connections on the server. Enter your server's IP address or 0.0.0.0 as the listen_address value to allow Cassandra to listen for incoming connections on all network interfaces.
Find the rpc_address directive and verify it's set to localhost.
Cassandra uses the rpc_address value to listen for CQLSH client connections using remote procedure calls (RPC) to the node.
Save and close the file.
Restart the Cassandra service to apply the configuration changes.
Discover how to install Apache Cassandra in Ubuntu to efficiently manage and scale your database operations.
Apache Cassandra uses plain authentication by default, making it vulnerable to unauthorized access. Enable password-based authentication to ensure data confidentiality and secure access to the Cassandra console. Follow the steps below to modify the default Cassandra configuration and enable authentication for all database users.
Open the main Cassandra configuration file.
Find the authenticator and authorizer directives, and change the values to PasswordAuthenticator and CassandraAuthorizer.
Save and close the file.
The above configuration enables password authentication and sets role-based access control.
Restart the Cassandra service to apply the configuration changes.
Log in to the Cassandra shell.
Create a new administrative user, such as admin and set a secure password to use with Apache Cassandra.
Exit the Cassandra shell.
Log in to the Cassandra shell as the new administrative user.
Exit the Cassandra shell.
Apache Cassandra uses a different data model compared to relational databases with the following key concepts:
Cassandra uses the CQL (Cassandra Query Language) and the CQLSH (Cassandra Query Language Shell) to create and manage databases. Follow the steps below to acess the Cassandra shell and perform common data modeling tasks.
Log in to the Cassandra shell as the administrative user you created earlier.
Create a new keyspace, such as example_keyspace.
A keyspace defines the replication strategy and is distributed across nodes in Apache Cassandra. Configure a replication strategy such as SimpleStrategy for single-node clusters or NetworkTopologyStrategy for multi-node clusters when creating keyspaces.
Switch to the keyspace.
Create a new table such as users and define 3 columns.
Insert new data in the users table using the INSERT command.
View the table data using the SELECT command.
Output:
Update a record in the table using the UPDATE command. For example, update the user's email using the respective user_id value.
Delete a record from the users table using the DELETE command.
Query the table data again and verify that it's empty.
Output:
Backing up Cassandra nodes enables you to recover the data in case of database failure or data loss. The Cassandra nodetool utility allows you to take snapshots and incremental backups. Follow the steps below to back up and restore Apache Cassandra Nodes using the nodetool utility.
Take a new snapshot from the example_keyspace your created earlier and store it as my_backup.
Output:
Open the main Cassandra configuration file to enable incremental backups.
Find the incremental_backups directive and change the value from false to true.
Restart Cassandra to apply the backup configuration changes.
Run the following command to copy the snapshot data to the keyspace directory in case of data loss.
Log in to the Cassandra shell.
Query the users table in the example_keyspace to verify the table data is available.
Apache Cassandra may display runtime and installation errors. Follow these steps to troubleshoot and fix common issues you may encounter installing Apache Cassandra.
View the Cassandra service status and verify it's running.
Query the default Apache Cassandra port 9042 and verify that it's actively listening for incoming connections.
View the Cassandra logs to find new entries and troubleshoot the error.
Ensure your username and password details are correct and run the following command to log in to the Cassandra shell.
Query the main Cassandra configuration and verify password authentication is enabled.
Output:
Log in as the Cassandra super user.
Reset your target user's password. Replace admin with your actual Cassandra user.
View the Cassandra memory usage.
Open the cassandra-env.sh file to increase the heap size.
Find the following heap directives and increase the Cassandra memory values.
Save and close the file.
Restart Cassandra to apply changes.
If you receive the following memory error:
Upgrade your server plan and verify that it has at least 4GB RAM to run Cassandra.
Check the Cassandra keyspace for large partitions. Replace keyspace_name with your actual keyspace and table_name with your target table.
Enable tracing to analyze query performance in the Cassandra shell.
Change the compaction strategy to improve the query response rate.
You have installed Apache Cassandra on your Debian 12 and performed database management tasks. You can integrate Cassandra with other nodes to create a multi-node cluster and set up applications to read and write data in the Cassandra database. For more information and advanced configuration options, visit the Apache Cassandra documentation.
0 Comments
Be the first to comment and share your perspective with the community.