Apache Cassandra is an open-source NoSQL database management system that is developed to handle large-scale data across multiple servers. It can serve as an intensive database for business intelligence systems, and as a real-time data storage for online applications.
Cassandra adds a new virtual machine to its system with no downtime or interruption to any applications. In every Cassandra node, data is distributed across a certain cluster meaning that every node holds a different set of data. The database in this system is ideal for places that require maximum uptime and data redundancy, disaster recovery, and failovers.
Note: uptime and data redundancy, disaster recovery, and failovers are also affected by the type of hosting that you chose. Consult Hostadvice for the best web hosting services available.
In this tutorial, we will show you how to install Apache Cassandra and run node clusters on Ubuntu 18.04 server.
Pre-requisites
- Requires Java Platform installed in your system
- A root user to run the application.
Step 1: Installing Java
Cassandra requires Java application to run on your server. So, install the latest Java 8+ version. In this case, we will use Java PPA.
Start by running the following command:
sudo add-apt-repository -y ppa:webupd8team/java
Ensure your repository database is up-to-date by running the command below:
sudo apt-get update
Now install Java 8+ using the command below:
sudo apt-get -y install oracle-java8-installer
Confirm the Java version you have:
java -version
You should get an output like this:
java version "1.8.0_101" Java(TM) SE Runtime Environment (build 1.8.0_101-b13) Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Step 2: Downloading and Installing Cassandra
Download the latest version of Apache Cassandra. We shall use the official Cassandra package available on Apache Software Foundation. Ensure you add the software repository to verify that the package is available for your system.
echo "deb http://www.apache.org/dist/cassandra/debian 36x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.list
To avoid errors, add a public key to your Cassandra repository file as shown below:
gpg --keyserver pgp.mit.edu --recv-keys 749D6EEC0353B12C gpg --export --armor 749D6EEC0353B12C | sudo apt-key add -
Now update the Cassandra repositories.
sudo apt-get update
Go ahead and install Cassandra.
sudo apt-get install cassandra
Step 3: Activating Cassandra
To activate Cassandra on your system and confirm it’s working, run the following command:
systemctl enable cassandra systemctl start cassandra systemctl -l status cassandra
Check to confirm the status of your Cassandra cluster:
If your cluster is functioning properly, you should see a UN display and an output that look like this:
Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 103.51 KiB 256 100.0% c43a2db6-8e5f-4b5e-8a83-d9b6764d923d rack1
In this case, UN means;
U-Cluster is UP
N-Cluster is Normal
In case of any faults, open the file named cassandra-env.sh in your editor file to resolve this error:
vim /etc/cassandra/cassandra-env.sh
Step 4: Configuring Cassandra
To enable the login authentication for the user, create a backup of the configuration file on Cassandra i.e cassandra.yaml.
cp /etc/cassandra/cassandra.yaml /etc/cassandra/cassandra.yaml.backup Click to open the configuration file. vim /etc/cassandra/cassandra.yaml
Now, match your items in the file based on your projects requirement and how you intend to use Cassandra. Once you edit the configuration, restart Cassandra to apply these changes:
Ubuntu /etc/cassandra/cassandra.yaml authenticator: org.apache.cassandra.auth.PasswordAuthenticator authorizer: org.apache.cassandra.auth.CassandraAuthorizer role_manager: CassandraRoleManager roles_validity_in_ms: 0 permissions_validity_in_ms: 0
To add a superuser on Cassandra, open a command terminal and type cqlsh. Login to your default Cassandra account, using the details below:
cqlsh -u cassandra -p cassandra
Create your superuser account using the command below and include information of your choice in the brackets:
cassandra@cqlsh> CREATE ROLE [new_superuser] WITH PASSWORD = '[secure_password]' AND SUPERUSER = true AND LOGIN = true;
Exit and log in again with the new Cassandra superuser account and get rid off of the permissions present in the Cassandra account:
superuser@cqlsh> ALTER ROLE cassandra WITH PASSWORD = 'cassandra' AND SUPERUSER = false AND LOGIN = false; superuser@cqlsh> REVOKE ALL PERMISSIONS ON ALL KEYSPACES FROM cassandra;
Allow the new superuser account to take control by replacing the text in brackets with with your username used in the superuser account:
superuser@cqlsh> GRANT ALL PERMISSIONS ON ALL KEYSPACES TO [superuser];
Step 5: Connecting to a Cluster
To connect to the Cassandra Cluster, use the command line cqlsh on its interface:
cqlsh
Now connect to the cluster:
Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.6 | CQL spec 3.4.2 | Native protocol v4] Use HELP for help. cqlsh>
Now you should be connected to the Cassandra cluster.
Conclusion
By this point, you should know how to install Apache Cassandra on Ubuntu 18.04. If you are using Apache Cassandra for the first time, it is recommended that you use the details in Cassandra’s official documentation that’s available at https://cassandra.apache.org/doc/latest/.
Check out these top 3 Dedicated server hosting services:
- Check the recommendations for the best VPS and get a suitable one.