Apr 08, 2019
How to Install Cassandra on Ubuntu 18.04
NoSQL database managers are ideal for clusters of data and scalable applications. Among them is Cassandra from the Apache Foundation. In this tutorial, we will show you how to set up install Cassandra on Ubuntu 18.04.
Database managers are essential for application development. One of the main reasons being, they are the ones that provide secure storage of the application data. In this sense, the best-known database managers are the SQL types with PostgreSQL, MySQL, and MariaDB as the most used by the community. Of course, there are other solutions more focused on the business environment such as Oracle, DB2 or Microsoft SQL server. As previously mentioned, NoSQL types like Cassandra are great for other uses, that we’ll delve into right now!
Cassandra a NoSQL Database manager
Cassandra is a NoSQL database manager that belongs to the Apache foundation. It is open source and available for several Linux distributions, among them, Ubuntu 18.04. Cassandra is fast in handling stored data, however, its main advantage is scalability.
With Cassandra, it is very advantageous to create large applications with a lot of data because it has an excellent resource manager. Besides this, it has fault tolerance which means that almost no data is lost in case of problems. So if we need scalability and high availability without compromising performance, Cassandra is ideal.
Let’s install Cassandra on Ubuntu 18.04 and start working with it!
Install Cassandra on Ubuntu 18.04
Thanks to Cassandra’s .deb packages repository the installation will be easy. Let’s begin:
1. Access Your Server Through SSH
2. Add the Cassandra Repository File
After that, we need to add the Cassandra repository to our repository file. To do that, type the following command in the command line:
echo "deb http://www.apache.org/dist/cassandra/debian 39x main" | sudo tee -a /etc/apt/sources.list.d/cassandra.sources.list
3. Add the GPG Key
To avoid problems with the repository, add the GPG key and increase the security of the repository. First, we need to install curl if it is not present on your system:
sudo apt install curl
Then we can add the key with the following command:
curl https://www.apache.org/dist/cassandra/KEYS | sudo apt-key add -
4. Install Cassandra on Ubuntu
Next, we can start the installation of Cassandra. First, we refresh the repositories and then proceed to install Cassandra on Ubuntu:
sudo apt update
sudo apt install cassandra
5. Enable and Start Cassandra
At the end of the installation, we have to enable the Cassandra service to start automatically when the system boots. In addition, we should start it manually. We can do it with the following commands:
sudo systemctl enable cassandra
sudo systemctl start cassandra
6. Verify The Installation
To check if the installation has been successful, we can check the status of the service. To do this, run the following command:
sudo systemctl status cassandra
Configure Cassandra on Ubuntu 18.04
Cassandra’s default configuration is valid if we are going to run Cassandra on a single node.
On the other hand, if Cassandra will be used in a cluster or by several nodes simultaneously, it is convenient to make some modifications to the configuration file.
The Cassandra configuration file is called cassandra.yaml and is located at /etc/cassandra/. We can open it with our favorite text editor and modify some options:
sudo nano /etc/cassandra/cassandra.yaml
First of all, we have to change the name of the cluster. Look for the cluster_name parameter and assign the name you want:
Then, it is a good idea to change the data storage port. To do this, look for the storage_port parameter and assign one. Remember that it must be an available port in the firewall for everything to work correctly:
Finally, we look for the seed_provider parameter and in the seeds section, we add the IP addresses of the nodes that make up the cluster separated by a comma
Once you’re done, save the file and reload Cassandra.
sudo systemctl reload cassandra
Now we can start to work with Cassandra.
Cassandra is a very useful database manager that we can take advantage of. It is designed for large applications that require flexibility and scalability. In this tutorial, we have learned how to install Cassandra on Ubuntu 18.04.
Cassandra is a very powerful application, that has many configuration options. However, we have observed the most basic ones that will help you start working with it right away. If you want to learn more, we recommend checking the official documentation! Happy developing.