Reputation: 363
I'm using latest default image of Cassandra in Docker. In Cassandra I have one keyspace with my data. What I want to do is to add some nodes and change replication factor. How can I achieve this?
Upvotes: 3
Views: 1598
Reputation: 57748
So to do this, you'll need two Cassandra containers running on your Mac. You'll also need to set specific container names, so that they can be used as the "seed" list for both.
Bitnami has a good doc on how to do this, just page down halfway to the "Setting up a cluster" section:
https://hub.docker.com/r/bitnami/cassandra/
Basically, you create a specific network. All containers on the same network should be able to talk to each other. In theory, you could skip this step and your containers would run on the "default" network. But creating a specific network is good practice.
docker network create cassandra_network
Create the first node like this:
docker run --name cassandra-node1 \
--net=cassandra_network \
-p 9042:9042 \
-e CASSANDRA_CLUSTER_NAME=cassandra-cluster \
-e CASSANDRA_SEEDS=cassandra-node1,cassandra-node2 \
bitnami/cassandra:latest
If you don't want the "latest" (or don't want to use Bitnami's image) then you can swap out the last line with this to get the community image and whichever version:
cassandra:4.0.1
Watch the log to make sure it comes up. Then create the second node with the same command, but alter the name.
docker run --name cassandra-node2 \
--net=cassandra_network \
-p 9042:9042 \
-e CASSANDRA_CLUSTER_NAME=cassandra-cluster \
-e CASSANDRA_SEEDS=cassandra-node1,cassandra-node2 \
bitnami/cassandra:latest
Once the second node is up and joined, you can adjust your keyspace replication (depending on your data center name):
ALTER KEYSPACE system_auth WITH
replication={'class':'NetworkTopologyStrategy','dc1':'2'};
Or for SimpleStrategy
:
ALTER KEYSPACE system_auth WITH
replication = {'class': 'SimpleStrategy', 'replication_factor': '2'};
Including the community documentation for reference: https://hub.docker.com/_/cassandra
Upvotes: 2