mater | slave |
192.168.216.101:6379 | 192.168.216.101:6382 |
192.168.216.101:6380 | 192.168.216.101:6383 |
192.168.216.101:6381 | 192.168.216.101:6384 |
cluster-enabled yes #这个要配置,保证重启的时候还有集群信息 cluster-config-file /usr/redis-cluster/node-6379/conf/node-6379.conf #这步骤有点重要,否则部分java客户端连接不上,比如redisson,其获取到的cluster info #节点的信息是 127.0.0.1,客户端无法连接 cluster-announce-ip 192.168.216.101 bind 127.0.0.1 192.168.216.101 daemonize yes dir /usr/redis-cluster/node-6379/data logfile /usr/redis-cluster/node-6379/logs/redis.log
依次启动好所有服务
./src/redis-server redis.conf
使用6379节点握手其他五个节点,如
cluster meet 192.168.216.101 6380
将slots分配到三个master 节点上,注意分配的时候,要在redis服务外部使用命令,否则 ...缩略失败
redis-cli -p 6379 cluster addslots {0...5461}
redis-cli -p 6380 cluster addslots {5462...10922}
redis-cli -p 6381 cluster addslots {10923...16383}
进入想要成为从节点的服务,执行命令
cluster replicate ba57aca18c0e03aedde2b739fd69338aff712d06
public static void clusterTest() { Config config = new Config(); config.useClusterServers() .setScanInterval(10000) // 集群状态扫描间隔时间,单位是毫秒 //可以用"rediss://"来启用SSL连接 .addNodeAddress("redis://192.168.216.101:6379") .addNodeAddress("redis://192.168.216.101:6380") .addNodeAddress("redis://192.168.216.101:6381"); RedissonClient redisson = Redisson.create(config); redisson.getBucket("cluster1").set("192.168.216.101:6379"); redisson.getBucket("cluster2").set("192.168.216.101:6380"); redisson.getBucket("cluster3").set("192.168.216.101:6381"); redisson.shutdown(); }