From Fedora Project Wiki

No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 54: Line 54:
dc=DC1
dc=DC1
rack=RAC1
rack=RAC1
</pre>
On both nodes delete file ''/etc/cassandra/cassandra-topology.properties'':
<pre>
rm -f /etc/cassandra/cassandra-topology.properties
</pre>
</pre>


Line 64: Line 69:
<pre>
<pre>
$ nodetool status
$ 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
</pre>
</pre>
{{admon/note|Note:|If in any reason you previously started Apache Cassandra or you don't have same values in ''Datacenter'' and column ''Rack'' of nodetool status output, your '''nodes probably won't find each other''',  to fix this, stop cassandra and delete data directory ''rm -rf /var/lib/cassandra/*''. '''(This will cause data loss if you have already data in database)'''}}

Latest revision as of 15:59, 16 May 2018

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
Note:
If you use firewall, remember to open ports.

On both nodes create file /etc/cassandra/cassandra-rackdc.properties:

dc=DC1
rack=RAC1

On both nodes delete file /etc/cassandra/cassandra-topology.properties:

rm -f /etc/cassandra/cassandra-topology.properties

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
Note:
If in any reason you previously started Apache Cassandra or you don't have same values in Datacenter and column Rack of nodetool status output, your nodes probably won't find each other, to fix this, stop cassandra and delete data directory rm -rf /var/lib/cassandra/*. (This will cause data loss if you have already data in database)