CassandraDB nodes crash when 4 noes are present - docker

I am trying to set up an Apache CassandraDB cluster via docker.
I've managed to create up to and including 3 nodes using docker run --network cassandra -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_SEEDS=node0 --name "node0" -d cassandra.
Whenever I add a 4th node using the same command (just changing the container name), another random node in the cluster crashes and the node that was created also exits shortly after being on the UJ and DJ stages.
Here's what I've tried.
docker network create cassandra
docker run --network cassandra -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_SEEDS=node0 --name "node0" -d cassandra
I then waited until the node was up and nodetool was showing this:
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.19.0.2 88.49 KiB 16 100.0% 15573541-fc19-4569-9a43-cb04e49e134f rack1
After that, I added two additional nodes to the cluster.
docker run --network cassandra -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_SEEDS=node0 --name "node1" -d cassandra
docker run --network cassandra -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_SEEDS=node0 --name "node2" -d cassandra
I waited until those two joined the cluster and nodetool showed this:
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.19.0.2 74.11 KiB 16 64.7% 15573541-fc19-4569-9a43-cb04e49e134f rack1
UN 172.19.0.4 98.4 KiB 16 76.0% 30afdc85-e863-452c-9031-59803e4b1f11 rack1
UN 172.19.0.3 74.04 KiB 16 59.3% 6d92cf62-65b4-4365-ab28-2d53872605e3 rack1
That seems good! After that, I wanted to add another node to test whether my replication factor was working properly. So, I added another node to the cluster using the same command:
docker run --network cassandra -e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch -e CASSANDRA_SEEDS=node0 --name "node3" -d cassandra
When I added this node, node1 crashed immediately. node3 (thats's the new one) was briefly on the UJ (UP-Joining) stage and then switched to DJ (DOWN-Joining) and was then removed from the nodelist.
Here are the results from nodetool status, in order:
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.19.0.2 74.11 KiB 16 64.7% 15573541-fc19-4569-9a43-cb04e49e134f rack1
UN 172.19.0.4 74.03 KiB 16 76.0% 30afdc85-e863-452c-9031-59803e4b1f11 rack1
DN 172.19.0.3 74.04 KiB 16 59.3% 6d92cf62-65b4-4365-ab28-2d53872605e3 rack1
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UJ 172.19.0.5 20.75 KiB 16 ? 2e4a25e4-3c81-4383-9c9f-6326e4043910 rack1
UN 172.19.0.2 74.11 KiB 16 64.7% 15573541-fc19-4569-9a43-cb04e49e134f rack1
UN 172.19.0.4 74.03 KiB 16 76.0% 30afdc85-e863-452c-9031-59803e4b1f11 rack1
DN 172.19.0.3 74.04 KiB 16 59.3% 6d92cf62-65b4-4365-ab28-2d53872605e3 rack1
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
DJ 172.19.0.5 20.75 KiB 16 ? 2e4a25e4-3c81-4383-9c9f-6326e4043910 rack1
UN 172.19.0.2 74.11 KiB 16 64.7% 15573541-fc19-4569-9a43-cb04e49e134f rack1
UN 172.19.0.4 74.03 KiB 16 76.0% 30afdc85-e863-452c-9031-59803e4b1f11 rack1
DN 172.19.0.3 74.04 KiB 16 59.3% 6d92cf62-65b4-4365-ab28-2d53872605e3 rack1
Datacenter: dc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.19.0.2 74.11 KiB 16 64.7% 15573541-fc19-4569-9a43-cb04e49e134f rack1
UN 172.19.0.4 74.03 KiB 16 76.0% 30afdc85-e863-452c-9031-59803e4b1f11 rack1
DN 172.19.0.3 74.04 KiB 16 59.3% 6d92cf62-65b4-4365-ab28-2d53872605e3 rack1
Here are the logs for node1:
As you can see, the first item in the log was the confirmation that node2 had connected to the cluster.
https://gist.github.com/janic0/7e464e5c819c37e6ed38819fb3c19eff
Here are the logs for node3 (again, that's the new node)
https://gist.github.com/janic0/0968b7136c3beb3ef76a2379f3cd9be5

I've investigated it and found that Docker kills these containers with exit code 137 - or "out of memory".
Yep, I thought something like that was happening.
Each of the nodes used up about 4GB of RAM and the forth node was just enough to force Docker to kill some of the containers. If you do want to host that many nodes on one machine for some reason, you can increase the memory limit:
So I've done something like this before. If you're just going to be doing some local testing and you want a multi-node cluster, I've used Minikube for that before. In fact, I put together a repo which has some resources for doing that: https://github.com/aploetz/cassandra_minikube
But another approach which might be a "quick fix" for you, would be to explicitly adjust the Java heap sizing to something much smaller for each of your nodes. In my Minikube example above, I'd set:
-Xms512M
-Xmx512M
-Xmn256M
This should create a 1/2 GB heap, which is plenty for local dev or some simple testing. You can set these values in your cassandra-env.sh or jvm-server.options file (depending on your Cassandra version).

Related

Token balancing in a blank new Cassandra-Cluster

My setup consists of 3 Cassandra nodes. every node runs as part of a docker container.
One seednode and two normal nodes.
I use cassandra:latest which mean at this time version 3.11.4.
All nodes run in one cluster.
All nodes run in one datacenter.
I use the the following setup in my docker-compose.yml
- "CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch"
- "CASSANDRA_NUM_TOKENS=8"
- "MAX_HEAP_SIZE=512M"
- "HEAP_NEWSIZE=128M"
Heap-size are so small because it tests only the start of the cluster and my notebook has not enough ram.
The partitioner is the default Murmur3Partitioner of cassandra.
I start only the cluster, no keyspace-creation or other things a going through the thing.
In every documentation that i found there is the statement of the balanced token-range and unbalanced token distribution is bad etc. etc.
But what ist a balanced token-range?
When I start the cluster, first the seedcontainer, with an intervall of 1 minute each other node comes up and ready.
The cluster is healthy and there are no errors in log. As the result of docker-compose ps describes:
Name Command State Ports
----------------------------------------------------------------------------------------------------------------------------------
docker_cassandra-seed_1 docker-entrypoint.sh bash ... Up 7000/tcp, 7001/tcp, 7199/tcp, 0.0.0.0:23232->9042/tcp, 9160/tcp
docker_cassandra1_1 docker-entrypoint.sh bash ... Up 7000/tcp, 7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp
docker_cassandra2_1 docker-entrypoint.sh bash ... Up 7000/tcp, 7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp
If the cluster is up, there are 3 nodes with 8 vnodes runs on each node.
It is a cluster distribution of 24 with always 24 token ranges.
The token range in Cassandra is -2^63 till +2^63 - 1 (java long).
If I call a
docker exec -ti docker_cassandra-seed_1 nodetool ring
i receive the following result.
docker exec -ti docker_cassandra-seed_1 nodetool ring
Datacenter: tc1
==========
Address Rack Status State Load Owns Token
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% -8870864291163548206
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -8804151848356105327
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% -8578084366820530367
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -7746741366682664202
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -7013522326538302096
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% -6994428155886831685
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% -6650863707982675450
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -5995004048488281144
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -5683587085031530885
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% -5274940575732780430
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% -5184169415607375486
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% -2082614198258325552
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% -1084866128895283137
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% 2495470503021543046
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% 3043280549254813456
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% 3058642754102082410
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% 3117172086630093502
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% 3405798334726690865
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% 3829479365384141235
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% 4124513942316551627
172.27.0.2 rack1 Up Normal 220.44 KiB 55.24% 4807293191442647176
172.27.0.4 rack1 Up Normal 231.07 KiB 55.89% 4911525338969505185
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% 8068956543491535994
172.27.0.3 rack1 Up Normal 254.57 KiB 88.87% 8197176123795617738
Which means the difference between every token range in the ring is totally different.
Or in other words, the perfect case for the calculation where ((2^63 * 2) - 1) / (3 * 8) = 768.614.336.404.564.000 tokens per node in an ideal token distribution.
Sorry I have only excel at the fast here for calculating (round the 10000s):
-9.223.372.036.854.770.000 Long Min
-8.870.864.291.163.540.000 352.507.745.691.229.000
-8.804.151.848.356.100.000 66.712.442.807.440.400
-8.578.084.366.820.530.000 226.067.481.535.570.000
-7.746.741.366.682.660.000 831.343.000.137.870.000
-7.013.522.326.538.300.000 733.219.040.144.359.000
-6.994.428.155.886.830.000 19.094.170.651.470.800
-6.650.863.707.982.670.000 343.564.447.904.160.000
-5.995.004.048.488.280.000 655.859.659.494.390.000
-5.683.587.085.031.530.000 311.416.963.456.750.000
-5.274.940.575.732.780.000 408.646.509.298.750.000
-5.184.169.415.607.370.000 90.771.160.125.410.300
-2.082.614.198.258.320.000 3.101.555.217.349.050.000
-1.084.866.128.895.280.000 997.748.069.363.040.000
2.495.470.503.021.540.000 3.580.336.631.916.820.000
3.043.280.549.254.810.000 547.810.046.233.270.000
3.058.642.754.102.080.000 15.362.204.847.269.900
3.117.172.086.630.090.000 58.529.332.528.010.200
3.405.798.334.726.690.000 288.626.248.096.600.000
3.829.479.365.384.140.000 423.681.030.657.450.000
4.124.513.942.316.550.000 295.034.576.932.410.000
4.807.293.191.442.640.000 682.779.249.126.090.000
4.911.525.338.969.500.000 104.232.147.526.860.000
8.068.956.543.491.530.000 3.157.431.204.522.030.000
8.197.176.123.795.610.000 128.219.580.304.080.000
9.223.372.036.854.770.000 Long Max
The right column describes the distribution of each token range. And here is a big gap between the biggest and the smallest token range.
Or a little bit consolidated (from the middle of the result) that is totally uneven or unbalanced or undistributed:
-5184169415607375486
-2082614198258325552
-1084866128895283137
After some tesing, i´ve setup a super simple thing.
One pc (with ubuntu 18.04, java 1.8.0_201, cassandra version 3.6).
Install, let all the parameters to default, drive the cassandra service up and look at the token-distribution.
Here is the result:
tokendistribution on a new cluster
So my question is: What means balanced token-range in a Cassandra cluster?
As described in this link
https://thelastpickle.com/blog/2019/02/21/set-up-a-cluster-with-even-token-distribution.html
it seems to be the solution, at least for the distribution of tokens and data for a keyspace.
The following steps i take to get a balanced system:
Setup cassandra.yaml for the seed-node with (for my testcase num_tokens=8) let the other parameter as default
startup the seednode, wait until ready
connect via cqlsh or programmatic solution and create the keyspace (for my test-case with replication-factor=1).
shutdown the seed-node
edit the cassandra.yaml of the seed-node and outcomment/add the parameter for allocate_tokens_for_keyspace: [your_keyspace_name_from_step_3]
startup the seed-node and wait until the node is ready
edit the cassandra.yaml for the second node in the cluster take the step 5. in this file and the num_token equal to num_token of the seed-node.
run the second node an wait until it is ready
do the steps 7-8 for any other node in your cluster.
With that and e.g. a testrun with adding 2.000.000 datarows in a testtable in the keyspace i see the following result:
docker exec -ti docker_cassandra-seed_1 nodetool status
Datacenter: tc1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.30.10.4 36.03 MiB 8 33.3% 1e0d781f-d71f-4704-bcd1-efb5d4caff0e rack1
UN 172.30.10.2 36.75 MiB 8 33.3% 56287b3c-b0f1-489f-930e-c7b00df896f3 rack1
UN 172.30.10.3 36.03 MiB 8 33.3% 943acc5f-7257-414a-b36c-c06dcb53e67d rack1
Even the tokendistribution ist better then before:
172.30.10.2 6.148.914.691.236.510.000
172.30.10.3 6.148.914.691.236.520.000
172.30.10.4 5.981.980.531.853.070.000
At the moment, there is some clarification about the problem with the uneven distribution, so thank you again Chris Lohfink for the link with the solution.
I´ve testing a little bit around the above scenario.
My testcluster consists of 5 nodes (1 seed, 4 normal nodes).
The first 5 steps from above remains valid:
Setup cassandra.yaml for the seed-node with (for my testcase
num_tokens=8) let the other parameter as default
startup the seednode, wait until ready
connect via cqlsh or programmatic
solution and create the keyspace (for my test-case with
replication-factor=1).
shutdown the seed-node, edit the cassandra.yaml of the seed-node and outcomment/add the parameter for allocate_tokens_for_keyspace: [your_keyspace_name_from_step_3]
startup the seed-node and wait until the node is ready
Then, you can startup all the other nodes (in my case 4) at same time (or with 1 minute delay between startup of each node), but automated. Important is, that all nodes have the allocate_tokens_for_keyspace: [your_keyspace....] set.
After all nodes are up, and fill with 1.000.000 rows, there´s an even balance of 20%.
That scenario makes the life easier, if you start a cluster with a lot of nodes.

Can't launch more than 1 cassandra node

I launched a cassandra docker image using the following command,
docker run --name=n1 -d cassandra:3.11.4
344138bb96e5326113af6ba5c44a17d8b40ed710fe36ce063677a56ef0c0117
This works fine,
docker exec -it n1 nodetool status gives,
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 103.7 KiB 256 100.0% 0ca2907d-49b9-4ed4-8bf3-6db99d0c8b45 rack1
Now when I try to launch a second node, this what I get,
docker inspect -f '{{ .NetworkSettings.IPAddress}}' n1
172.17.0.2
docker run --name n2 -d cassandra:3.11.4 -seeds 172.17.0.2
1c89b67cb61b049c4a8ae0f21bd0f7cddffad02b7e7964e502cd82e0d2ff2866
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
344138bb96e5 cassandra:3.11.4 "docker-entrypoint.s…" 2 minutes ago Up 2 minutes 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp n1
docker exec -it n1 nodetool status
Still no second node
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 103.7 KiB 256 100.0% 0ca2907d-49b9-4ed4-8bf3-6db99d0c8b45 rack1
docker exec -it n2 nodetool status
Error response from daemon: Container 1c89b67cb61b049c4a8ae0f21bd0f7cddffad02b7e7964e502cd82e0d2ff2866 is not running
docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c89b67cb61b cassandra:3.11.4 "docker-entrypoint.s…" 2 minutes ago Exited (1) 2 minutes ago n2
344138bb96e5 cassandra:3.11.4 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 7000-7001/tcp, 7199/tcp, 9042/tcp, 9160/tcp n1
What am I doing wrong here?
I don't know where you get the information which you can use -seeds 172.17.0.2 to specify seed in this docker image, in fact check the log of n2, it said:
getopt: invalid option -- 's'
getopt: invalid option -- 'e'
getopt: invalid option -- 'e'
getopt: invalid option -- 'd'
getopt: invalid option -- 's'
Error parsing arguments! Unknown argument "172.17.0.2"
And from it's doc, CASSANDRA_SEEDS env is the correct way, like next:
docker run --name n2 -d -e CASSANDRA_SEEDS=172.17.0.2 cassandra:3.11.4
Results:
shubuntu1#shubuntu1:~$ docker run --name n1 -d cassandra:3.11.4
1d1d95f0caeff471c409cd8eda2e77aa5d9b3a60831c284937c305e823016885
shubuntu1#shubuntu1:~$ docker exec -it n1 nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 112.85 KiB 256 100.0% c6117826-2fff-48a2-964b-ba403e972154 rack1
shubuntu1#shubuntu1:~$ docker run --name n2 -d -e CASSANDRA_SEEDS=172.17.0.2 cassandra:3.11.4
37e5b84ab92b8b9087e6cff37b146b1f7e337ec9499ce907408abeba11f1985c
Wait a few time, then check again, we find the cluster has 2 nodes now:
shubuntu1#shubuntu1:~$ docker exec -it n1 nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 112.98 KiB 256 100.0% e61857d3-b924-4fe9-9a68-03d603de7c38 rack1
UN 172.17.0.2 108.62 KiB 256 100.0% c6117826-2fff-48a2-964b-ba403e972154 rack1

Cassandra: How to increase the number of node instances in localhost

I am able to start two cassandra node instances up and running through docker.
docker run --name n1 -d tobert/cassandra -dc DC1 -rack RAC1
docker run --name n2 -d tobert/cassandra -seeds 172.17.0.2 -dc DC2 -rack RAC1
When I try to start the new node instance n3, then it doesn't through any error but I do no see any n3 instance came up, I am seeing only 2 nodes.
$ docker run --name n3 -d tobert/cassandra -seeds 172.17.0.2 -dc DC1 -rack RAC2
XXX
$ docker ps (doesnt show the third cassandra node)
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
8ab64fa86819 tobert/cassandra "/bin/cassandra-docke" 41 minutes ago Up 41 minutes 7000/tcp, 7199/tcp, 9042/tcp, 9160/tcp, 61621/tcp n2
125fc4ffba4d tobert/cassandra "/bin/cassandra-docke" 42 minutes ago Up 42 minutes 7000/tcp, 7199/tcp, 9042/tcp, 9160/tcp, 61621/tcp n1
$ docker exec -it n1 nodetool status
Datacenter: DC2
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 82.43 KB 256 100.0% XXX RAC1
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.2 51.48 KB 256 100.0% XXX RAC1
Will anyone please let me know why is this happening. What conf need to be done to initiate more node instances. It is clear that the node instances more than 2 in my localhost is an issue here. Why?
Looks like sometimes we need to run the docker run command more than once in-order to start-up the new node. No idea why this happens.
I have assigned memory of 4GB to the docker container using command boot2docker --memory 4096 init which gave some space to add a new node which I was expecting to.
Finally here are the nodes that are up and running
$ docker exec -it n1 nodetool status
Datacenter: DC1
===============
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 98.91 KB 256 64.5% 30156883-aafe-43b8-b8ee-fec2c9225778 RAC2
UN 172.17.0.2 51.51 KB 256 68.3% 486f457c-8be2-4844-9cd0-d5ef37b46cea RAC1
UN 172.17.0.4 98.97 KB 256 67.3% d19ad6a1-8138-4283-815c-3b223a33c987 RAC1

Cassandra Nodes not linking in Docker

I am watching a kind of old video on PluralSight for Cassandra and linking works with the method below. However, it is not working with the current docker version. This is how I am linking different nodes. For example:
docker run --name=n1 -d tobert/cassandra
docker run --name n2 -d tobert/cassandra -seeds 172.17.0.7
172.17.0.7 is the IP address when I run the command
docker inspect -f '{{ .NetworkSettings.IPAddress}}' n1
However, only one node is allowed to run at a time is seems. When I run the command
docker ps
or
docker exec -it n1 nodetool status
only one of the containers are running. When I try to inspect a container's ip address, it returns empty. Is there another way to link cassandra nodes in docker?
Manage to resolve this.
It appears to have been an issue with the docker machine created by the "Docker quickstart terminal". Perhaps related to default memory of 1024?
Recreating the machine solved it for me
docker-machine rm default
docker-machine create -d virtualbox --virtualbox-memory=4096 default
Yes, Dashu is right, you need more than the default memory to run multiple Cassandra instances. See similar Twitter thread here: https://twitter.com/perksc/status/641159044225466368.
The -seeds parameter is specific to the entrypoint of this Cassandra docker container and facilitates Cassandra's own clustering (see Github project here: https://github.com/tobert/cassandra-docker). With this feature you don't need to use Docker's own container linking to establish a cluster.
(I'm the author of the Pluralsight course in question. Funny that the course is less than a year old, but so much has changed in Docker since then!)
I was having the same problem. It is solved with using the memory parameter -m 4g. So I initialize the nodes with 4 g.
A - Changing The Docker Memory
And it is good to increase the Docker Memory;
B - My Setup
Windows Version: Windows 10 Pro
Memory: 16 gb
Docker version;
docker --version
Docker version 18.09.2, build 6247962
C - Solution Demo
Initializing 1st cassandra node;
docker run --name=n1 -d -m 4g tobert/cassandra
Getting the ip of the first node;
docker inspect -f "{{ .NetworkSettings.IPAddress }}" n1
The output of the above command is;
172.17.0.3
Initializing the second Cassandra node linking with the first one;
docker run --name n2 -d -m 4g tobert/cassandra -seeds 172.17.0.3
Running the nodetools status command at first node;
docker exec -it n1 nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 51.5 KB 256 100.0% 002150d0-90b9-4f8f-861f-0d0205e3ea72 rack1
UN 172.17.0.4 82.46 KB 256 100.0% 05c06381-778e-4989-860b-756d05c8cfbc rack1
Running the nodetools status command at second node;
docker exec -it n2 nodetool status
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 51.5 KB 256 100.0% 002150d0-90b9-4f8f-861f-0d0205e3ea72 rack1
UN 172.17.0.4 82.46 KB 256 100.0% 05c06381-778e-4989-860b-756d05c8cfbc rack1
You can link docker containers with --link flag:
docker run --name n1 tobert/cassandra
docker run --name n2 --link n1:cassandra tobert/cassandra -seeds cassandra
Communication across links, from docker documentation, contains detailed explanation how to use --link flag.
I also run your commands and it works on my machine.
Below is output of the command: docker exec -it n1 nodetool status:
Datacenter: datacenter1
=======================
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Tokens Owns (effective) Host ID Rack
UN 172.17.0.3 72 KB 256 100.0% f0a34a45-5f7a-46ff-8fe6-1cf5ff36a3e3 rack1
UN 172.17.0.2 51.46 KB 256 100.0% 8036177e-515c-42b1-9263-3b815c25bde6 rack1
Also, when -seed parameter is wrong (not existing ip address) second container is waiting for a while and after ~30s terminates with exeception:
ERROR [main] 2016-02-07 19:12:11,081 CassandraDaemon.java:541 - Exception encountered during startup
java.lang.RuntimeException: Unable to gossip with any seeds
at org.apache.cassandra.gms.Gossiper.doShadowRound(Gossiper.java:1307) ~[apache-cassandra-2.1.7.jar:2.1.7]
at org.apache.cassandra.service.StorageService.checkForEndpointCollision(StorageService.java:533) ~[apache-cassandra-2.1.7.jar:2.1.7]
So I think n2 is not able to access n1 - please double check your n1 ip address (to check your n2 logs run: docker exec xxxx tail -f /data/log/system.log -n 100, where xxxx - n2 container id).
If you do not have any specific requirements on Cassandra version you can also check image from official repository: https://hub.docker.com/_/cassandra/.

connection problem with cassandra

I m new to cassandra.I m trying to connect to cassandra bt couldnot connect.
the steps i m following are
1.start the server with command -
/root/Documents/apache-cassandra-0.6.6/bin/cassandra -f
2.on another terminal i m giving command
/root/Documents/apache-cassandra-0.6.6/bin/cassandra-cli
which is saying welcome to cassandra cli
3.then i m connecting too cassandra by giving the command
/root/Documents/apache-cassandra-0.6.6/bin/cassandra-cli
but i m getting exception as "Exception connecting to 10.10.10.142/9160 - java.net.NoRouteToHostException: No route to host
"
can anyone help me why i m getting such exception.
This has "nothing" to do with cassandra.
The documentation (regarding NoRouteToHostException) states that:
"Signals that an error occurred while attempting to connect a socket to a remote address and port. Typically, the remote host cannot be reached because of an intervening firewall, or if an intermediate router is down. "
Another option to consider is to add the port 7199 to the firewall or just to test it to see if you can access a 2 node system is to turn off the firewall in linux using " sudo service firewalld stop"
[dse#orion conf]$ dsetool status mars
DC: Cassandra Workload: Cassandra Graph: no
Status=Up/Down
|/ State=Normal/Leaving/Joining/Moving
-- Address Load Effective-Ownership VNodes Rack Health [0,1]
UN 10.0.0.165 250.03 KiB 100.00% 1 rack1 0.20
UN 10.0.0.20 656.65 KiB 100.00% 256 rack1 0.40

Resources