From 2f90515c8b6ba0c3c526ed5d27f935122d3dd992 Mon Sep 17 00:00:00 2001 From: Tomas Repik Date: Jun 06 2017 06:07:20 +0000 Subject: environment variables included --- diff --git a/Dockerfile b/Dockerfile index e728c2b..ec7a8ed 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,7 +39,7 @@ LABEL io.k8s.description="$SUMMARY" \ ENV CASSANDRA_VERSION=3.9 \ # Set paths to avoid hard-coding them in scripts. HOME=/var/lib/cassandra - CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/cassandra + #CONTAINER_SCRIPTS_PATH=/usr/share/container-scripts/cassandra # 7000: intra-node communication # 7001: TLS intra-node communication @@ -58,7 +58,6 @@ ADD root / # Container setup # RUN chown cassandra:0 /etc/cassandra/cassandra.yaml && \ -# sed -ri 's/(- seeds:).*/\1 "'"172.17.0.2"'"/' /etc/cassandra/cassandra.yaml && \ # sed -ri 's/(^authenticator:).*/\1 PasswordAuthenticator/' /etc/cassandra/cassandra.yaml && \ # sed -ri 's/(^authorizer:).*/\1 CassandraAuthorizer/' /etc/cassandra/cassandra.yaml && \ # chown -R cassandra.0 /var/lib/cassandra/ && \ diff --git a/README.md b/README.md deleted file mode 100644 index 9d3ab3c..0000000 --- a/README.md +++ /dev/null @@ -1,84 +0,0 @@ -Cassandra container -=================== - -This repository contains Dockerfiles for Cassandra images for general usage and OpenShift. - -Description ------------ - -This container image provides a containerized packaging of the Cassandra daemon -and client application. The cassandra server daemon accepts connections from clients -and provides access to content from Cassandra databases on behalf of the clients. -You can find more information on the Cassandra project from the project Web site -(https://cassandra.apache.org/). - -Volumes -------- - -You can also set the following mount points by passing the `-v /host:/container` flag to Docker. - -| Volume mount point | Description | -| :-------------------------- | ------------------------ | -| `/var/lib/cassandra/data` | Cassandra data directory | - -**Notice: When mouting a directory from the host into the container, ensure that the mounted -directory has the appropriate permissions and that the owner and group of the directory -matches the user UID or name which is running inside the container.** - - -Usage ------ - -For this, we will assume that you are using the `fedora/cassandra-39` image. -If you want to set only the mandatory environment variables and store the database -in the `/home/user/database` directory on the host filesystem, execute the following command: - -``` -$ docker run -d -v /home/user/database:/var/lib/cassandra/data fedora/cassandra-39 -``` - -Ports ------ - -By default, Cassandra uses 7000 for cluster communication (7001 if SSL is enabled), 9042 for native protocol clients, and 7199 for JMX. The internode communication and native protocol ports are configurable in the Cassandra Configuration File (cassandra.yaml). The JMX port is configurable in cassandra-env.sh (through JVM options). All ports are TCP. - - -Documentation -------------- - -See http://cassandra.apache.org/doc/latest/ - - -Requirements ------------- - -* Memory: For production 32 GB to 512 GB; the minimum is 8 GB for Cassandra nodes. For development in non-loading testing environments: no less than 4 GB. -* CPU: For production 16-core CPU processors are the current price-performance sweet spot. For development in non-loading testing environments: 2-core CPU processors are sufficient. -* Disk space: SSDs are recommended for Cassandra nodes. The size depends on the compaction strategy used. With SSDs, you can use a maximum of 3 to 5 TB per node of disk space for uncompressed data. -* Network: Recommended bandwidth is 1000 Mb/s (gigabit) or greater. - -More on hardware requirements on https://docs.datastax.com/en/landing_page/doc/landing_page/planning/planningHardware.html - - -Custom configuration file -------------------------- - -It is allowed to use custom configuration files for cassandra server. - -To use custom configuration file in container it has to be mounted into `/etc/cassandra/cassandra.yaml`. For example to use configuration file stored in `/home/user` directory use this option for `docker run` command: `-v /home/user/cassandra.yaml:/etc/cassandra/cassandra.yaml:Z`. - -To configure multiple JVM options a `jvm.options` file needs to be mounted into the container. For example to use configuration file stored in `/home/user` directory use this option for `docker run` command: `-v /home/user/jvm.options:/etc/cassandra/jvm.options:Z`. - - -Troubleshooting ---------------- - -The cassandra deamon in the container logs to the standard output, so the log is available in the container log. The log can be examined by running: - -docker logs - - -See also --------- - -The Dockerfile is using a cassandra rpm package from Fedora. More information is found at: https://admin.fedoraproject.org/pkgdb/package/rpms/cassandra/ diff --git a/README.md b/README.md new file mode 120000 index 0000000..5a12639 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +root/usr/share/container-scripts/cassandra/README.md \ No newline at end of file diff --git a/root/usr/bin/run-cassandra b/root/usr/bin/run-cassandra index 9cd4ec9..215429a 100755 --- a/root/usr/bin/run-cassandra +++ b/root/usr/bin/run-cassandra @@ -1,14 +1,56 @@ #!/bin/bash -set -o nounset set -o pipefail -# source ${CONTAINER_SCRIPTS_PATH}/common.sh +CASSANDRA_CONF_DIR="/etc/cassandra/" +CASSANDRA_CONF_FILE="cassandra.yaml" -# get the ip-address that the cassandra server is going to run on -SEED=$(cassandra -f 2>/dev/null | grep :7000 | cut -d'/' -f2 | cut -d':' -f1) +# check whether the user mounted in his own config file +CONFIG_OWNER=$(ls -l "$CASSANDRA_CONF_DIR" | grep "$CASSANDRA_CONF_FILE" | awk '{print $3}') -# add the ip to seeds in the config file so that one is able to gossip with the server -sed -ri 's/(- seeds:).*/\1 "'"$SEED"'"/' /etc/cassandra/cassandra.yaml +if [ "$CONFIG_OWNER" == "cassandra" ]; then + # set the seeds for succesfull gossip initialization + # if the seeds were not set as the environment variable + if [ -z "$CASSANDRA_SEEDS" ]; then + # get the ip-address that the cassandra server is going to run on + #CASSANDRA_SEEDS=$(cassandra -f 2>/dev/null | grep :7000 | cut -d'/' -f2 | cut -d':' -f1) + + # get the hostname of the machine that the cassandra server is going to run on + CASSANDRA_SEEDS=$(cat /proc/sys/kernel/hostname) + fi + + # alter the seeds in the config file + sed -ri 's/(- seeds:).*/\1 "'"$CASSANDRA_SEEDS"'"/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" + + for yaml in \ + cluster_name \ + disk_optimization_strategy \ + endpoint_snitch \ + num_tokens \ + rpc_address \ + key_cache_size_in_mb \ + concurrent_reads \ + concurrent_writes \ + memtable_allocation_type \ + memtable_cleanup_threshold \ + memtable_flush_writers \ + concurrent_compactors \ + compaction_throughput_mb_per_sec \ + counter_cache_size_in_mb \ + internode_compression \ + gc_warn_threshold_in_ms \ + ; do + var="CASSANDRA_${yaml^^}" + val="${!var}" + if [ "$val" ]; then + sed -ri 's/^(# )?('"$yaml"':).*/\2 '"$val"'/' "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" + fi + done + + # hidden viariable (not originaly in config file) + CASSANDRA_AUTO_BOOTSTRAP="${CASSANDRA_AUTO_BOOTSTRAP:-false}" + + echo "auto_bootstrap: ${CASSANDRA_AUTO_BOOTSTRAP}" >> "$CASSANDRA_CONF_DIR$CASSANDRA_CONF_FILE" +fi exec cassandra -f diff --git a/root/usr/share/container-scripts/cassandra/README.md b/root/usr/share/container-scripts/cassandra/README.md index 9d3ab3c..6243217 100644 --- a/root/usr/share/container-scripts/cassandra/README.md +++ b/root/usr/share/container-scripts/cassandra/README.md @@ -12,8 +12,44 @@ and provides access to content from Cassandra databases on behalf of the clients You can find more information on the Cassandra project from the project Web site (https://cassandra.apache.org/). -Volumes -------- +Environment variables and Volumes +--------------------------------- + +The image recognizes the following environment variables that you can set during +initialization by passing `-e VAR=VALUE` to the Docker run command. + +| Variable name | Description | +| :------------------------ | ----------------------------------------- | + + +The following environment variables influence the Cassandra configuration file. They are all optional. + +| Variable name | Description | Default +| :------------------------------------------ | -------------------------------------------------------------------- | -------------- +| CASSANDRA_CLUSTER_NAME | The name of the cluster. | 'Test Cluster' +| CASSANDRA_DISK_OPTIMIZATION_STRATEGY | The strategy for optimizing disk reads. | ssd +| CASSANDRA_ENDPOINT_SNITCH | Cassandra uses the snitch to locate nodes and route requests. | SimpleSnitch +| CASSANDRA_NUM_TOKENS | Defines the number of tokens randomly assigned to this node. | 256 +| CASSANDRA_RPC_ADDRESS | The listen address for client connections. | ' ' +| CASSANDRA_KEY_CACHE_SIZE_IN_MB | Maximum size of the key cache in memory. | ' ' +| CASSANDRA_CONCURRENT_READS | Allows operations to queue low enough in the stack so that the OS + and drives can reorder them. | 32 +| CASSANDRA_CONCURRENT_WRITES | Writes in Cassandra are rarely I/O bound, so the ideal number of + concurrent writes depends on the number of CPU cores on the node. + The recommended value is 8 × number_of_cpu_cores. | 32 +| CASSANDRA_MEMTABLE_ALLOCATION_TYPE | The method Cassandra uses to allocate and manage memtable memory. | 'heap_buffers' +| CASSANDRA_MEMTABLE_CLEANUP_THRESHOLD | Ratio used for automatic memtable flush. | 0.5 +| CASSANDRA_MEMTABLE_FLUSH_WRITERS | The number of memtable flush writer threads. | 1 +| CASSANDRA_CONCURRENT_COMPACTORS | Number of concurrent compaction processes allowed to run + simultaneously on a node. | ' ' +| CASSANDRA_COMPACTION_THROUGHPUT_MB_PER_SEC | Throttles compaction to the specified Mb/second across the instance. | 16 +| CASSANDRA_COUNTER_CACHE_SIZE_IN_MB | Maximum size of the counter cache in memory. | ' ' +| CASSANDRA_INTERNODE_COMPRESSION | Controls whether traffic between nodes is compressed. | all +| CASSANDRA_GC_WARN_THRESHOLD_IN_MS | Any GC pause longer than this interval is logged at the WARN level. | 1000 +| CASSANDRA_AUTO_BOOTSTRAP | It causes new (non-seed) nodes migrate the right data to themselves + automatically. | true + +More deatils about each variable can be found at: http://docs.datastax.com/en/cassandra/3.0/cassandra/configuration/configCassandra_yaml.html You can also set the following mount points by passing the `-v /host:/container` flag to Docker.