一. Redis集群
A. 在redis的解压目录下新建rediscluster文件夹,将redis的解压目录下的redis.conf文件拷贝到rediscluster目录下,将该文件复制六份,名字分别为:
- redis-6379.conf
- redis-6380.conf
- redis-6381.conf
- redis-6382.conf
- redis-6383.conf
- redis-6384.conf
B. 以redis-6379.conf文件为例,修改其中的内容,修改部分内容如下:
port 6379
cluster-enabled yes
cluster-config-file /redis/nodes/nodes-6379.conf #该文件和文件夹不用手动创建
cluster-node-timeout 15000
C. 分别启动六个redis服务,命令如下:
src/redis-server ../rediscluster/redis-6379.conf &
src/redis-server ../rediscluster/redis-6380.conf &
src/redis-server ../rediscluster/redis-6381.conf &
src/redis-server ../rediscluster/redis-6382.conf &
src/redis-server ../rediscluster/redis-6383.conf &
src/redis-server ../rediscluster/redis-6384.conf &
D. 配置集群,进入到redis的src目录下,执行如下命令:
./redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1
E. shell脚本启动,脚本内容如下:
#!/bin/bash
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6379.conf > /dev/null &` &&
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6380.conf > /dev/null &` &&
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6381.conf > /dev/null &` &&
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6382.conf > /dev/null &` &&
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6383.conf > /dev/null &` &&
`/redis/redis-5.0.5/src/redis-server /redis/rediscluster/redis-6384.conf > /dev/null &`
sleep 3s
`/redis/redis-5.0.5/src/redis-cli --cluster create 127.0.0.1:6379 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6382 127.0.0.1:6383 127.0.0.1:6384 --cluster-replicas 1 > /dev/null &`