This page contains example cluster setup for Apache Cassandra.
2-node Cassandra cluster
The Cassandra main configuration file /etc/cassandra/cassandra.yaml needs to be edited to setup the cluster. The options that you have to modify are:
Option | Description |
---|---|
cluster_name | Name of your cluster. Must be same on all nodes. |
num_tokens | Number of virtual nodes within a Cassandra instance. This is used to partition the data and spread the data throughout the cluster. The recommended value is 256. |
seeds | Comma-delimited list of the IP address of each node in the cluster. |
listen_address | The IP address or hostname that Cassandra binds to for connecting to other Cassandra nodes. It defaults to localhost and needs to be changed to the IP address of the node. |
rpc_address | The listen address for client connections (CQL protocol). |
endpoint_snitch | Set to a class that implements the IEndpointSnitch. Cassandra uses snitches for locating nodes and routing requests. The default one is SimpleSnitch but we will change to GossipingPropertyFileSnitch which is more suitable for production environments. |
auto_bootstrap | This parameter is not present in the configuration file, so it has to be added and set to false. It makes new (non-seed) nodes automatically migrate the right data to themselves. |
Node 1 with IP address 10.0.0.1 edit/add options to /etc/cassandra/cassandra.yaml:
num_tokens: 256 seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: 10.0.0.1, 10.0.0.2 listen_address: 10.0.0.1 rpc_address: 10.0.0.1 endpoint_snitch: GossipingPropertyFileSnitch auto_bootstrap: false
Node 2 with IP address 10.0.0.2 edit/add options to /etc/cassandra/cassandra.yaml:
num_tokens: 256 seed_provider: - class_name: org.apache.cassandra.locator.SimpleSeedProvider parameters: - seeds: 10.0.0.1, 10.0.0.2 listen_address: 10.0.0.2 rpc_address: 10.0.0.2 endpoint_snitch: GossipingPropertyFileSnitch auto_bootstrap: false
On both nodes create file /etc/cassandra/cassandra-rackdc.properties:
dc=DC1 rack=RAC1
Now you can start cluster, on both nodes start cassandra:
systemctl start cassandra
You should see cluster status and joined nodes with client tools:
$ nodetool status Datacenter: DC1 =============== Status=Up/Down |/ State=Normal/Leaving/Joining/Moving -- Address Load Tokens Owns (effective) Host ID Rack UN 10.0.0.1 151.33 KiB 256 100.0% 80235601-9725-4da2-8e50-7b609cbb54d9 RAC1 UN 10.0.0.1 151.17 KiB 256 100.0% 2310ac52-456f-426b-87b1-56eefa376338 RAC1