网站建设平台推广windows优化大师是哪个公司的
做一个伪集群
配置文件:
daemonize yes
port 7777
logfile .redis-7777.log
dir ./
bind 0.0.0.0
启动6666 and 7777
现在设置主从表
但是有个问题我把服务器停掉 关系就会解除
还可以手动解除
slaveof no one 命令
配置Sentinel(哨兵)
故障转移
配置文件搞进来:
当7000停掉后:: ./src/redis-cli -p 7000 shutdown
7001 或者 7002会有一个为主机
故障转移测试
IDEA操作:
<dependencies><dependency><groupId>com.yugabyte</groupId><artifactId>jedis</artifactId><version>2.9.0-yb-11</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.12</version></dependency></dependencies>
测试:
package com.ff.test;import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;import java.util.HashSet;
import java.util.Random;
import java.util.Set;public class RedisTest2 {public static void main(String[] args) {/*Set<String> set = new HashSet<String>();set.add("192.168.200.166:26379");set.add("192.168.200.166:26380");set.add("192.168.200.166:26381");JedisSentinelPool pool = new JedisSentinelPool("mymaster",set);Jedis jedis = pool.getResource();jedis.set("hello", "java");String hello = jedis.get("hello");System.out.println(hello);jedis.close();*/String nodeName = "mymaster";Set<String> set = new HashSet<String>();set.add("192.168.200.166:26379");set.add("192.168.200.166:26380");set.add("192.168.200.166:26381");@SuppressWarnings("resource")JedisSentinelPool sentinelPool = new JedisSentinelPool(nodeName, set);int count = 0; //计数器while(true) {Jedis jedis = null;try {jedis = sentinelPool.getResource();jedis.select(1);int idx = new Random().nextInt(100000);jedis.set("k-" + idx, "v-" +idx);if(count % 100 == 0) {System.out.println("k-" +idx);}count++;} catch (Exception e) {e.printStackTrace();} finally {if(jedis != null) {jedis.close();}}try {Thread.sleep(10);} catch (InterruptedException e) {e.printStackTrace();} finally {}}}
}
一直运行 我们在将主表停掉,然后等一会就会发现转移了
故障转移的时候不可以操作Redis -----会出现脑裂 (出现两个表 网络震荡 解决不了)
在Spring下操作:
SpringBoot访问Sentinel
Redis开发规范
Redis内存管理