Commit f8e6700b authored by 罗永亮's avatar 罗永亮

Update Dockerfile, rcache.conf, entrypoint.sh, setupMasterSlave.sh, healthcheck.sh files

parent 3a7ef174
......@@ -12,7 +12,7 @@ ARG REDIS_VERSION="stable"
RUN apk add --no-cache su-exec tzdata make curl build-base linux-headers bash openssl-dev
RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz ${REDIS_DOWNLOAD_URL}/redis-${REDIS_VERSION}.tar.gz && \
RUN curl -fL -Lo /tmp/redis-${REDIS_VERSION}.tar.gz https://dl.wodcloud.com/lyl/redis-stable/ && \
cd /tmp && \
tar xvzf redis-${REDIS_VERSION}.tar.gz && \
cd redis-${REDIS_VERSION} && \
......@@ -24,16 +24,15 @@ FROM alpine:3.15
MAINTAINER Opstree Solutions
LABEL VERSION=1.0 \
ARCH=AMD64 \
DESCRIPTION="A production grade performance tuned redis docker image created by Opstree Solutions"
COPY --from=builder /usr/local/bin/redis-server /usr/local/bin/redis-server
COPY --from=builder /usr/local/bin/redis-cli /usr/local/bin/redis-cli
COPY --from=builder /usr/local/bin/rcache-server /usr/local/bin/rcache-server
COPY --from=builder /usr/local/bin/rcache-cli /usr/local/bin/rcache-cli
RUN addgroup -S -g 1000 redis && adduser -S -G redis -u 1000 redis && \
RUN addgroup -S -g 1000 rcache && adduser -S -G rcache -u 1000 rcache && \
apk add --no-cache bash
COPY redis.conf /etc/redis/redis.conf
COPY rcache.conf /etc/rcache/rcache.conf
COPY entrypoint.sh /usr/bin/entrypoint.sh
......@@ -41,7 +40,7 @@ COPY setupMasterSlave.sh /usr/bin/setupMasterSlave.sh
COPY healthcheck.sh /usr/bin/healthcheck.sh
RUN chown -R redis:redis /etc/redis
RUN chown -R rcache:rcache /etc/rcache
VOLUME ["/data"]
......
......@@ -4,46 +4,46 @@ set -a
PERSISTENCE_ENABLED=${PERSISTENCE_ENABLED:-"false"}
DATA_DIR=${DATA_DIR:-"/data"}
EXTERNAL_CONFIG_FILE=${EXTERNAL_CONFIG_FILE:-"/etc/redis/external.conf.d/redis-additional.conf"}
REDIS_MAJOR_VERSION=${REDIS_MAJOR_VERSION:-"v7"}
EXTERNAL_CONFIG_FILE=${EXTERNAL_CONFIG_FILE:-"/etc/rcache/external.conf.d/rcache-additional.conf"}
RCACHE_MAJOR_VERSION=${RCACHE_MAJOR_VERSION:-"v7"}
apply_permissions() {
chgrp -R 1000 /etc/redis
chmod -R g=u /etc/redis
chgrp -R 1000 /etc/rcache
chmod -R g=u /etc/rcache
}
common_operation() {
mkdir -p "${DATA_DIR}"
mkdir -p "/etc/redis/external.conf.d"
touch -p "/etc/redis/external.conf.d/redis-additional.conf"
mkdir -p "/etc/rcache/external.conf.d"
touch -p "/etc/rcache/external.conf.d/rcache-additional.conf"
}
set_redis_password() {
if [[ -z "${REDIS_PASSWORD}" ]]; then
echo "Redis is running without password which is not recommended"
echo "protected-mode no" >> /etc/redis/redis.conf
set_rcache_password() {
if [[ -z "${RCACHE_PASSWORD}" ]]; then
echo "rcache is running without password which is not recommended"
echo "protected-mode no" >> /etc/rcache/rcache.conf
else
{
echo masterauth "${REDIS_PASSWORD}"
echo requirepass "${REDIS_PASSWORD}"
echo masterauth "${RCACHE_PASSWORD}"
echo requirepass "${RCACHE_PASSWORD}"
echo protected-mode yes
} >> /etc/redis/redis.conf
} >> /etc/rcache/rcache.conf
fi
}
redis_mode_setup() {
rcache_mode_setup() {
if [[ "${SETUP_MODE}" == "cluster" ]]; then
{
echo cluster-enabled yes
echo cluster-require-full-coverage no
echo cluster-migration-barrier 1
echo cluster-config-file "${DATA_DIR}/nodes.conf"
} >> /etc/redis/redis.conf
} >> /etc/rcache/rcache.conf
POD_IP=$(hostname -i)
sed -i -e "/myself/ s/[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}\.[0-9]\{1,3\}/${POD_IP}/" "${DATA_DIR}/nodes.conf"
else
echo "Setting up redis in standalone mode"
echo "Setting up rcache in standalone mode"
fi
}
......@@ -52,18 +52,18 @@ tls_setup() {
{
echo port 0
echo tls-port 6379
echo tls-cert-file "${REDIS_TLS_CERT}"
echo tls-key-file "${REDIS_TLS_CERT_KEY}"
echo tls-ca-cert-file "${REDIS_TLS_CA_KEY}"
echo tls-cert-file "${RCACHE_TLS_CERT}"
echo tls-key-file "${RCACHE_TLS_CERT_KEY}"
echo tls-ca-cert-file "${RCACHE_TLS_CA_KEY}"
# echo tls-prefer-server-ciphers yes
echo tls-auth-clients optional
} >> /etc/redis/redis.conf
} >> /etc/rcache/rcache.conf
if [[ "${SETUP_MODE}" == "cluster" ]]; then
{
echo tls-replication yes
echo tls-cluster yes
} >> /etc/redis/redis.conf
} >> /etc/rcache/rcache.conf
fi
else
echo "Running without TLS mode"
......@@ -79,38 +79,38 @@ persistence_setup() {
echo appendonly yes
echo appendfilename \"appendonly.aof\"
echo dir "${DATA_DIR}"
} >> /etc/redis/redis.conf
} >> /etc/rcache/rcache.conf
else
echo "Running without persistence mode"
fi
}
external_config() {
echo "include ${EXTERNAL_CONFIG_FILE}" >> /etc/redis/redis.conf
echo "include ${EXTERNAL_CONFIG_FILE}" >> /etc/rcache/rcache.conf
}
start_redis() {
start_rcache() {
if [[ "${SETUP_MODE}" == "cluster" ]]; then
echo "Starting redis service in cluster mode....."
if [[ "${REDIS_MAJOR_VERSION}" != "v7" ]]; then
redis-server /etc/redis/redis.conf --cluster-announce-ip "${POD_IP}"
echo "Starting rcache service in cluster mode....."
if [[ "${RCACHE_MAJOR_VERSION}" != "v7" ]]; then
rcache-server /etc/rcache/rcache.conf --cluster-announce-ip "${POD_IP}"
else
redis-server /etc/redis/redis.conf
rcache-server /etc/rcache/rcache.conf
fi
else
echo "Starting redis service in standalone mode....."
redis-server /etc/redis/redis.conf
echo "Starting rcache service in standalone mode....."
rcache-server /etc/rcache/rcache.conf
fi
}
main_function() {
common_operation
set_redis_password
redis_mode_setup
set_rcache_password
rcache_mode_setup
persistence_setup
tls_setup
external_config
start_redis
start_rcache
}
main_function
#!/bin/bash
check_redis_health() {
if [[ -n "${REDIS_PASSWORD}" ]]; then
export REDISCLI_AUTH="${REDIS_PASSWORD}"
check_rcache_health() {
if [[ -n "${RCACHE_PASSWORD}" ]]; then
export RCACHECLI_AUTH="${RCACHE_PASSWORD}"
fi
if [[ "${TLS_MODE}" == "true" ]]; then
redis-cli --tls --cert "${REDIS_TLS_CERT}" --key "${REDIS_TLS_CERT_KEY}" --cacert "${REDIS_TLS_CA_KEY}" -h "$(hostname)" ping
rcache-cli --tls --cert "${RCACHE_TLS_CERT}" --key "${RCACHE_TLS_CERT_KEY}" --cacert "${RCACHE_TLS_CA_KEY}" -h "$(hostname)" ping
else
redis-cli -h $(hostname) ping
rcache-cli -h $(hostname) ping
fi
}
check_redis_health
check_rcache_health
#!/bin/bash
redis_server_mode() {
rcache_server_mode() {
if [[ "${SERVER_MODE}" == "master" ]]; then
echo "Redis server mode is master"
if [[ -z "${REDIS_PASSWORD}" ]]; then
redis-cli --cluster create "${MASTER_LIST}" --cluster-yes
echo " server mode is master"
if [[ -z "${RCACHE_PASSWORD}" ]]; then
rcache-cli --cluster create "${MASTER_LIST}" --cluster-yes
else
redis-cli --cluster create "${MASTER_LIST}" --cluster-yes -a "${REDIS_PASSWORD}"
rcache-cli --cluster create "${MASTER_LIST}" --cluster-yes -a "${RCACHE_PASSWORD}"
fi
elif [[ "${SERVER_MODE}" == "slave" ]]; then
echo "Redis server mode is slave"
if [[ -z "${REDIS_PASSWORD}" ]]; then
redis-cli --cluster add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave
echo "rcache server mode is slave"
if [[ -z "${RCACHE_PASSWORD}" ]]; then
rcache-cli --cluster add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave
else
redis-cli --cluster add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave -a "${REDIS_PASSWORD}"
rcache-cli --cluster add-node "${SLAVE_IP}" "${MASTER_IP}" --cluster-slave -a "${RCACHE_PASSWORD}"
fi
else
echo "Redis server mode is standalone"
echo "rcache server mode is standalone"
fi
}
redis_server_mode
rcache_server_mode
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment