
Apache Cassandra is a free open-source NoSQL database server commonly used with distributed systems. Cassandra can replicate high volumes of data across multiple cloud locations with low latency. When designing an application that requires high availability even in cases where a full data location goes down, Cassandra is the best choice for a database server. Examples of these applications include banking systems, healthcare management systems, social media applications, and e-commerce stores.
This guide explains how to install, use, and secure the Apache Cassandra Database Server on a Ubuntu 22.04 server.
Before you begin:
Deploy a Ubuntu 22.04 server with at least 8GB RAM in development, or 32GB in production.
Using SSH, access the server.
Switch to the sudo user account.
In this section, install the Apache Cassandra dependencies such as the Java run time environment as described in the steps below.
Install the Java development kit.
Install apt-transport-https and gnupg2 dependency packages.
Download and add the Apache Cassandra GPG key to the server.
Add the latest Apache Cassandra repository to the APT sources list.
The above command installs version 4.1. To use the latest version, visit the Apache Cassandra download page.
Update the server packages to enable the Cassandra repository.
Install Apache Cassandra.
When the installation is successful, Apache Cassandra takes an average of 2 minutes to start up. View the application logs to verify that it starts correctly.
Your output should look like the one below:
As displayed in the above output, the Apache Cassandra database is ready to use with a new default superuser role cassandra
Check the Apache Cassandra database server status, and verify that it's active.
Output.
Verify the Cassandra node status.
Output:
As displayed in the Apache Cassandra status outputs, the database server is active and ready to use.
Apache Cassandra uses the cqlsh command line tool that accepts Cassandra Query Language (CQL) commands when interacting with the database server. In this section, access the database server, and add sample data as described in the steps below.
Log in to the Cassandra database server.
Create a new sample keyspace my_company.
The above command creates a new my_company keyspace. In Cassandra, a keyspace is an object that stores tables, and defines how data replication works on different nodes.
Switch to the keyspace.
Create a new sample products table with the following data.
The above code creates a table with the product_id column which is a PRIMARY KEY that uniquely identifies records in the products table. The product_name column stores product names. retail_price stores the actual price that customers pay for a product. product_id uses the Universal Unique Identifier (UUID) data type. The data type ensures uniqueness of the product_id value in the Cassandra cluster even when some nodes are down.
Add sample data to the products table.
In the above commands, the UUID() function generates a new product_id for each record.
View the products table data.
Output:
Exit the Cassandra database console.
It's important to secure the Apache Cassandra database server from unauthorized access. In this section, secure Cassandra with a password to harden your database server security as described in the steps below.
Use a text editor such as Nano, edit the main Cassandra configuration file.
Find the following authenticator: directive.
Change the authenticator: value from AllowAllAuthenticator to PasswordAuthenticator below.
Save and close the file.
In the above configuration, the default AllowAllAuthenticator does not prompt users for a password to access the Cassandra database. But, PasswordAutheticator enforces password authentication for all system users.
Restart the Apache Cassandra server to save changes.
The above command restarts Apache Cassandra. Wait for at least 1 minute, before re-accessing the database console. Check the application logs to verify that the startup is complete.
Output:
Log in to the Cassandra database console using the default username (cassandra), and password (cassandra).
Create a new super-user account. Replace db_administrator with your desired user, and EXAMPLE_PASSWORD with a strong password.
Exit the Cassandra database console.
To verify that the user is available, log in to the Cassandra database server as the new user.
When prompted, enter the user password you created earlier, and press Enter to proceed.
To tighten server security, disable the default super-user cassandra.
Exit the database console.
Verify that the default user account can no longer access the database server.
Output.
In this guide, you installed and used the Apache Cassandra database server on a Ubuntu 22.04 Vultr server. Using the cqlsh command, you accessed the database server, and used CQL commands to create a sample keyspace, then, added data to the table. For more information and configuration options, visit the Apache Cassandra official documentation.
0 Comments
Be the first to comment and share your perspective with the community.