本实验在一台主机上创建6个实例,以不同的端口号区分,模拟6个节点。
下载安装包
代码语言:javascript复制wget https://download.redis.io/releases/redis-6.2.1.tar.gz
安装redis
代码语言:javascript复制tar xf redis-6.2.1.tar.gz
cd redis-6.2.1
make
make install PREFIX=/usr/local/redis
部署
每个实例创建一个目录
代码语言:javascript复制mkdir cluster/{7000,7001,7002,7003,7004,7005}
拷贝redis命令到每个实例的目录中
代码语言:javascript复制cp /usr/local/redis/bin/redis-server cluster/7000
cp /usr/local/redis/bin/redis-server cluster/7001
cp /usr/local/redis/bin/redis-server cluster/7002
cp /usr/local/redis/bin/redis-server cluster/7003
cp /usr/local/redis/bin/redis-server cluster/7004
cp /usr/local/redis/bin/redis-server cluster/7005
每个实例创建一个配置文件
代码语言:javascript复制vim cluster/7000/redis.conf
port 7000
cluster-enabled yes # 启用cluster
cluster-config-file 7000.conf
cluster-node-timeout 5000
appendonly yes
启动所有实例
代码语言:javascript复制cluster/7000/redis-server cluster/7000/redis.conf
创建Cluster集群
代码语言:javascript复制/usr/local/redis/bin/redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 --cluster-replicas 1
--cluster-replicas表示为每一个主节点创建一个从节点。