使用ruby 进行redis集群安装

环境:centos7、docker 、有外网

1、下载镜像

docker pull redis
docker pull ruby

2、建配置模板

在/home 目录下创建redis-cluster文件夹并在redis-cluster文件夹下创建配置文件redis-cluster.conf
 cd /home && mkdir redis-cluster && touch redis-cluster.conf 打开redis-cluster.conf 并插入配置信息如下:
cat <<EOF >/home/redis-cluster.conf
port \${PORT}
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
cluster-announce-ip 192.168.10.44
cluster-announce-port \${PORT}
cluster-announce-bus-port 1\${PORT}
appendonly yes
EOF

3、建网络

docker network create redis-net
docker network ls

4、建配置

for port in `seq 6000 6005`; do 
  mkdir -p /home/redis-cluster/${port}/conf && PORT=${port} envsubst < ./redis-cluster.conf > /home/redis-cluster/${port}/conf/redis.conf && mkdir -p /home/redis-cluster/${port}/data;done

5、启动redis

for port in `seq 6000 6005`; do 
  docker run -d -ti -p ${port}:${port} -p 1${port}:1${port} -v /home/redis-cluster/${port}/conf/redis.conf:/usr/local/etc/redis/redis.conf -v /home/redis-cluster/${port}/data:/data  --restart always --name redis-${port} --net redis-net --sysctl net.core.somaxconn=1024 redis redis-server /usr/local/etc/redis/redis.conf; 
done

6、加入集群

echo yes | docker run -i --rm --net redis-net ruby sh -c ' gem install redis && wget http://download.redis.io/redis-stable/src/redis-trib.rb && ruby redis-trib.rb create --replicas 1 '"$(for port in `seq 6000 6005`; do  echo -n "$(docker inspect --format '{{ (index .NetworkSettings.Networks "redis-net").IPAddress }}' "redis-${port}")":${port} ' ' ;  done)"

7、安装 redis-cli

cd /tmp
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable
make
报错折执行下面语句
make MALLOC=libc
cp src/redis-cli /usr/bin/

8、检测redis集群

redis-cli -h 192.168.10.44 -p 6000 CLUSTER NODES
redis-cli -h 192.168.10.44 -p 6000 -c
set a 3
get a

 

posted @ 2020-07-27 17:20  苍茫宇宙  阅读(601)  评论(0编辑  收藏  举报