Cassandra

無法讓 Docker 中的 Cassandra 與集群通信

  • November 28, 2017

嘗試使用官方 docker 映像讓 Cassandra 在 docker 中執行。當我執行以下程式碼行時,它會啟動然後停止 docker 而不連接到集群。我檢查了該cassandra.yaml文件,它看起來就像我集群上的其他節點一樣。文件也一樣cassandra-rackdc.properties。docker 可以 ping 所有其他電腦。

我執行以下和一些推導:

docker run --name cassandra -i \
-v /media/mcamp/HDD/Docker/CampgroundContainer1:/var/lib/cassandra \
-e CASSANDRA_SEEDS="192.168.0.114, 192.168.0.101, 192.168.0.106" \
-e CASSANDRA_CLUSTER_NAME=CampCluster \
-e CASSANDRA_DC=campground-wireless \
-e CASSANDRA_RACK=Docker1 \
-e CASSANDRA_ENDPOINT_SNITCH=GossipingPropertyFileSnitch \
-e CASSANDRA_START_RPC=true \
-e CASSANDRA_LISTEN_ADDRESS=172.17.0.2 \
-p 7000:7000 \
cassandra:latest

我收到以下錯誤:

INFO  [ScheduledTasks:1] 2017-11-10 03:45:39,428 TokenMetadata.java:498 - Updating topology for all endpoints that have changed
Exception (java.lang.RuntimeException) encountered during startup: Unable to gossip with any seeds
java.lang.RuntimeException: Unable to gossip with any seeds
   at org.apache.cassandra.gms.Gossiper.doShadowRound(Gossiper.java:1415)
   at org.apache.cassandra.service.StorageService.checkForEndpointCollision(StorageService.java:550)
   at org.apache.cassandra.service.StorageService.prepareToJoin(StorageService.java:801)
   at org.apache.cassandra.service.StorageService.initServer(StorageService.java:666)
   at org.apache.cassandra.service.StorageService.initServer(StorageService.java:612)
   at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:393)
   at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:600)
   at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:689)
ERROR [main] 2017-11-10 03:46:08,466 CassandraDaemon.java:706 - Exception encountered during startup
java.lang.RuntimeException: Unable to gossip with any seeds
   at org.apache.cassandra.gms.Gossiper.doShadowRound(Gossiper.java:1415) ~[apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.StorageService.checkForEndpointCollision(StorageService.java:550) ~[apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.StorageService.prepareToJoin(StorageService.java:801) ~[apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.StorageService.initServer(StorageService.java:666) ~[apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.StorageService.initServer(StorageService.java:612) ~[apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.CassandraDaemon.setup(CassandraDaemon.java:393) [apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:600) [apache-cassandra-3.11.1.jar:3.11.1]
   at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:689) [apache-cassandra-3.11.1.jar:3.11.1]
INFO  [StorageServiceShutdownHook] 2017-11-10 03:46:08,469 HintsService.java:220 - Paused hints dispatch
WARN  [StorageServiceShutdownHook] 2017-11-10 03:46:08,469 Gossiper.java:1540 - No local state, state is in silent shutdown, or node hasn't joined, not announcing shutdown
INFO  [StorageServiceShutdownHook] 2017-11-10 03:46:08,469 MessagingService.java:984 - Waiting for messaging service to quiesce
INFO  [ACCEPT-/172.17.0.2] 2017-11-10 03:46:08,470 MessagingService.java:1338 - MessagingService has terminated the accept() thread
INFO  [StorageServiceShutdownHook] 2017-11-10 03:46:09,653 HintsService.java:220 - Paused hints dispatch

我認為問題可能是您沒有設置CASSANDRA_BROADCAST_ADDRESSCassandra 在與其他節點通信時使用的參數。預設情況下,它將其設置為值CASSANDRA_LISTEN_ADDRESS,但在您的情況下,此地址是 Docker 網路的地址,因此其他節點將無法訪問您的 Docker 實例。

您需要設置CASSANDRA_BROADCAST_ADDRESS託管 Docker 的機器的 IP 地址。

引用自:https://dba.stackexchange.com/questions/190610