├── Dockerfile ├── LICENSE ├── README.md ├── agent-run ├── cassandra-run └── cassandra.yaml /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM abh1nav/java7 2 | 3 | MAINTAINER Abhinav Ajgaonkar 4 | 5 | # Download and extract Cassandra 6 | RUN \ 7 | mkdir /opt/cassandra; \ 8 | wget -O - http://www.us.apache.org/dist/cassandra/2.1.5/apache-cassandra-2.1.5-bin.tar.gz \ 9 | | tar xzf - --strip-components=1 -C "/opt/cassandra"; 10 | 11 | # Download and extract DataStax OpsCenter Agent 12 | RUN \ 13 | mkdir /opt/agent; \ 14 | wget -O - http://downloads.datastax.com/community/datastax-agent-5.1.0.tar.gz \ 15 | | tar xzf - --strip-components=1 -C "/opt/agent"; 16 | 17 | ADD . /src 18 | 19 | # Copy over daemons 20 | RUN \ 21 | cp /src/cassandra.yaml /opt/cassandra/conf/; \ 22 | mkdir -p /etc/service/cassandra; \ 23 | cp /src/cassandra-run /etc/service/cassandra/run; \ 24 | mkdir -p /etc/service/agent; \ 25 | cp /src/agent-run /etc/service/agent/run 26 | 27 | # Expose ports 28 | EXPOSE 7199 7000 7001 9160 9042 29 | 30 | WORKDIR /opt/cassandra 31 | 32 | CMD ["/sbin/my_init"] 33 | 34 | # Clean up 35 | RUN apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2014 Abhinav Ajgaonkar 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Cassandra 2.1.5 as a Docker container. For development use only. 2 | 3 | ## Quickstart 4 | 5 | ### TL;DR 6 | 7 | Paste this into your terminal to start a 5 node cluster with OpsCenter: 8 | 9 | ``` 10 | bash <(curl -sL http://bit.ly/docker-cassandra) 11 | ``` 12 | 13 | OR, if you don't trust the one-liner, here are its contents: 14 | 15 | ``` 16 | #!/bin/bash 17 | docker pull abh1nav/opscenter:latest 18 | docker pull abh1nav/cassandra:latest 19 | echo "Starting OpsCenter" 20 | docker run -d --name opscenter abh1nav/opscenter:latest 21 | sleep 10 22 | OPS_IP=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' opscenter) 23 | echo "Starting node cass1" 24 | docker run -d --name cass1 -e OPS_IP=$OPS_IP abh1nav/cassandra:latest 25 | sleep 30 26 | SEED_IP=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' cass1) 27 | for name in cass{2..5}; do 28 | echo "Starting node $name" 29 | docker run -d --name $name -e SEED=$SEED_IP -e OPS_IP=$OPS_IP abh1nav/cassandra:latest 30 | sleep 30 31 | done 32 | echo "Registering cluster with OpsCenter" 33 | curl \ 34 | http://$OPS_IP:8888/cluster-configs \ 35 | -X POST \ 36 | -d \ 37 | "{ 38 | \"cassandra\": { 39 | \"seed_hosts\": \"$SEED_IP\" 40 | }, 41 | \"cassandra_metrics\": {}, 42 | \"jmx\": { 43 | \"port\": \"7199\" 44 | } 45 | }" > /dev/null 46 | echo "Go to http://$OPS_IP:8888/" 47 | ``` 48 | 49 | ## Manual Mode 50 | 51 | ### OpsCenter 52 | Skip this section if you don't want to run OpsCenter. 53 | 54 | Pull the image and launch OpsCenter. 55 | 56 | ``` 57 | docker pull abh1nav/cassandra:latest 58 | docker run -d --name opscenter abh1nav/opscenter:latest 59 | ``` 60 | 61 | Grab the OpsCenter IP: 62 | 63 | ``` 64 | OPS_IP=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' opscenter) 65 | ``` 66 | 67 | ### Single Node 68 | Pull the image. 69 | 70 | ``` 71 | docker pull abh1nav/cassandra:latest 72 | ``` 73 | 74 | Launch the node 75 | 76 | - without OpsCenter: 77 | 78 | ``` 79 | docker run -d --name cass1 abh1nav/cassandra:latest 80 | ``` 81 | 82 | - with OpsCenter: 83 | 84 | ``` 85 | docker run -d --name cass1 -e OPS_IP=$OPS_IP abh1nav/cassandra:latest 86 | ``` 87 | 88 | Grab the seed node's IP using: 89 | 90 | ``` 91 | SEED_IP=$(docker inspect -f '{{ .NetworkSettings.IPAddress }}' cass1) 92 | ``` 93 | 94 | Connect to it using CQLSH: 95 | 96 | ``` 97 | cqlsh $SEED_IP 98 | ``` 99 | 100 | ### Multiple Nodes 101 | 102 | Follow the single node setup to get the first node running and keep track of its IP. Run the following to launch the other nodes in the cluster: 103 | - without OpsCenter: 104 | 105 | ``` 106 | for name in cass{2..5}; do 107 | echo "Starting node $name" 108 | docker run -d --name $name -e SEED=$SEED_IP abh1nav/cassandra:latest 109 | sleep 30 110 | done 111 | ``` 112 | 113 | - with OpsCenter: 114 | 115 | ``` 116 | for name in cass{2..5}; do 117 | echo "Starting node $name" 118 | docker run -d --name $name -e SEED=$SEED_IP -e OPS_IP=$OPS_IP abh1nav/cassandra:latest 119 | sleep 30 120 | done 121 | ``` 122 | 123 | Once all the nodes are up, check cluster status using: 124 | 125 | ``` 126 | nodetool --host $SEED_IP status 127 | ``` 128 | 129 | or, if you installed OpsCenter, go to `http://$OPS_IP:8888` and choose the "Add Existing Cluster option". 130 | -------------------------------------------------------------------------------- /agent-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [[ -z $OPS_IP ]]; then 3 | echo "No OPS_IP provided, agent won't start" 4 | tail -f /dev/null 5 | else 6 | echo "OpsCenter IP is: $OPS_IP" 7 | if [ ! -f /root/.agentconfig ]; then 8 | echo "Filling in the blanks inside address.yaml" 9 | cd /opt/agent/conf 10 | echo "stomp_interface: $OPS_IP" >> ./address.yaml 11 | touch /root/.agentconfig 12 | fi 13 | 14 | # Wait 2 mins and start agent 15 | echo "Sleeping 2min before starting agent" 16 | sleep 30 17 | cd /opt/agent 18 | bin/datastax-agent -f 19 | fi 20 | -------------------------------------------------------------------------------- /cassandra-run: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Grab the container IP 4 | ADDR=$(/sbin/ifconfig eth0 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}') 5 | echo "IP Address is: $ADDR" 6 | 7 | # Check if a seed was provided 8 | SEED=${SEED:=$ADDR} 9 | echo "Seed is: $SEED" 10 | 11 | if [ ! -f /root/.cassconfig ]; then 12 | echo "Filling in the blanks inside cassandra.yaml" 13 | # Target files 14 | ENV_FILE=/opt/cassandra/conf/cassandra-env.sh 15 | CONF_FILE=/opt/cassandra/conf/cassandra.yaml 16 | # Add heap settings 17 | echo MAX_HEAP_SIZE="4G" >> $ENV_FILE 18 | echo HEAP_NEWSIZE="800M" >> $ENV_FILE 19 | # Add broadcast IPs 20 | echo "listen_address: $ADDR" >> $CONF_FILE 21 | echo "broadcast_rpc_address: $ADDR" >> $CONF_FILE 22 | echo "rpc_address: 0.0.0.0" >> $CONF_FILE 23 | # Add seed info 24 | echo "seed_provider:" >> $CONF_FILE 25 | echo " - class_name: org.apache.cassandra.locator.SimpleSeedProvider" >> $CONF_FILE 26 | echo " parameters:" >> $CONF_FILE 27 | echo " - seeds: \"$SEED\"" >> $CONF_FILE 28 | touch /root/.cassconfig 29 | fi 30 | 31 | # Start server 32 | cd /opt/cassandra 33 | bin/cassandra -f 34 | -------------------------------------------------------------------------------- /cassandra.yaml: -------------------------------------------------------------------------------- 1 | cluster_name: 'Test Cluster' 2 | num_tokens: 256 3 | hinted_handoff_enabled: true 4 | max_hint_window_in_ms: 10800000 # 3 hours 5 | hinted_handoff_throttle_in_kb: 1024 6 | max_hints_delivery_threads: 2 7 | batchlog_replay_throttle_in_kb: 1024 8 | authenticator: AllowAllAuthenticator 9 | authorizer: AllowAllAuthorizer 10 | permissions_validity_in_ms: 2000 11 | partitioner: org.apache.cassandra.dht.Murmur3Partitioner 12 | data_file_directories: 13 | - /opt/cassandra/data 14 | commitlog_directory: /opt/cassandra/commitlog 15 | disk_failure_policy: stop 16 | commit_failure_policy: stop 17 | key_cache_size_in_mb: 18 | key_cache_save_period: 14400 19 | row_cache_size_in_mb: 0 20 | row_cache_save_period: 0 21 | counter_cache_size_in_mb: 22 | counter_cache_save_period: 7200 23 | commitlog_sync: periodic 24 | commitlog_sync_period_in_ms: 10000 25 | commitlog_segment_size_in_mb: 32 26 | concurrent_reads: 32 27 | concurrent_writes: 32 28 | concurrent_counter_writes: 32 29 | memtable_allocation_type: heap_buffers 30 | index_summary_capacity_in_mb: 31 | index_summary_resize_interval_in_minutes: 60 32 | trickle_fsync: false 33 | trickle_fsync_interval_in_kb: 10240 34 | storage_port: 7000 35 | ssl_storage_port: 7001 36 | start_native_transport: true 37 | native_transport_port: 9042 38 | start_rpc: true 39 | rpc_port: 9160 40 | rpc_keepalive: true 41 | rpc_server_type: sync 42 | thrift_framed_transport_size_in_mb: 15 43 | incremental_backups: false 44 | snapshot_before_compaction: false 45 | auto_snapshot: true 46 | tombstone_warn_threshold: 1000 47 | tombstone_failure_threshold: 100000 48 | column_index_size_in_kb: 64 49 | batch_size_warn_threshold_in_kb: 5 50 | compaction_throughput_mb_per_sec: 16 51 | sstable_preemptive_open_interval_in_mb: 50 52 | read_request_timeout_in_ms: 5000 53 | range_request_timeout_in_ms: 10000 54 | write_request_timeout_in_ms: 2000 55 | counter_write_request_timeout_in_ms: 5000 56 | cas_contention_timeout_in_ms: 1000 57 | truncate_request_timeout_in_ms: 60000 58 | request_timeout_in_ms: 10000 59 | cross_node_timeout: false 60 | endpoint_snitch: SimpleSnitch 61 | dynamic_snitch_update_interval_in_ms: 100 62 | dynamic_snitch_reset_interval_in_ms: 600000 63 | dynamic_snitch_badness_threshold: 0.1 64 | request_scheduler: org.apache.cassandra.scheduler.NoScheduler 65 | server_encryption_options: 66 | internode_encryption: none 67 | keystore: conf/.keystore 68 | keystore_password: cassandra 69 | truststore: conf/.truststore 70 | truststore_password: cassandra 71 | client_encryption_options: 72 | enabled: false 73 | keystore: conf/.keystore 74 | keystore_password: cassandra 75 | internode_compression: all 76 | inter_dc_tcp_nodelay: false 77 | --------------------------------------------------------------------------------