# bind 127.0.0.1 port ${PORT} daemonize no dir /data/redis appendonly yes cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 15000
构建一个redis集群管理镜像
1 2 3 4 5 6 7 8 9 10
FROM ruby MAINTAINER xn<xiongneng@gmail.com> RUN gem install redis RUNmkdir /redis WORKDIR /redis ADD ./redis-unstable /redis/redis-unstable WORKDIR /redis/redis-unstable RUN make && make install RUNls /redis/redis-unstable/src/redis-cli RUN redis-cli --version
# 创建 master 和 slave 文件夹 rm -rf ./master ./slave for port in `seq 7000 7005`; do ms="master" if [ $port -ge 7003 ]; then ms="slave" fi mkdir -p ./$ms/$port/ && mkdir -p ./$ms/$port/data \ && PORT=$port envsubst < ./redis-cluster.tmpl > ./$ms/$port/redis.conf; done
# 运行docker redis 的 master 和 slave 实例 for port in `seq 7000 7005`; do ms="master" if [ $port -ge 7003 ]; then ms="slave" fi docker run -d -p $port:$port -p 1$port:1$port \ -v $PWD/$ms/$port/redis.conf:/data/redis.conf \ -v $PWD/$ms/$port/data:/data/redis \ --restart always --name redis-$ms-$port --net redis-cluster-net \ redis redis-server /data/redis.conf; done
# 组装masters : slaves 节点参数 matches="" for port in `seq 7000 7005`; do ms="master" if [ $port -ge 7003 ]; then ms="slave" fi matches=$matches$(docker inspect --format '{{(index .NetworkSettings.Networks "redis-cluster-net").IPAddress}}'"redis-$ms-${port}"):${port}" "; done