How To Install Apache Cassandra On Debian 11
In this article we will learn how to install Apache Cassandra version 4.0 on Debian 11 (Bullseye) operating system. Apache Cassandra is a popular open-source distributed database management system that is designed to handle large amounts of data across many commodity servers, providing high availability with no single point of failure. It is a NoSQL database, which means it doesn’t use the traditional table-based relational database model. Instead, it uses a column-family data model, which allows for a flexible schema that can handle large amounts of data.\
Here are some key features of Apache Cassandra:
- Distributed architecture: Cassandra is designed to run on a cluster of commodity hardware, providing high availability and fault tolerance. Data is replicated across multiple nodes, ensuring that it is always available, even if some nodes fail.
- High scalability: Cassandra can scale horizontally by adding more nodes to the cluster. This allows it to handle large amounts of data and high traffic loads with ease.
- Flexible data model: Cassandra’s column-family data model allows for a flexible schema that can handle a wide range of data types, including structured, semi-structured, and unstructured data.
- High performance: Cassandra is designed to provide high throughput and low latency, making it ideal for use cases that require fast data access and real-time analytics.
- Tunable consistency: Cassandra allows you to configure the level of consistency you need for your application, from eventual consistency to strong consistency.
- Open-source and community-driven: Cassandra is an open-source project with a large and active community of developers and users.
To use Apache Cassandra, we will need to install it on our system or use a cloud-based service that provides Cassandra hosting. The installation process will vary depending on our operating system and the version of Cassandra you want to install.
Apache Cassandra Installation
Prerequisites
In this tutorial we will use Apache Casandra 4.0, before we proceed to the Apache Cassandra installation process, there are several prerequisites that must be met, namely :
- A Debian 11 operating system.
- Java installed on the system.
- It’s recommended that you use a fresh OS install to prevent any potential issues.
- A root user access or normal user with administrative privileges.
As mentioned above, Apache Cassandra requires Java installed on the system, then we need to verify it first. To verify Java installed on the system, we will submit following command line :
$ java -version
Output :
ramansah@otodiginet:~$ java -version openjdk version "11.0.12" 2021-07-20 OpenJDK Runtime Environment (build 11.0.12+7-post-Debian-2) OpenJDK 64-Bit Server VM (build 11.0.12+7-post-Debian-2, mixed mode, sharing)
If our system has no Java installed on the system, then we will install it first. For Installing OpenJDK 11 on Debian 11 BullsEye can be found at How To Install OpenJDK 11 On Debian 11 article.
The Apache Cassandra installation will be consist of several steps, as mentioned below :
- Update Debian 11 Local Repository
- Adding Apache Cassandra Repository
- Installing Apache Cassandra
- Verify Cassandra Installation
1. Update Debian 11 Local Repository
Before installing Apache Cassandra on Debian 11 Bullseye, we have to prepare the environment first. We will update our system to ensure that we have the latest security patches and updates. We can do this by running the appropriate command Debian 11 system.
$ sudo apt update
2. Adding Apache Cassandra Repository
In this step, we will add Apache Cassandra repository to our Debian 11 system. For this purpose, we will submit the following command line :
$ curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add -
Output :
ramansah@otodiginet:~$ curl https://downloads.apache.org/cassandra/KEYS | sudo apt-key add - % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 Warning: apt-key is deprecated. Manage keyring files in trusted.gpg.d instead (see apt-key(8)). 100 267k 100 267k 0 0 61909 0 0:00:04 0:00:04 --:--:-- 63193
3. Installing Apache Cassandra
In this step, we will install Apache Cassandra on Debian 11 operating system. We will do following commands line:
$ sudo apt update $ sudo apt install -y cassandra
Output :
ramansah@otodiginet:~$ sudo apt update Hit:1 http://deb.debian.org/debian bullseye InRelease Hit:2 http://ftp.debian.org/debian stretch-backports InRelease Hit:3 http://security.debian.org/debian-security bullseye-security InRelease Hit:4 http://deb.debian.org/debian bullseye-updates InRelease Hit:5 http://deb.debian.org/debian bullseye-backports InRelease Get:6 https://downloads.apache.org/cassandra/debian 40x InRelease [3,902 B] Get:7 https://downloads.apache.org/cassandra/debian 40x/main amd64 Packages [685 B] Fetched 4,587 B in 3s (1,317 B/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done All packages are up to date.
ramansah@otodiginet:~$ sudo apt install -y cassandra Reading package lists... Done Building dependency tree... Done Reading state information... Done Suggested packages: cassandra-tools The following NEW packages will be installed: cassandra 0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. Need to get 47.3 MB of archives. After this operation, 58.5 MB of additional disk space will be used. Get:1 https://downloads.apache.org/cassandra/debian 40x/main amd64 cassandra all 4.0.1 [47.3 MB] Fetched 47.3 MB in 1min 51s (425 kB/s) Selecting previously unselected package cassandra. (Reading database ... 136457 files and directories currently installed.) Preparing to unpack .../cassandra_4.0.1_all.deb ... Unpacking cassandra (4.0.1) ... Setting up cassandra (4.0.1) ... Adding group `cassandra' (GID 123) ... Done. vm.max_map_count = 1048575 net.ipv4.tcp_keepalive_time = 300 update-rc.d: warning: start and stop actions are no longer supported; falling back to defaults
By default Apache Cassandra will be started after installation was completed. Then we will check its service by submitting command line :
$ sudo systemctl status cassandra
Output :
ramansah@otodiginet:~$ sudo systemctl status cassandra ● cassandra.service - LSB: distributed storage system for structured data Loaded: loaded (/etc/init.d/cassandra; generated) Active: active (running) since Fri 2021-09-24 12:37:11 EDT; 1min 5s ago Docs: man:systemd-sysv-generator(8) Process: 7487 ExecStart=/etc/init.d/cassandra start (code=exited, status=0/SUCCESS) Tasks: 58 (limit: 4623) Memory: 1.4G CPU: 15.289s CGroup: /system.slice/cassandra.service └─7595 /usr/bin/java -ea -da:net.openhft... -XX:+UseThreadPriorities -XX:+HeapDumpOnOut> Sep 24 12:37:11 otodiginet systemd[1]: Starting LSB: distributed storage system for structured data.> Sep 24 12:37:11 otodiginet systemd[1]: Started LSB: distributed storage system for structured data.
4. Verify Apache Cassandra Installation
When Apache Cassandra installation was competed done, then we will verify if Apache Cassandra was installed on the system. For this purpose, we will use a command line to check the node status.
$ sudo nodetool status
Output :
ramansah@otodiginet:~$ sudo nodetool status Datacenter: datacenter1 ======================= Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 127.0.0.1 69.04 KiB 16 100.0% e014e9c1-7c2c-4c4f-9c76-f8981a0c5b75 rack1
5. CQLSH (Cassandra Query Language Shell)
CQLSH (Cassandra Query Language Shell) is a command-line tool that allows you to interact with Apache Cassandra using the Cassandra Query Language (CQL). CQL is a SQL-like language that is used to interact with Cassandra’s column-family data model.
To use CQLSH, you will need to have Apache Cassandra installed on your system. Once Cassandra is installed, you can start CQLSH by opening a terminal or command prompt and entering the following command:
$ cqlsh
Output :
ramansah@otodiginet:~$ cqlsh Connected to Test Cluster at 127.0.0.1:9042 [cqlsh 6.0.0 | Cassandra 4.0.1 | CQL spec 3.4.5 | Native protocol v5] Use HELP for help. cqlsh>
Example of using CQLSH
1. Create a keyspace:
CREATE KEYSPACE mykeyspace WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 3};
2. Create a table
CREATE TABLE mytable ( id int PRIMARY KEY, name text, age int );
3. Insert data into a table:
INSERT INTO mytable (id, name, age) VALUES (1, 'John', 30);
4. Query data in a table:
SELECT * FROM mytable WHERE age > 25;
5. Update data in a table :
UPDATE mytable SET age = 35 WHERE id = 1;
6. Delete data from a table:
DELETE FROM mytable WHERE id = 1;
Conclusion
In this short article, we have installed Apache Cassandra 4.0 on Debian 11 (Bulls Eye) operating system successfully. I hope this article will be helpful.