中国城乡住房和城乡建设部网站首页,最精品网站建设,外贸网站建设入门,如何在个人网上建网站做一个伪集群 配置文件#xff1a;
daemonize yes
port 7777
logfile .redis-7777.log
dir ./
bind 0.0.0.0启动6666 and 7777 现在设置主从表 但是有个问题我把服务器停掉 关系就会解除
还可以手动解除 slaveof no one 命令 配置Sentinel#xff08;哨兵#… 做一个伪集群 配置文件
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操作
dependenciesdependencygroupIdcom.yugabyte/groupIdartifactIdjedis/artifactIdversion2.9.0-yb-11/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.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) {/*SetString set new HashSetString();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;SetString set new HashSetString();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内存管理