Apache Cassandra 1.2 Documentation

Initializing a multiple node cluster

The Cassandra 1.2 documentation is transitioning to a new format!
Please use the new Cassandra 1.2 documentation instead.
Back to Table of Contents
All Documents List     

You can use initialize a Cassandra cluster with one or more data centers. Data replicates across the data centers automatically and transparently; no ETL work is necessary to move data between different systems or servers. You can configure the number of copies of the data in each data center and Cassandra handles the rest, replicating the data for you.

Note

In Cassandra, the term data center is a grouping of nodes. Data center is synonymous with replication group, that is, a grouping of nodes configured together for replication purposes.

Prerequisites

Each node must be correctly configured before starting the cluster. You must determine or perform the following before starting the cluster:

  • Install Cassandra on each node.
  • Choose a name for the cluster.
  • Get the IP address of each node.
  • Determine which nodes will be seed nodes. (Cassandra nodes use the seed node list for finding each other and learning the topology of the ring.)
  • Determine the snitch.
  • If the nodes are behind a firewall, open the required ports for internal/external communication. See Configuring firewall port access.
  • If using multiple data centers, determine a naming convention for each data center and rack, for example: DC1, DC2 or 100, 200 and RAC1, RAC2 or R101, R102.
  • Other possible configuration settings are described in Choosing node configuration options and Node and cluster configuration (cassandra.yaml).

The following examples demonstrate initializing Cassandra:

Configuration example for single data center

This example describes installing a six node cluster spanning two racks in a single data center. Each node is configured to use the RackInferringSnitch (multiple rack aware) and 256 virtual nodes (recommended).

It is recommended to have more than one seed node per data center.

To initialize the cluster:

Set properties for each node in the cassandra.yaml file. The location of this file depends on the type of installation; see Cassandra Configuration Files Locations or DataStax Enterprise Configuration Files Locations.

Note

After changing properties in the cassandra.yaml file, you must restart the node for the changes to take effect.

  1. Suppose you install Cassandra on these nodes with one node per rack serving as a seed:

    • node0 110.82.155.0 (seed1)
    • node1 110.82.155.1
    • node2 110.82.155.2
    • node3 110.82.156.3 (seed2)
    • node4 110.82.156.4
    • node5 110.82.156.5

    It is a best practice to have at more than one seed node per data center.

  2. If you have a firewall running on the nodes in your cluster, you must open certain ports to allow communication between the nodes. See Configuring firewall port access.

  1. If the Cassandra is running, stop the node and clear the data.

    • For packaged installs, run the following commands:

      $ sudo service cassandra stop (stops the service)

      $ sudo rm -rf /var/lib/cassandra/* (clears the data from the default directories)

    • For binary installs, run the following commands from the install directory:

      $ ps auwx | grep cassandra (finds the Cassandra Java process ID [PID])

      $ sudo kill <pid> (stops the process)

      $ sudo rm -rf /var/lib/cassandra/* (clears the data from the default directories)

  2. Modify the following property settings in the cassandra.yaml file for each node:

    • num_tokens: -
    • -seeds: <internal IP_address of each seed node>
    • listen_address: <localhost IP address>
    • endpoint_snitch <name of snitch> - See endpoint_snitch.

    node0

    cluster_name: 'MyDemoCluster'
    num_tokens: 256
    seed_provider:
      - class_name: org.apache.cassandra.locator.SimpleSeedProvider
        parameters:
             - seeds: "110.82.155.0,110.82.155.3"
    listen_address: 110.82.155.0
    rpc_address: 0.0.0.0
    endpoint_snitch: RackInferringSnitch
    

    node1 to node5

    The properties for these nodes are the same as node0 except for the listen_address.

  3. After you have installed and configured Cassandra on all nodes, start the seed nodes one at a time, and then start the rest of the nodes.

    Note

    If the node has restarted because of automatic restart, you must stop the node and clear the data directories, as described in above.

    • Packaged installs: sudo service cassandra start

    • Binary installs, run one of the following commands from the install directory:

      bin/cassandra (starts in the background)

      bin/cassandra -f (starts in the foreground)

  4. To check that the ring is up and running, run the nodetool status command.


    ../../_images/nodetool_status.png

Configuration example for multiple data centers

This example describes installing a six node cluster spanning two data centers. Each node is configured to use the PropertyFileSnitch (uses a user-defined description of the network details) and 256 virtual nodes (recommended).

It is recommended to have more than one seed node per data center.

To configure a cluster with multiple data centers:

Set properties for each node in the cassandra.yaml and cassandra-topology.properties files. The location of these files depends on the type of installation; see Cassandra Configuration Files Locations or DataStax Enterprise Configuration Files Locations.

Note

After changing properties in these files, you must restart the node for the changes to take effect.

  1. Suppose you install Cassandra on these nodes:

    • node0 10.168.66.41 (seed1)
    • node1 10.176.43.66
    • node2 10.168.247.41
    • node3 10.176.170.59 (seed2)
    • node4 10.169.61.170
    • node5 10.169.30.138
  2. If you have a firewall running on the nodes in your cluster, you must open certain ports to allow communication between the nodes. See Configuring firewall port access.

  3. If the Cassandra is running, stop the node and clear the data.

    • For packaged installs, run the following commands:

      $ sudo service cassandra stop (stops the service)

      $ sudo rm -rf /var/lib/cassandra/* (clears the data from the default directories)

    • For binary installs, run the following commands from the install directory:

      $ ps auwx | grep cassandra (finds the Cassandra Java process ID [PID])

      $ sudo kill <pid> (stops the process)

      $ sudo rm -rf /var/lib/cassandra/* (clears the data from the default directories)

  4. Modify the following property settings in the cassandra.yaml file for each node:

    • num_tokens: -
    • -seeds: <internal IP_address of each seed node>
    • listen_address: <localhost IP address>
    • endpoint_snitch <name of snitch> - See endpoint_snitch.

    node0:

    cluster_name: 'MyDemoCluster'
    num_tokens: 256
    seed_provider:
       - class_name: org.apache.cassandra.locator.SimpleSeedProvider
          parameters:
            - seeds: "10.168.66.41,10.176.170.59"
    listen_address: 10.168.66.41
    endpoint_snitch: PropertyFileSnitch
    

    Note

    Include at least one node from each data center.

    node1 to node5

    The properties for these nodes are the same as node0 except for the listen_address.

  5. In the cassandra-topology.properties file, assign the data center and rack names you determined in the Prerequisites to the IP addresses of each node. For example:

    # Cassandra Node IP=Data Center:Rack
    10.168.66.41=DC1:RAC1
    10.176.43.66=DC2:RAC1
    10.168.247.41=DC1:RAC1
    10.176.170.59=DC2:RAC1
    10.169.61.170=DC1:RAC1
    10.169.30.138=DC2:RAC1
  6. Also, in the cassandra-topologies.properties file, assign a default data center name and rack name for unknown nodes.

    # default for unknown nodes
    default=DC1:RAC1
  7. After you have installed and configured Cassandra on all nodes, start the seed nodes one at a time, and then start the rest of the nodes.

    Note

    If the node has restarted because of automatic restart, you must stop the node and clear the data directories, as described in above.

    • Packaged installs: sudo service cassandra start

    • Binary installs, run one of the following commands from the install directory:

      bin/cassandra (starts in the background)

      bin/cassandra -f (starts in the foreground)

  8. To check that the ring is up and running, run the nodetool status command.


    ../../_images/nodetool_status.png

More information about configuring data centers

Links to more information about configuring a data center: