diff --git a/Dockerfile b/Dockerfile index b950918..ee1d17d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,9 @@ # Use the official Cassandra 4.1.3 image FROM cassandra:4.1.3 +RUN apt-get update && apt-get install -y iputils-ping less locate + + # Environment variables to configure Cassandra ENV CASSANDRA_CLUSTER_NAME=TestCluster ENV CASSANDRA_NUM_TOKENS=256 @@ -17,6 +20,13 @@ COPY data/dev_keyspace_schema.cql /docker-entrypoint-initdb.d/dev_keyspace_schem COPY scripts/setup.sh /setup.sh RUN chmod +x /setup.sh +# Copy cassandra.yaml +COPY cassandra.yaml /etc/cassandra/ + +# Copy cassandra-rackdc.properties and substitute environment variables +COPY cassandra-rackdc.properties /etc/cassandra/ +RUN envsubst < /etc/cassandra/cassandra-rackdc.properties > /etc/cassandra/cassandra-rackdc.properties + # Set the entrypoint ENTRYPOINT ["/setup.sh"] @@ -24,4 +34,4 @@ ENTRYPOINT ["/setup.sh"] EXPOSE 7000 7001 7199 9042 9160 # Add health check -HEALTHCHECK --interval=30s --timeout=10s --retries=5 CMD cqlsh -e "DESCRIBE KEYSPACES" || exit 1 +# HEALTHCHECK --interval=30s --timeout=10s --retries=5 CMD cqlsh -e "DESCRIBE KEYSPACES" || exit 1 diff --git a/README.md b/README.md index 38f17f6..fcd95a7 100644 --- a/README.md +++ b/README.md @@ -29,8 +29,8 @@ run a single service: open bash on server -* cassandra1: `docker exec -it cassandra-cassandra1 /bin/sh` -* cassandra2: `docker exec -it cassandra-cassandra2 /bin/sh` -* cassandra3: `docker exec -it cassandra-cassandra3 /bin/sh` +* cassandra1: `docker exec -it cassandra1 /bin/bash` +* cassandra2: `docker exec -it cassandra2 /bin/bash` +* cassandra3: `docker exec -it cassandra3 /bin/bash` diff --git a/cassandra-rackdc.properties b/cassandra-rackdc.properties new file mode 100644 index 0000000..eec8a07 --- /dev/null +++ b/cassandra-rackdc.properties @@ -0,0 +1,2 @@ +dc=${CASSANDRA_DC} +rack=${CASSANDRA_RACK} diff --git a/cassandra.yaml b/cassandra.yaml new file mode 100644 index 0000000..51fe15c --- /dev/null +++ b/cassandra.yaml @@ -0,0 +1,27 @@ +# Seed provider +seed_provider: + - class_name: org.apache.cassandra.locator.SimpleSeedProvider + parameters: + - seeds: "${CASSANDRA_SEEDS}" + +# Address to bind to and tell other Cassandra nodes to connect to +listen_address: "${CASSANDRA_LISTEN_ADDRESS}" + +# Address to broadcast to other Cassandra nodes +broadcast_address: "${CASSANDRA_BROADCAST_ADDRESS}" + +# Address to bind the RPC server (default: same as listen_address) +rpc_address: 0.0.0.0 + +# Address to broadcast to clients +broadcast_rpc_address: "${CASSANDRA_RPC_ADDRESS}" + +# Native transport port for CQL +native_transport_port: 9042 + +# Snitch configuration +endpoint_snitch: GossipingPropertyFileSnitch + +# DC and RACK settings +dc: ${CASSANDRA_DC} +rack: ${CASSANDRA_RACK} diff --git a/docker-compose.yml b/docker-compose.yml index d36fdf0..a8281a5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,12 +2,16 @@ version: '3.8' services: cassandra1: - build: . + image: cassandra:4.1.3 container_name: cassandra1 env_file: - .env environment: - CASSANDRA_BROADCAST_ADDRESS=cassandra1 + - CASSANDRA_LISTEN_ADDRESS=cassandra1 + - CASSANDRA_RPC_ADDRESS=cassandra1 + - CASSANDRA_DC=DC1 + - CASSANDRA_RACK=RAC1 - PRIMARY_NODE=true volumes: - ./data/dumps/node1:/dump @@ -17,19 +21,23 @@ services: - "9042:9042" networks: - cassandra-net - healthcheck: - test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] - interval: 30s - timeout: 10s - retries: 5 + # healthcheck: + # test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] + # interval: 30s + # timeout: 10s + # retries: 5 cassandra2: - build: . + image: cassandra:4.1.3 container_name: cassandra2 env_file: - .env environment: - CASSANDRA_BROADCAST_ADDRESS=cassandra2 + - CASSANDRA_LISTEN_ADDRESS=cassandra2 + - CASSANDRA_RPC_ADDRESS=cassandra2 + - CASSANDRA_DC=DC1 + - CASSANDRA_RACK=RAC1 - PRIMARY_NODE=false volumes: - ./data/dumps/node2:/dump @@ -37,22 +45,26 @@ services: - ./logs/node2:/var/log/cassandra networks: - cassandra-net - depends_on: - cassandra1: - condition: service_healthy - healthcheck: - test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] - interval: 30s - timeout: 10s - retries: 5 + # depends_on: + # cassandra1: + # condition: service_healthy + # healthcheck: + # test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] + # interval: 30s + # timeout: 10s + # retries: 5 cassandra3: - build: . + image: cassandra:4.1.3 container_name: cassandra3 env_file: - .env environment: - CASSANDRA_BROADCAST_ADDRESS=cassandra3 + - CASSANDRA_LISTEN_ADDRESS=cassandra3 + - CASSANDRA_RPC_ADDRESS=cassandra3 + - CASSANDRA_DC=DC1 + - CASSANDRA_RACK=RAC1 - PRIMARY_NODE=false volumes: - ./data/dumps/node3:/dump @@ -60,14 +72,14 @@ services: - ./logs/node3:/var/log/cassandra networks: - cassandra-net - depends_on: - cassandra2: - condition: service_healthy - healthcheck: - test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] - interval: 30s - timeout: 10s - retries: 5 + # depends_on: + # cassandra2: + # condition: service_healthy + # healthcheck: + # test: ["CMD", "cqlsh", "-e", "DESCRIBE KEYSPACES"] + # interval: 30s + # timeout: 10s + # retries: 5 networks: cassandra-net: