Anolis 8.6 下 Redis 7.2.0 集群搭建和配置

news2024/9/28 5:29:52

Redis 7.2.0 搭建和集群配置

  • 一.Redis 下载与单机部署
    • 1.Redis 下载
    • 2.虚拟机配置
    • 3.Redis 单机源码安装和测试
    • 4.Java 单机连接测试
      • 1.Pom 依赖
      • 2.配置文件
      • 3.启动类
      • 4.配置类
      • 5.单元测试
      • 6.测试结果
  • 二.Redis 集群部署
    • 1.主从
      • 1.从节点配置
      • 2.Java 测试
    • 2.哨兵
      • 1.哨兵节点配置
      • 2.复制一个哨兵节点(双哨兵)
      • 3.Java 测试访问哨兵
    • 3.集群
      • 1.集群配置文件修改
      • 2.Java 访问 Redis 集群测试

一.Redis 下载与单机部署

1.Redis 下载

Redis 官网

在这里插入图片描述

2.虚拟机配置

## 1.关闭防火墙
systemctl stop firewalld && systemctl disable firewalld && systemctl status firewalld
## 2.配置域名解析
echo '192.168.1.103 rd1' >> /etc/hosts
echo '192.168.1.104 rd2' >> /etc/hosts
echo '192.168.1.105 rd3' >> /etc/hosts
echo '192.168.1.106 rd4' >> /etc/hosts
echo '192.168.1.107 rd5' >> /etc/hosts
echo '192.168.1.108 rd6' >> /etc/hosts

关闭并禁用防火墙

在这里插入图片描述

3.Redis 单机源码安装和测试

## 1.解压缩
tar zxvf redis-7.2.0.tar.gz
## 2.进入源码安装目录
cd /home/redis-7.2.0/src/
## 3.编译和安装
make && make install PREFIX=/usr/local/redis
## 4.进入Redis解压目录
cd /home/redis-7.2.0/
## 5.修改配置
vim redis.conf
## 6.启动服务
/usr/local/redis/bin/redis-server redis.conf &
## 7.停止服务
kill -9 `ps aux |grep redis|grep -v grep | awk '{print $2}'`

以下行号仅供参考,增加配置后会有微小变动

行号原值新值含义
87bind 127.0.0.1 -::1bind 0.0.0.0 -::1绑定地址
111protected-mode yes#protected-mode no防火墙保护
533replicaof replicaof rd1 6379配置主节点(主从同步)
541masterauth masterauth 123456配置主节点密码(主从同步)
535requirepass 123456密码(在空行添加)

哨兵配置(可在配置哨兵模式时参考)

行号原值新值含义
92sentinel monitor sentinel monitor mymaster 192.168.1.103 6379 1哨兵初始监控的主机地址
112sentinel auth-pass mymaster MySUPER–secret-0123passw0rdsentinel auth-pass mymaster 123456哨兵配置主节点密码(保持所有节点密码一致,避免重新选取主节点后连接失败)
170requirepass requirepass 456789哨兵密码

服务启动

在这里插入图片描述

连接测试

在这里插入图片描述

连接

在这里插入图片描述

4.Java 单机连接测试

1.Pom 依赖

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>org.example</groupId>
    <artifactId>redis-demo</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <maven.compiler.source>20</maven.compiler.source>
        <maven.compiler.target>20</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>3.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-redis</artifactId>
            <version>3.1.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.commons</groupId>
            <artifactId>commons-pool2</artifactId>
            <version>2.11.1</version>
        </dependency>

        <!-- 测试类 -->

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <version>3.1.2</version>
        </dependency>
    </dependencies>
</project>

2.配置文件

spring:
  data:
    redis:
      host: 192.168.1.103
      port: 6379
      password: 123456

3.启动类

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-22 22:28
 */
@SpringBootApplication
public class RedisApp {
    public static void main(String[] args) {
        SpringApplication.run(RedisApp.class,args);
    }
}

4.配置类

package org.example.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-22 22:29
 */
@Component
public class RedisConfig {

    private RedisConnectionFactory redisConnectionFactory;

    @Autowired
    public void setRedisConnectionFactory(RedisConnectionFactory redisConnectionFactory) {
        this.redisConnectionFactory = redisConnectionFactory;
    }

    @Bean(name = "redisTemplate")
    public RedisTemplate<String, Object> redisTemplate(){
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        // 序列化key
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        // 序列化hash
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        // 连接redis数据库
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }
}

5.单元测试

import org.example.RedisApp;
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.test.context.junit4.SpringRunner;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-22 22:29
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = RedisApp.class)
public class TestApp {

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    @Test
    public void test(){
        redisTemplate.opsForValue().set("test","haha");
    }
}

6.测试结果

在这里插入图片描述

查看值

在这里插入图片描述

二.Redis 集群部署

集群信息

HostIP
rd1192.168.1.103
rd2192.168.1.104
rd3192.168.1.105
rd4192.168.1.106
rd5192.168.1.107
rd6192.168.1.108
## 1.将修改后的配置文件复制到安装目录
cp /home/redis-7.2.0/redis.conf /usr/local/redis/

1.主从

1.从节点配置

## 1.将 Redis 包拷贝到 rd2 / rd3
scp -r /usr/local/redis root@rd2:/usr/local/redis
scp -r /usr/local/redis root@rd3:/usr/local/redis
## 2.修改 rd2 / rd3 上 redis.conf 配置增加主节点信息 replicaof rd1 6379 / masterauth 123456
vi /usr/local/redis/redis.conf
## 3.依次启动 rd1 rd2 rd3
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
## 4.客户端连接
/usr/local/redis/bin/redis-cli
## 5.认证
auth 123456

Redis 安装包复制

在这里插入图片描述

增加主节点配置

在这里插入图片描述

主节点启动信息

在这里插入图片描述

从节点启动信息

在这里插入图片描述

查看主从信息

在这里插入图片描述

2.Java 测试

通过上面测试代码写入主节点

在这里插入图片描述

主从模式故障不支持自动恢复,需要人为处理,从节点读需要手动写读取代码

2.哨兵

1.哨兵节点配置

## 1.复制 redis 包到 rd4
scp -r /usr/local/redis root@rd4:/usr/local/redis
## 2.拷贝 sentinel 配置文件
scp -r /home/redis-7.2.0/sentinel.conf root@rd4:/usr/local/redis/
## 3.修改哨兵配置 
# sentinel monitor <master-redis-name> <master-redis-ip> <master-redis-port> <quorum>
# quorum 表示当有多少个 sentinel 认为一个 master 失效时才算真正失效(取值参考 sentinels/2 + 1)
vi /usr/local/redis/sentinel.conf
## 将 92 行修改为 sentinel monitor mymaster 192.168.1.103 6379 1
## 在 112 行增加 sentinel auth-pass mymaster 123456
## 在 170 行增加 requirepass 123456
## 4.启动哨兵
/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel.conf &
## 5.查看信息
/usr/local/redis/bin/redis-cli -p 26379
127.0.0.1:26379> info

修改配置

插入图片描述](https://img-blog.csdnimg.cn/23fad4f11e32475e840313b3320c1ae3.png

哨兵启动信息,注意端口为 26379

图片描述](https://img-blog.csdnimg.cn/0651a222fce84eddbf019df0547b2c72.png

查看哨兵信息

在这里插入图片描述

2.复制一个哨兵节点(双哨兵)

## 1.停止所有节点
kill -9 `ps aux |grep redis|grep -v grep | awk '{print $2}'`
## 2.创建日志目录
mkdir -p logfile /var/log/redis
## 3.修改配置文件 增加日志输出 大概 355 行
vi /usr/local/redis/redis.conf
vi /usr/local/redis/sentinel.conf
## 增加 logfile /var/log/redis/redis.log
## 增加 logfile /var/log/redis/sentinel.log
## 4.复制配置好的哨兵文件到 rd5
scp -r /usr/local/redis root@rd5:/usr/local/redis
## 5.启动 rd1 / rd2 / rd3
/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &
## 6.启动 rd4 / rd5 的哨兵
/usr/local/redis/bin/redis-sentinel /usr/local/redis/sentinel.conf &

3.Java 测试访问哨兵

配置文件

spring:
  data:
    redis:
      password: 123456 # 访问主从节点的密码
      sentinel:
        master: mymaster
        nodes: 192.168.1.106:26379,192.168.1.107:26379
        password: 123456 # 访问哨兵的密码
      lettuce:
        pool:
          max-idle: 50
          min-idle: 10
          max-active: 100
          max-wait: 1000
          
logging:
  level:
    root: info
    io.lettuce.core: debug
    org.springframework.data.redis: debug

配置类

package org.example.config;

import io.lettuce.core.ReadFrom;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.data.redis.RedisProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.data.redis.connection.RedisClusterConfiguration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.connection.RedisSentinelConfiguration;
import org.springframework.data.redis.connection.RedisStandaloneConfiguration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.connection.lettuce.LettucePoolingClientConfiguration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.stereotype.Component;

import java.time.Duration;
import java.util.HashSet;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-22 22:29
 */
@Component
public class RedisConfig {

    /**
     * 配置 Redis 工厂
     * @param properties
     * @return
     */
    @Bean(name = "redisConnectionFactory")
    public RedisConnectionFactory redisConnectionFactory(RedisProperties properties) {

        //取配置
        RedisProperties.Cluster cluster = properties.getCluster();
        RedisProperties.Sentinel sentinel = properties.getSentinel();
        RedisProperties.Pool pool = properties.getLettuce().getPool();
        //池化配置
        LettucePoolingClientConfiguration poolingClientConfiguration = LettucePoolingClientConfiguration.builder().readFrom(ReadFrom.ANY_REPLICA).build();
        if (null != pool){
            if (pool.getMaxIdle() > 0){
                poolingClientConfiguration.getPoolConfig().setMaxIdle(pool.getMaxIdle());
            }
            if (pool.getMinIdle() > 0){
                poolingClientConfiguration.getPoolConfig().setMinIdle(pool.getMinIdle());
            }
            if (pool.getMaxActive() > 0){
                poolingClientConfiguration.getPoolConfig().setMaxTotal(pool.getMaxActive());
            }
            if (pool.getMaxWait().compareTo(Duration.ZERO) > 0){
                poolingClientConfiguration.getPoolConfig().setMaxWait(pool.getMaxWait());
            }
        }
        //Redis 配置
        if (null != cluster){
            //集群
            RedisClusterConfiguration clusterConfiguration = new RedisClusterConfiguration(cluster.getNodes());
            if (null != properties.getPassword()){
                clusterConfiguration.setPassword(properties.getPassword());
            }
            if (null != cluster.getMaxRedirects()){
                clusterConfiguration.setMaxRedirects(cluster.getMaxRedirects());
            }
            return new LettuceConnectionFactory(clusterConfiguration,poolingClientConfiguration);
        } else if (null != sentinel){
            //哨兵
            RedisSentinelConfiguration sentinelConfiguration = new RedisSentinelConfiguration(sentinel.getMaster(),new HashSet<>(sentinel.getNodes()));
            sentinelConfiguration.setSentinelPassword(sentinel.getPassword());
            sentinelConfiguration.setPassword(properties.getPassword());
            //设置从节点读
            return new LettuceConnectionFactory(sentinelConfiguration,poolingClientConfiguration);
        } else {
            //单机
            RedisStandaloneConfiguration config = new RedisStandaloneConfiguration();
            config.setHostName(properties.getHost());
            config.setPort(properties.getPort());
            config.setPassword(properties.getPassword());
            return new LettuceConnectionFactory(config);
        }
    }

    /**
     * redis 配置
     * @param redisConnectionFactory
     * @return
     */
    @Bean(name = "redisTemplate")
    public RedisTemplate<String, Object> redisTemplate(@Qualifier("redisConnectionFactory") RedisConnectionFactory redisConnectionFactory){
        RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
        // 序列化key
        redisTemplate.setKeySerializer(new StringRedisSerializer());
        redisTemplate.setValueSerializer(new StringRedisSerializer());
        // 序列化hash
        redisTemplate.setHashKeySerializer(new StringRedisSerializer());
        redisTemplate.setHashValueSerializer(new StringRedisSerializer());
        // 连接redis数据库
        redisTemplate.setConnectionFactory(redisConnectionFactory);
        return redisTemplate;
    }

}

启动类

package org.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-22 22:28
 */
@SpringBootApplication
public class RedisApp {

    public static void main(String[] args) {
        SpringApplication.run(RedisApp.class,args);
    }
}

测试类

package org.example.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-23 20:13
 */
@RequestMapping("/redis")
@RestController
public class RedisTest {

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/write")
    public void write(String key,String val){
        redisTemplate.opsForValue().set(key,val);
    }

    @GetMapping("/read")
    public void read(String key){
        System.out.println(redisTemplate.opsForValue().get(key));
    }
}

查看主节点:/usr/local/redis/bin/redis-cli -p 26379

在这里插入图片描述

启动服务

在这里插入图片描述

测试写集群:127.0.0.1:8080/redis/write?key=test&val=hello

在这里插入图片描述

写节点:rd3

在这里插入图片描述

读数据:rd2

在这里插入图片描述

杀掉主节点并等待:kill -9 ps aux |grep redis|grep -v grep | awk '{print $2}'

在这里插入图片描述

查看 rd4 哨兵,主节点切为 rd2

这里插入图片描述](https://img-blog.csdnimg.cn/3350f7bb15df4a74bde5c2034fd62771.png

查看 rd5 哨兵,主节点

在这里插入图片描述

写测试:127.0.0.1:8080/redis/write?key=test&val=reHello

在这里插入图片描述

读测试:127.0.0.1:8080/redis/read?key=test

在这里插入图片描述

恢复 rd5 服务:/usr/local/redis/bin/redis-server /usr/local/redis/redis.conf &

在这里插入图片描述

通过 rd1 查看从节点信息

在这里插入图片描述

3.集群

清除之前测试写入的数据
查找持久化文件:find / -type f -name dump.rdb 如果存在也删掉

1.集群配置文件修改

## 1.在 rd1 复制配置文件
cp /home/redis-7.2.0/redis.conf /usr/local/redis/redis-cluster.conf
## 2.编辑
vim /usr/local/redis/redis-cluster.conf
## 设置密码 requirepass 123456
## 关闭保护模式 protected-mode no
## 开启集群 cluster-enabled yes 约1586行
## 设置配置文件 cluster-config-file redis-cluster.conf 约1594行
## 设置超时 cluster-node-timeout 15000 约1600行
## 设置主节点密码 masterauth 123456
## 设置日志 logfile /var/log/redis/redis-cluster.log
## 3.将 redis-cluster.conf 分发到 rd2 / rd3 / rd4 / rd5 / rd6
scp /usr/local/redis/redis-cluster.conf root@rd2:/usr/local/redis/
scp /usr/local/redis/redis-cluster.conf root@rd3:/usr/local/redis/
scp /usr/local/redis/redis-cluster.conf root@rd4:/usr/local/redis/
scp /usr/local/redis/redis-cluster.conf root@rd5:/usr/local/redis/
scp /usr/local/redis/redis-cluster.conf root@rd6:/usr/local/redis/
## 4.依次启动 rd1 / rd2 /rd3 /rd4 /rd5 / rd6
/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster.conf &
## 5.清空已有数据
## 5.创建集群 在任一节点执行
## -a 密码认证,若没写密码无效带这个参数
## --cluster create 创建集群实例列表 IP:PORT IP:PORT IP:PORT IP:PORT IP:PORT IP:PORT
## --cluster-replicas 复制因子1(即每个主节点需2个从节点)
/usr/local/redis/bin/redis-cli -a 123456 --cluster create --cluster-replicas 1 192.168.1.103:6379 192.168.1.104:6379 192.168.1.105:6379 192.168.1.106:6379 192.168.1.107:6379 192.168.1.108:6379

启动所有节点服务

在这里插入图片描述

创建集群:集群至少要三个主节点,

在这里插入图片描述

查看集群信息和集群节点

在这里插入图片描述

新建三台虚拟机

HostIP
rd7192.168.1.109
rd8192.168.1.110
rd9192.168.1.111
## 1.新建三台虚拟机并分发配置 rd7 / rd8 /rd9
scp -r /usr/local/redis root@192.168.1.109:/usr/local/
scp -r /usr/local/redis root@192.168.1.110:/usr/local/
scp -r /usr/local/redis root@192.168.1.111:/usr/local/
## 2.创建日志目录 / 关闭防火墙并禁用
mkdir -p /var/log/redis
systemctl stop firewalld && systemctl disable firewalld
## 3.启动 rd7 / rd8 /rd9
/usr/local/redis/bin/redis-server /usr/local/redis/redis-cluster.conf &
## 4.将新节点添加到当前集群 在 rd1 执行
## -a 密码认证,若没写密码无效带这个参数
## --cluster add-node 创建集群实例列表 IP:PORT IP:PORT IP:PORT IP:PORT IP:PORT IP:PORT
## 要有一个节点为当前集群的节点
## /usr/local/redis/bin/redis-cli -a 123456 --cluster add-node 192.168.1.109:6379 192.168.1.110:6379 192.168.1.111:6379 192.168.1.103:6379

查看集群命令说明:/usr/local/redis/bin/redis-cli --cluster help

在这里插入图片描述

## 添加主节点
/usr/local/redis/bin/redis-cli -a 123456 --cluster add-node 192.168.1.109:6379 192.168.1.103:6379
## 如果 slot 分配不均,可以用如下命令修复集群
## 分配不均报错如下 [ERR] Not all 16384 slots are covered by nodes.
/usr/local/redis/bin/redis-cli -a 123456 --cluster fix 192.168.1.103:6379
## 执行 resharding 指令来为它分配 hash slots
## 执行下面命令后要依次设置移动 slot 的节点 ID 源节点列表,可直接用 all
/usr/local/redis/bin/redis-cli -a 123456 --cluster reshard 192.168.1.103:6379

添加主节点并查看结果(部分截图)

在这里插入图片描述

查看主从节点状态:/usr/local/redis/bin/redis-cli -a 123456 --cluster check 192.168.1.103:6379 | grep ‘M|S’

在这里插入图片描述

## 随机添加从节点,优先添加到从节点少的节点下
/usr/local/redis/bin/redis-cli -a 123456 --cluster add-node 192.168.1.110:6379 192.168.1.103:6379 --cluster-slave
## 添加到指定主节点下(添加到 103 即 rd1 下面)
/usr/local/redis/bin/redis-cli -a 123456 --cluster add-node 192.168.1.111:6379 192.168.1.103:6379 --cluster-slave --cluster-master-id 9e99c815e3660680439261573c5c5b382573cf1c

随机添加

在这里插入图片描述

查看主从节点状态:/usr/local/redis/bin/redis-cli -a 123456 --cluster check 192.168.1.103:6379

在这里插入图片描述

2.Java 访问 Redis 集群测试

配置集群主节点

spring:
  data:
    redis:
      password: 123456 # 访问主从节点的密码
      cluster:
        max-redirects: 10
        nodes: 192.168.1.103:6379,192.168.1.105:6379,192.168.1.108:6379,192.168.1.109:6379
      lettuce:
        pool:
          max-idle: 50
          min-idle: 10
          max-active: 100
          max-wait: 1000
          enabled: true

logging:
  level:
    root: info
    io.lettuce.core: debug
    org.springframework.data.redis: debug

修改插入方法计算 SLOT

package org.example.controller;

import io.lettuce.core.codec.CRC16;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author zhuwd && moon
 * @Description
 * @create 2023-08-23 20:13
 */
@RestController
@RequestMapping("/redis")
public class RedisTest {

    @Autowired
    RedisTemplate<String, Object> redisTemplate;

    private static final int SLOT_S = 16384;

    @GetMapping("/write")
    public void write(String key,String val){
        int slot = CRC16.crc16(key.getBytes())%SLOT_S;
        redisTemplate.opsForValue().set(key,val);
        System.out.println("slot " + slot + " key " + key + " val " + val);
    }

    @GetMapping("/read")
    public void read(String key){
        System.out.println(redisTemplate.opsForValue().get(key));
    }
}

测试插入数据:127.0.0.1:8080/redis/write?key=test&val=reHello

在这里插入图片描述

查看日志插入主节点为 rd3【192.168.1.105】,槽号为 6918

在这里插入图片描述

读数据:127.0.0.1:8080/redis/read?key=test

在这里插入图片描述

从节点 192.168.1.104 为 rd2,查看其是否为 rd3 从节点:/usr/local/redis/bin/redis-cli -a 123456 --cluster check 192.168.1.103:6379

在这里插入图片描述

客户端查看数据

在这里插入图片描述

查看集群槽号 12376 属于 103 节点 rd1

在这里插入图片描述

插入 Key 测试其节点:127.0.0.1:8080/redis/write?key=RedisTJXY&val=12376

在这里插入图片描述

查看客户端数据

在这里插入图片描述

在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/920727.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

tkinter自定义多参数对话框

文章目录 参数对话框自定义参数对话框 参数对话框 tkinter提供了三种参数对话框&#xff0c;用于输出浮点型、整型和字符串&#xff0c;分别是askfloat, askinteger以及askstring&#xff0c;使用方法如下 代码如下 import tkinter as tk from tkinter.simpledialog import *…

使用StreamLold写入 Starrocks报错:Caused by org

问题描述 使用StreamLoad写入Starrocks报错&#xff0c;报这个错误:Caused by: org.apache.http.ProtocolException: Content-Length header already present 代码案例 引入依赖 <!-- Starrocks使用StreamLoad发送Http请求 --><dependency><groupId>or…

三维模型OBJ格式轻量化压缩变形现象分析

三维模型OBJ格式轻量化压缩变形现象分析 三维模型的OBJ格式轻量化压缩是一种常见的处理方法&#xff0c;它可以减小模型文件的体积&#xff0c;提高加载和渲染效率。然而&#xff0c;在进行轻量化压缩过程中&#xff0c;有时会出现模型变形的现象&#xff0c;即压缩后的模型与…

【面试高频题】值得仔细推敲的贪心及其证明

题目描述 这是 LeetCode 上的 「1846. 减小和重新排列数组后的最大元素」 &#xff0c;难度为 「中等」。 Tag : 「贪心」 给你一个正整数数组 arr。 请你对 arr 执行一些操作&#xff08;也可以不进行任何操作&#xff09;&#xff0c;使得数组满足以下条件&#xff1a; arr 中…

Cesium.Entity图片纹理在不同观察角度有不同亮度

Cesium.Entity图片纹理在不同观察角度有不同亮度 测试代码&#xff1a; viewer.entities.add({rectangle: {coordinates: Cesium.Rectangle.fromDegrees(-92.0, 30.0, -76.0, 40.0),material: "../images/rect.png",} }); 测试图片&#xff1a; rect.png 这个图片…

vue 学习笔记 简单实验

1.代码(html) <script src"https://unpkg.com/vuenext" rel"external nofollow" ></script> <div id"counter">Counter: {{ counter }} </div> <script> const Counter {data() {return {counter: 5}} } Vue.cr…

★80交流驱动器通过rs485接口设置速度(附ascii表)

1抓取的数据及解析 2手册上的通信协议及数据帧说明 说明:双向传输项目 3硬件接线注意事项 用的RSJ45端子&#xff0c;双传项目中&#xff0c;一头用的pin6的水晶头子&#xff08;直流离心机上用过是可以的&#xff09;&#xff0c;另一个用的pin8的水晶头子&#xff0c;这里最…

Linux常用命令——dhcrelay命令

在线Linux命令查询工具 dhcrelay 使用dhcrelay命令可以提供中继DHCP和BOOTP请求 补充说明 dhcrelay命令使用dhcrelay命令可以提供中继DHCP和BOOTP请求&#xff0c;从一个没有DHCP服务器的子网直接连接到其它子网内的一个或多个DHCP服务器。该命令在DHCP中继服务器上使用&am…

【MPLS LDP】安全策略

正在备考华为认证的小伙伴应该知道&#xff0c;除了理论知识外&#xff0c;刷题也相当重要&#xff0c;周工这里有一份HCIAHCIP-Datacom带解析的最新题库 点赞留言 即可领取。 LDP协议 安全策略介绍 LDP MD5验证 MD5称为Message-Digest Algorithm 5&#xff0c;是国际标准摘…

面试题(一)

目录 一.@Transactional 原理和常见的坑 前期准备 事务不生效的几种 Case 原理 源码解读 @Transactional 执行机制 private 导致事务不生效原因 异常不匹配原因 两种 @Transactional Spring @Transactional javax.transaction.Transactional 二.@Autowired 和 @R…

EasyExcel实现文件分批次导入

文章目录 EasyExcel引入依赖表结构项目结构DozerUtils工具类实体类StudentController监听类ServiceServiceImplmapper 启动项目测试测试数据PostMan测试 EasyExcel EasyExcel是一个基于Java的、快速、简洁、解决大文件内存溢出的Excel处理工具。 他能让你在不用考虑性能、内存…

智能交通顶会 IEEE ITSC工作 LimSim:长期交互式多场景交通仿真器(已开源)

交通仿真器是自动驾驶技术发展的重要支撑。交通仿真器可以在虚拟环境中仿真各种交通场景和车辆行驶情况&#xff0c;从而提高测试效率、降低测试风险、提高测试准确性和加速开发周期&#xff0c;是自动驾驶技术验证和优化的重要手段之一。 **LimSim是由上海人工智能实验室智能…

怎么把PDF转成Word?需要注意什么事项?

PDF是一种常见的文档格式&#xff0c;但是与Word文档不同&#xff0c;PDF文件通常不能直接编辑。如果您想编辑PDF文件中的文本&#xff0c;或者想将PDF文件转换为Word文档&#xff0c;下面我们就来看一看把PDF转成Word有哪些方法和注意事项。 PDF转Word工具 有许多将PDF转换为…

AndroidStudio升级后总是Read Time Out的解决办法

AndroidStudio升级后在gradle的时候总是Time out&#xff0c;遇到过多次&#xff0c;总结一下解决办法 1、gradle下载超时 在工程目录../gradle/wrapper/gradle-wrapper.properties中找到gradle版本的下载链接&#xff0c;如下图&#xff1a; 将其复制到迅雷里下载&#xff0…

vue和react学哪一个比较有助于以后发展?

前言 首先声明vue和react这两个框架都是很优秀的前端框架&#xff0c;使用的人群下载量上数量也是相当的庞大&#xff0c;这篇文章没有贬低或者攻击任何一个框架的意思&#xff0c;只在于根据答主的问题来对这两个框架做出对比&#xff0c;以方便大家更加清晰的了解到当下vue和…

小迪和小捷的太空之旅——汽车篇

前情提要 书接上回&#xff0c;小迪与小捷接到外星人的委托&#xff0c;前往其母星拿取特殊小硬件。 在这个陌生的星球&#xff0c;小迪和小捷将遇到怎样的故事呢&#xff1f;

flask实现获取到上传的文件--postman实战

python&#xff1a; index_page.route("/upload",methods["POST"]) def upload():f request.files[file]return "request:%s,params:%s,var_a:%s" % (request.method, request.files, f)postman测试 也可以使用curl进行测试&#xff0c;post可…

高防护等级工业RFID读写器

工业环境恶劣&#xff0c;RFID工业读写器要能够在工业领域应用必须满足一定的防护等级&#xff0c;才能避免外界灰尘油污对设备产生影响&#xff0c;因此企业选择一款高防护等级的读写器尤为重要。下面本文就为大家介绍一下工业读写器对应的防护等级&#xff0c;给大家一个参考…

Wireshark数据抓包分析之互联网控制报文协议_ICMP

一、实验目的: 通过使用wireshark抓取的ICMP数据包对这个ICMP控制报文进行分析 二、预备知识&#xff1a; 1.ICMP协议概述&#xff1a;ICMP是Internet Control Message Protocol的缩写&#xff0c;即互联网控制报文协议。它是TCP/IP协议族的一个子协议&#xff0c;用于IP主机、…

c++ qt--页面布局(第五部分)

c qt–页面布局&#xff08;第五部分&#xff09; 一.页面布局 在设计页面的左侧一栏的组件中我们可以看到进行页面布局的一些组件 布局组件的使用 1.水平布局 使用&#xff1a;将别的组件拖到水平布局的组件中即可&#xff0c;可以选择是在哪个位置 2.垂直布局 使用&…