FROM redis:5.0
ADD sources.list /etc/apt/sources.list
ADD redis.conf init_cluster.sh /usr/local/etc/
RUN apt-get update && apt-get install dnsutils iproute2 -y && apt-get clean && rm -rf /var/lib/apt/lists/*
bind 0.0.0.0
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
dir /data/
port 6379
pidfile /var/run/redis.pid
logfile "redis.log"
protected-mode no
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian-security buster/updates main
deb-src http://mirrors.aliyun.com/debian-security buster/updates main
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
#!/bin/bash
#ns=$NAMESPACE
RedisPwd=$1
cluster_domain=`awk '/search/{print $2}' /etc/resolv.conf`
function cluster_init(){
sleep 3
n0=``/usr/bin/digĀ +short redis-cluster-0.redis-service.${cluster_domain}`
n1=$(/usr/bin/dig +short redis-cluster-1.redis-service.${cluster_domain})
n2=$(/usr/bin/dig +short redis-cluster-2.redis-service.${cluster_domain})
n3=$(/usr/bin/dig +short redis-cluster-3.redis-service.${cluster_domain})
n4=$(/usr/bin/dig +short redis-cluster-4.redis-service.${cluster_domain})
n5=`ip a|grep inet|tail -1|awk '{print $2}'|awk -F "/" '{print $1}'`
#n5=`/usr/bin/dig +short redis-cluster-5.redis-service.${ns}.svc.cluster.local`
#n5=$(/usr/bin/dig +short redis-cluster-5.redis-service.${ns}.svc.cluster.local)
echo "0:$n0 1:$n1 2:$n2 3:$n3 4:$n4 5:$n5"
echo yes | /usr/local/bin/redis-cli -a $RedisPwd --cluster create ${n0}:6379 ${n1}:6379 ${n2}:6379 ${n3}:6379 ${n4}:6379 ${n5}:6379 --cluster-replicas 1 && echo "redis-cluster init finshed" || echo "xxxx.... "
}
function set_password(){
sleep 5
echo "start save cluster password"
/usr/local/bin/redis-cli -h redis-cluster -p 6379 config set masterauth $RedisPwd && \
/usr/local/bin/redis-cli -h redis-cluster config set requirepass $RedisPwd
echo "end save cluster password"
sleep 1
# for i in $(seq 0 5)
# do
# redis_host=redis-cluster-${i}.redis-service.${ns}.svc.${cluster_domain}
# /usr/local/bin/redis-cli -h ${redis_host} -a $RedisPwd config set masterauth $RedisPwd
# /usr/local/bin/redis-cli -h ${redis_host} config set requirepass $RedisPwd
# /usr/local/bin/redis-cli -h ${redis_host} -a $RedisPwd config rewrite
# done
}
cluster_init && set_password
echo "ok......"
Content type
Image
Digest
Size
58.6 MB
Last updated
almost 5 years ago
docker pull linuxpy/redis:cluster-v3