redis集群搭建笔记

下载redis源码

wget http://download.redis.io/releases/redis-5.0.7.tar.gz
tar -xvf redis-5.0.7.tar.gz

编译安装redis

yum install gcc-c++
cd redis-5.0.7
make install PREFIX=/root/redis

准备文件夹

mkdir /root/redis-cluster
mkdir /root/redis-cluster/redis01
mkdir /root/redis-cluster/redis02
mkdir /root/redis-cluster/redis03
mkdir /root/redis-cluster/redis04
mkdir /root/redis-cluster/redis05
mkdir /root/redis-cluster/redis06

整理配置文件

将/root/redis/bin中的所有文件复制到redis01-06中, /root/redis-cluster/redis01/redis.conf文件内容修改

port 7001
cluster-enabled yes

删除快照文件dump.rdb redis02-redis06类似

编写脚本同时启动6个redis服务

start-all.sh

cd redis01
./redis-server redis.conf &
cd ..
cd redis02
./redis-server redis.conf &
cd ..
cd redis03
./redis-server redis.conf &
cd ..
cd redis04
./redis-server redis.conf &
cd ..
cd redis05
./redis-server redis.conf &
cd ..
cd redis06
./redis-server redis.conf &
cd ..

加上权限chmod +x start-all.sh,启动6个redis服务

连成cluster

./redis-cli --cluster create 192.168.126.131:7001 192.168.126.131:7002 192.168.126.131:7003 192.168.126.131:7004 192.168.126.131:7005 192.168.126.131:7006 --cluster-replicas 1

结束

总结

第一步:以cluster模式启动6个redis服务 第二步:连接以上服务