window 搭建redis集群

无非就是提高性能

就以三台为 不用主从结构

同样的redis复制三份

 

里面的redis.conf

我这个redis.conf是复制redis.window.conf的

里面的配置 除了改端口外 就下面复制复制 就成
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 5000
appendonly yes

然后挨个启动 发现直接点redis-server.exe 配置文件并不生效 提示什么用默认的 所以 记得 拖动redis.conf 到redis-server.exe打开 另外 可以在cmd窗口  ./redis-cli  -h 127.0.0.1 -p 6380 来链接不同主机不同端口

ok然后开始下载 rubby

下载地址

http://dl.bintray.com/oneclick/rubyinstaller/rubyinstaller-2.2.4-x64.exe

 

下载驱动

https://rubygems.org/gems/redis/versions/3.2.2

就是一个gem文件

到这个放的目录

gem install --local .\redis-3.2.2.gem

安装这个驱动

然后下载

 https://raw.githubusercontent.com/MSOpenTech/redis/3.0/src/redis-trib.rb

这个脚本文件

但是这个网站一直链接不上 于是就在github搜索一下这个脚本文件

下载好 后同样是到这个文件这里

cmd 

redis-trib.rb create --replicas 0 127.0.0.1:6380 127.0.0.1:6381 127.0.0.1:6379

会提示输入yes啥的 输入yes 有提示 slot 0 is already busy

这说明 redis有数据 到命令行窗口 挨个清空

先flushall 在cluster reset

然后在重复上面的

最后可以 ./redis-trib.rb check 127.0.0.1:6380 检查下嗯 就完了

在spring boot项目

根本就不需要什么多余的配置

只需要 一句

spring.redis.cluster.nodes=127.0.0.1:6380,127.0.0.1:6381,127.0.0.1:6379

在测试类里

package com.example.demo;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.junit4.SpringRunner;

@RunWith(SpringRunner.class)
@SpringBootTest
public class YanjunGatewayApplicationTests {
   @Autowired
    private StringRedisTemplate redisTemplate;

    @Test
    public void contextLoads() {
        for(int i=0; i<10;i++){
            redisTemplate.opsForValue().set("a"+i,"哈哈哈"+i);
        }
        System.out.println("success");

    }
    @Test
    public void contextLoads1() {
        for(int i=0; i<10;i++){
            String a =redisTemplate.opsForValue().get("a"+i);
            System.out.println(a);
        }
        System.out.println("success");

    }

}

 就是这么简单

windows环境下redis集群搭建搭建频繁如下: redis集群测试 01、安装Redis 02、创建6个目录Redis7001、Redis7002、Redis7003、Redis7004、Redis7005、Redis7006 03、把Redis目录下的redis.windows.conf文件分别复制到上创建创建的6个文件夹中 04、修改6个文件夹中的redis.windows.conf文件 a、修改端口,分别对应 700* b、绑定IP,这里使用的是一台电脑,都设置为127.0.0.1 c、指定数据文件(appendonly.aof)的存放位置,dir C:/MySoftPath/Java/Redis/Redis700*/ d、开启集群模式,cluster-enabled yes e、集群文件配制信息(不用设置路径,自动在对应的700*下面),cluster-config-file nodes-700*.conf f、超时时间,cluster-node-timeout 5000 g、开启aof模式,appendonly yes h、数据文件名称,appendfilename "appendonly.aof" 05、启动这6个redis 06、安装ruby环境(rubyinstaller-2.2.4-x64.exe),注意(安装所有模块),后台需要使用此环境。 07、下载ruby环境下Redis的驱动“redis-3.2.2.gem”。 08、把“redis-3.2.2.gem”放到ruby环境下进行驱动,在所在的目录运行【gem install --local redis-3.2.2.gem】 09、把redis-trib.rb集群工具放在redis目录下,使用此工具创建集群 10、创建Redis集群redis-trib.rb create --replicas 0 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006】 11、注意,如果第10步没有反应也不报错,在redis-trib.rb命令前面使用ruby 【ruby redis-trib.rb create --replicas.........】 12、最后配上别人的博客【http://www.cnblogs.com/tommy-huang/p/6240083.html】 。。。。。。。。。。。。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值