Apache Cassandra is an open-source NoSQL database. One of it’s main features is it’s decentralized nature that gives unique fault tolerance. Having our data replicated across datacenters means our production will not suffer from the loss of one of our sites, something all sysadmins dream of (or really happy to have such setup).
In this tutorial we will install Cassandra on Red Hat Enterprise Linux 8 by adding the Cassandra repository, install the software, and set up all else needed to have our service up and running and easy to manage.
In this tutorial you will learn:
- How to add Cassandra repository
- How to install needed packages
- How to repair systemd unit file
- How to test Cassandra with cqlsh
Software Requirements and Conventions Used
Category | Requirements, Conventions or Software Version Used |
---|---|
System | Red Hat Enterprise Linux 8 |
Software | Apache Cassandra 3.11 |
Other | Privileged access to your Linux system as root or via the sudo command. |
Conventions |
# – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command$ – requires given linux commands to be executed as a regular non-privileged user |
How to install cassandra on Redhat 8 step by step instructions
Red Hat Enterprise Linux uses rpm-based packaging, and Apache Cassandra does provide an rpm repository. While not all dependencies are included, the issues need to be solved aren’t much of a hassle. All we need is Java 8 (OpenJDK or Oracle JDK) installed beforehand.
- We’ll install Cassandra from the official Apache repository. To be able to do that, we create a textfile
/etc/yum.repos.d/cassandra.repo
with the following content:[cassandra] name=Apache Cassandra baseurl=https://www.apache.org/dist/cassandra/redhat/311x/ gpgcheck=1 repo_gpgcheck=1 gpgkey=https://www.apache.org/dist/cassandra/KEYS
- With that repository definition in place, we can install Cassandra with
dnf
:# dnf install cassandra
The installation will ask to accept keys of the developers. As we trust them not publishing something tricky, we’ll accept the keys to proceed with the installation.
- The installed package does include init script for SysV, and
systemd
does able to generate a service file for itself, however that does not play nicely. To save ourselves from a bit trial-by-error, we create a simple new service file/etc/systemd/system/cassandra.service
with the following content:
[Unit] Description=Apache Cassandra After=network.target [Service] PIDFile=/var/run/cassandra/cassandra.pid User=cassandra Group=cassandra ExecStart=/usr/sbin/cassandra -f -p /var/run/cassandra/cassandra.pid Restart=always [Install] WantedBy=multi-user.target
systemd
need to be reloaded to be aware of the new service definition:# systemctl daemon-reload
- Now we can manage our service with systemd. We can start, stop, and get the status of Cassandra:
# systemctl start|stop|status cassandra
It’s running state should provide something similar to the below output with the unit file created above:
# systemctl status cassandra cassandra.service - Apache Cassandra Loaded: loaded (/etc/systemd/system/cassandra.service; disabled; vendor preset: disabled) Active: active (running) since Tue 2019-01-08 18:39:32 CET; 24s ago Main PID: 6615 (java) Tasks: 58 (limit: 12544) Memory: 1.1G CGroup: /system.slice/cassandra.service 6615 java -Xloggc:/var/log/cassandra/gc.log -ea [...]
- Optionally we can enable autostart on boot:
# systemctl enable cassandra
- To run some example queries to test the functioning database management system, we’ll use
cqlsh
to access the CQL shell. This tool is shipped with the installation, howeverpython
this tool is dependent on does not. We’ll need to install it withdnf
:# dnf install python2
- To run an example query against Cassandra, we can enter the CQL shell:
# cqlsh Connected to Test Cluster at 127.0.0.1:9042. [cqlsh 5.0.1 | Cassandra 3.11.3 | CQL spec 3.4.4 | Native protocol v4] Use HELP for help. cqlsh>
- As user data isn’t inserted into the database yet, we’ll query some data from the system tables to see our installation is working fine:
cqlsh> SELECT keyspace_name, table_name FROM system_schema.tables where keyspace_name = 'system_auth'; keyspace_name | table_name ---------------+-------------------------------- system_auth | resource_role_permissons_index system_auth | role_members system_auth | role_permissions system_auth | roles (4 rows)