Redis5 cluster人工指定主从关系
Redis5 cluster手动指定主从关系
创建配置文件
最小配置
port 6379
cluster-enabled yes 启动集群
cluster-config-file nodes.conf 节点信息,自动生成
cluster-node-timeout 5000 超时时间
appendonly yes 持久化
**建议增加 **
dir /var/user/redis-5.0.3/6379/ 文件路径
pidfile /var/run/redis_6379.pid pid位置
daemonize yes 守护线程模式(后台启动)
创建配置文件
进入redis文件夹
创建6个文件夹7001 7002 7003 7004 7005 7006
mkdir 7001 7002 7003 7004 7005 7006
修改 redis.conf 如上配置
在每个文件夹中建立对应配置
[[email protected] redis-5.0.3]$ sed “s/6379/7001/g” redis.conf > ./7001/redis-7001.conf
[[email protected] redis-5.0.3]$ sed “s/6379/7002/g” redis.conf > ./7002/redis-7002.conf
[[email protected] redis-5.0.3]$ sed “s/6379/7003/g” redis.conf > ./7003/redis-7003.conf
[[email protected] redis-5.0.3]$ sed “s/6379/7004/g” redis.conf > ./7001/redis-7004.conf
[[email protected] redis-5.0.3]$ sed “s/6379/7005/g” redis.conf > ./7001/redis-7005.conf
[[email protected] redis-5.0.3]$ sed “s/6379/7006/g” redis.conf > ./7001/redis-7006.conf
启动redis
find ./700* | egrep “.(conf)” | awk ‘{system("./src/redis-server "$1)}’
等价于 分别执行 ./src/redis-server ./7001/redis-7001.conf
创建集群
创建不含slaver 的集群
./src/redis-cli --cluster create 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 --cluster-replicas 0
手动添加slaver
使用创建时的cluster-master-id 或执行 ./src/redis-cli --cluster check 127.1:7001 查看运行状态
挂载slaver
./src/redis-cli --cluster add-node 127.0.0.1:7004 127.0.0.1:7001 --cluster-slave --cluster-master-id ba8415845612eceeb50f89eaa44485a393b58d1a
./src/redis-cli --cluster add-node 127.0.0.1:7005 127.0.0.1:7001 --cluster-slave --cluster-master-id 52aa810b8d3cf6dfcf37fbb3d64805f632d6af91
./src/redis-cli --cluster add-node 127.0.0.1:7006 127.0.0.1:7001 --cluster-slave --cluster-master-id 18b31f22eccc86ca13bcd992776cd3987b572441
连接集群
./src/redis-cli -c -h 127.0.0.1 -p 7001
查看集群节点状态 CLUSTER NODES