On this page
- What do you need before installing Cassandra?
- How do you install Cassandra on Ubuntu or Debian?
- How do you install Cassandra on Rocky Linux?
- How do you configure the first node?
- How do you replace the default superuser?
- How do you encrypt traffic between nodes over public IPs?
- How do you add the second and third node?
- How do you size the heap and maintain the cluster?
- Questions
What do you need before installing Cassandra?
Plan for at least 4 GB of RAM per node for testing and 8 GB or more for real data, plus a supported Java runtime. Cassandra 5.0 runs on Java 11 or 17; Java 17 is the sensible pick today.
Cassandra keeps recent writes in memory, runs compaction in the background and leans on the operating system page cache for reads, so memory beyond the heap is never wasted. Fast NVMe disks help compaction a great deal. A three-node cluster is the smallest layout that keeps data available when one node is down with a replication factor of 3.
Prepare each server:
- A sudo user and SSH keys (see SSH keys and hardening).
- A unique hostname per node, for example
cass1.example.net; changing the hostname shows how. - Accurate time through chrony or systemd-timesyncd, because Cassandra resolves conflicting writes by timestamp.
- Swap turned off or set very low, since a swapping JVM stalls the whole cluster.
The examples use three nodes at 198.51.100.24, 198.51.100.25 and 198.51.100.26.
How do you install Cassandra on Ubuntu or Debian?
Install OpenJDK 17, add the Apache Cassandra repository for the 5.0 series and install the package.
sudo apt update
sudo apt install -y openjdk-17-jre-headless curl gnupg
java -version
sudo install -d -m 0755 /etc/apt/keyrings
sudo curl -fsSL -o /etc/apt/keyrings/apache-cassandra.asc https://downloads.apache.org/cassandra/KEYS
echo "deb [signed-by=/etc/apt/keyrings/apache-cassandra.asc] https://debian.cassandra.apache.org 50x main" | sudo tee /etc/apt/sources.list.d/cassandra.sources.list
sudo apt update
sudo apt install -y cassandra
nodetool versionUbuntu 24.04, 22.04 and Debian 12 carry OpenJDK 17 in their archives. Debian 13 moved to newer Java releases only, so on that release install a Java 17 build from a third-party JDK repository first, or run the node on Debian 12 or Ubuntu. The configuration lives in /etc/cassandra/ and data in /var/lib/cassandra/.
How do you install Cassandra on Rocky Linux?
Create a repo file that points at the Apache RPM repository, install Java 17 and the package, then start the service.
sudo tee /etc/yum.repos.d/cassandra.repo >/dev/null <<'EOF'
[cassandra]
name=Apache Cassandra
baseurl=https://redhat.cassandra.apache.org/50x/
gpgcheck=1
repo_gpgcheck=1
gpgkey=https://downloads.apache.org/cassandra/KEYS
EOF
sudo dnf install -y java-17-openjdk-headless
sudo dnf install -y cassandra
sudo systemctl daemon-reload
sudo systemctl enable --now cassandra
nodetool versionOn this family the config files sit in /etc/cassandra/conf/. Accept the GPG key when dnf asks for it.
How do you configure the first node?
Stop the freshly started service, clear the data it created with the default cluster name, edit cassandra.yaml, then start it again. A node refuses to start if its stored cluster name no longer matches the config.
sudo systemctl stop cassandra
sudo rm -rf /var/lib/cassandra/data/* /var/lib/cassandra/commitlog/* /var/lib/cassandra/saved_caches/*Set these keys in cassandra.yaml on the first node:
cluster_name: 'shop-cluster'
seed_provider:
- class_name: org.apache.cassandra.locator.SimpleSeedProvider
parameters:
- seeds: "198.51.100.24:7000"
listen_address: 198.51.100.24
rpc_address: 127.0.0.1
endpoint_snitch: GossipingPropertyFileSnitch
authenticator: PasswordAuthenticator
authorizer: CassandraAuthorizerName the data center and rack in cassandra-rackdc.properties:
dc=dc1
rack=rack1Start and check:
sudo systemctl start cassandra
nodetool statusA line starting with UN (up, normal) means the node is ready. Keeping rpc_address on loopback means clients connect through the local machine or an SSH tunnel; change it to the public IP only together with client TLS and a firewall rule.
How do you replace the default superuser?
Log in once with the built-in cassandra account, create your own superuser, then strip the old one. Before adding nodes, raise the replication of the auth keyspace so logins work when a node is down.
cqlsh -u cassandra -p cassandra 127.0.0.1CREATE ROLE dba WITH PASSWORD = 'Long-Random-Passphrase-77' AND SUPERUSER = true AND LOGIN = true;
-- log out, log back in as dba, then:
ALTER ROLE cassandra WITH PASSWORD = 'another-long-random-value' AND SUPERUSER = false AND LOGIN = false;
ALTER KEYSPACE system_auth WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3};
CREATE KEYSPACE shop WITH replication = {'class': 'NetworkTopologyStrategy', 'dc1': 3};
CREATE ROLE shop_app WITH PASSWORD = 'App-Secret-Value-19' AND LOGIN = true;
GRANT ALL PERMISSIONS ON KEYSPACE shop TO shop_app;A replication factor of 3 on a single node only warns for now and takes effect as nodes join. If cqlsh complains about the Python version on a newer distro, install the standalone cqlsh package from PyPI in a virtual environment and use that copy.
How do you encrypt traffic between nodes over public IPs?
Give every node a key pair in a keystore, put all node certificates into one shared truststore, and set internode_encryption: all. Gossip, streaming and replica writes then travel inside TLS on port 7000.
cd /etc/cassandra # /etc/cassandra/conf on Rocky
sudo keytool -genkeypair -alias cass1 -keyalg RSA -keysize 3072 -validity 1825 \
-dname "CN=cass1.example.net" -storetype PKCS12 -keystore cass1.p12 -storepass 'Keystore-Pass-1'
sudo keytool -exportcert -alias cass1 -keystore cass1.p12 -storepass 'Keystore-Pass-1' -file cass1.crtRepeat on each node with its own alias, copy every .crt file to one machine, and build the truststore:
for n in cass1 cass2 cass3; do
keytool -importcert -noprompt -alias $n -file $n.crt -storetype PKCS12 -keystore truststore.p12 -storepass 'Trust-Pass-1'
doneCopy truststore.p12 to all nodes, make both files readable by the cassandra user only, and add to cassandra.yaml:
server_encryption_options:
internode_encryption: all
keystore: /etc/cassandra/cass1.p12
keystore_password: Keystore-Pass-1
truststore: /etc/cassandra/truststore.p12
truststore_password: Trust-Pass-1
store_type: PKCS12
require_client_auth: trueWith require_client_auth, a node only talks to peers whose certificate sits in the truststore, so a stranger who reaches port 7000 cannot join.
How do you add the second and third node?
Install Cassandra the same way, stop it, clear its data, copy the settings from node one with its own listen_address and keystore, open the firewall between the nodes, then start one node at a time and wait for UN before the next.
Firewall rules on every node, shown for Ubuntu and Debian with ufw and for Rocky with firewalld:
sudo ufw allow from 198.51.100.25 to any port 7000 proto tcp
sudo ufw allow from 198.51.100.26 to any port 7000 proto tcp
# Rocky
sudo firewall-cmd --permanent --new-zone=cassandra
sudo firewall-cmd --permanent --zone=cassandra --add-source=198.51.100.25 --add-source=198.51.100.26
sudo firewall-cmd --permanent --zone=cassandra --add-port=7000/tcp
sudo firewall-cmd --reloadUse two seeds once you have three nodes, listing the same seeds on every machine, for example "198.51.100.24:7000,198.51.100.25:7000". Then start node two and watch it stream data:
sudo systemctl start cassandra
nodetool netstats
nodetool statusWhen all nodes show UN, run nodetool cleanup on the older nodes to drop data they no longer own. Keep JMX port 7199 bound to localhost, which is the packaged default, and never open 9042 to the world. For a private path between nodes, a WireGuard mesh is a good alternative to TLS on public addresses.
How do you size the heap and maintain the cluster?
Let Cassandra pick a heap automatically on small servers, or set it by hand to about a quarter to a half of RAM, never above roughly 16 GB with G1. Set both values in jvm-server.options:
-Xms4G
-Xmx4GOn an 8 GB node, 4 GB of heap leaves the rest for off-heap structures and the page cache. Routine care keeps a cluster healthy:
nodetool status
nodetool tablestats shop
nodetool repair -pr shop # weekly, on each node in turn
nodetool snapshot -t before-upgrade shop
sudo journalctl -u cassandra -n 50 --no-pager
sudo tail -n 50 /var/log/cassandra/system.logUpgrade one node at a time: nodetool drain, stop, upgrade the package, start, wait for UN. Nodes that will not join usually have a cluster name mismatch, a seed they cannot reach, a certificate missing from the truststore, or a clock that has drifted. If heap pressure shows up as long GC pauses in the log, move to a larger plan with this migration guide and replace the node.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Apache Cassandra cluster
How much RAM does a Cassandra node need?
Plan 4 GB for a test node and 8 GB or more for production. The heap takes a quarter to a half and the rest feeds the page cache and off-heap memory.
Which ports does Cassandra use?
Port 7000 for traffic between nodes (encrypted when internode TLS is on), 9042 for CQL clients and 7199 for JMX, which stays on localhost.
Can I run a one-node Cassandra?
Yes, for development or a small app that can accept downtime. Use replication factor 1 for its keyspaces, or keep 3 and add nodes later; reads at consistency ONE still work.
What is a seed node?
A seed is an address new nodes contact first to learn about the cluster. It is not a master. Use two or three seeds per data center and list the same seeds on every node.
How do I remove a node cleanly?
Run nodetool decommission on that node. It streams its data to the others and leaves the ring; then stop the service and destroy the server.
Do I need TLS if my nodes talk over WireGuard?
WireGuard already encrypts the link, so internode TLS becomes optional. Many people still enable it for defense in depth, especially when the cluster spans several cities.
More in Databases
- Install MySQL 8
- Install MariaDB
- Install PostgreSQL
- Install MongoDB
- PostgreSQL JSON, arrays and special types
- PostgreSQL views, triggers and CTEs
- PostgreSQL full-text search and encryption
- MySQL keys, indexes and full-text search
- MySQL JSON, views and stored procedures
- Apache Solr search server
- Install Redis or Valkey
- Install Memcached
- Install Apache CouchDB
- InfluxDB for time series
- Install Elasticsearch
- Back up and restore MySQL and MariaDB
- Back up and restore PostgreSQL
- MySQL users, roles and passwords
- PostgreSQL roles and permissions
- Repair a crashed MySQL table
- PostgreSQL streaming replication
- MongoDB replica set
- PostGIS for location data
- Database insight with PgHero
- Couchbase Server
- ArangoDB multi-model database
- Remote database access over SSH