当前位置: 首页 > news >正文

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

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.103port: 6379password: 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;@Autowiredpublic void setRedisConnectionFactory(RedisConnectionFactory redisConnectionFactory) {this.redisConnectionFactory = redisConnectionFactory;}@Bean(name = "redisTemplate")public RedisTemplate<String, Object> redisTemplate(){RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();// 序列化keyredisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setValueSerializer(new StringRedisSerializer());// 序列化hashredisTemplate.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 {@AutowiredRedisTemplate<String, Object> redisTemplate;@Testpublic 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: mymasternodes: 192.168.1.106:26379,192.168.1.107:26379password: 123456 # 访问哨兵的密码lettuce:pool:max-idle: 50min-idle: 10max-active: 100max-wait: 1000logging:level:root: infoio.lettuce.core: debugorg.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<>();// 序列化keyredisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setValueSerializer(new StringRedisSerializer());// 序列化hashredisTemplate.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 {@AutowiredRedisTemplate<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: 10nodes: 192.168.1.103:6379,192.168.1.105:6379,192.168.1.108:6379,192.168.1.109:6379lettuce:pool:max-idle: 50min-idle: 10max-active: 100max-wait: 1000enabled: truelogging:level:root: infoio.lettuce.core: debugorg.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 {@AutowiredRedisTemplate<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

在这里插入图片描述

查看客户端数据

在这里插入图片描述

在这里插入图片描述

相关文章:

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

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.复制一个哨兵…...

Android Retrofit 使用及原理详解~

简介 在 Android 开发中&#xff0c;网络请求是一个极为关键的部分。Retrofit 作为一个强大的网络请求库&#xff0c;能够简化开发流程&#xff0c;提供高效的网络请求能力。本文将深入介绍 Retrofit 的高级使用与原理&#xff0c;帮助读者更全面地理解和应用这一库。 什么是…...

三种主要的云交付服务和安全模型

对于许多企业来说&#xff0c;当今的数字化转型之旅包括一个关键决策&#xff1a;采用符合其需求的云交付服务。 云计算已成为现代 IT 基础设施的主要组成部分&#xff0c;具有从可扩展性到成本效率等诸多优势。然而&#xff0c;与所有技术一样&#xff0c;云也有其自身的网络…...

python爬虫实战(3)--爬取某乎热搜

1. 分析爬取地址 打开某乎首页&#xff0c;点击热榜 这个就是我们需要爬取的地址&#xff0c;取到地址某乎/api/v3/feed/topstory/hot-lists/total?limit50&desktoptrue 定义好请求头&#xff0c;从Accept往下的请求头全部复制&#xff0c;转换成json headers {Accep…...

IPv4,IPv6,TCP,路由

主要回顾一下TCP&#xff0f;IP的传输过程&#xff0c;在这个过程中&#xff0c;做了什么事情 ip : 网际协议,IP协议能让世界上任意两台计算机之间进行通信。 IP协议的三大功能&#xff1a; 寻址和路由传递服务&#xff1a;不可靠&#xff08;尽最大努力交付传输数据包&…...

Java 计算文本相似度

接受一个字符串和一个字符串列表作为参数的 Java 方法&#xff0c;用于计算两个字符串之间的相似度。 方法 import java.util.HashSet; import java.util.List; import java.util.Set;public class StringSimilarity {/*** 计算两个字符串之间的相似度* param str1 第一个字符…...

MySQL 视图

目录 一、视图概述 二、视图的作用和优点 三、视图的使用规则 四、视图操作 1、创建视图 2、查看视图 1&#xff09;查看视图基本信息 2&#xff09;查看视图详细信息 3、修改视图 4、更新视图 5、删除视图 一、视图概述 视图是数据库中的一个虚拟表&#xff0c;同真…...

深入理解回调函数qsort:从入门到模拟实现

&#x1f341;博客主页&#xff1a;江池俊的博客 &#x1f4ab;收录专栏&#xff1a;C语言进阶之路 &#x1f4a1;代码仓库&#xff1a;江池俊的代码仓库 &#x1f3aa;我的社区&#xff1a;GeekHub &#x1f389;欢迎大家点赞&#x1f44d;评论&#x1f4dd;收藏⭐ 文章目录 前…...

【Git基础】获取远程仓库

我们通常从远程服务器克隆一个Git仓库或者将本地仓库初始化为Git仓库。 1 从远程服务器克隆一个Git仓库 $ git clone https://github.com/your-username/your-repo-name你可以自定义其仓库名称&#xff1a; $ git clone https://github.com/your-username/your-repo-name cu…...

chatGPT界面

效果图&#xff1a; 代码&#xff1a; <!DOCTYPE html> <html> <head><title>复选框样式示例</title> </head> <style>* {padding:0;margin: 0;}.chatpdf{display: flex;height: 100vh;flex-direction: row;}.chatpdf .pannel{widt…...

windows一键启动jupyter

windows一键启动jupyter jupyter简介 Jupyter是一个开源的交互式计算环境&#xff0c;主要用于数据分析、数据可视化和科学计算。它的名字来源于三种编程语言的缩写&#xff1a;Julia、Python和R&#xff0c;这三种语言都可以在Jupyter环境中运行。如果您想进行数据分析、科学…...

树形结构的快速生成

背景 相信大家都遇到过树形结构&#xff0c;像是文件列表、多级菜单、评论区的设计等等&#xff0c;我们都发现它有很多层级&#xff0c;第一级可以有多个&#xff0c;下边的每一个层级也可以有多个&#xff1b;有的可以设计成无限层级的&#xff0c;有的只能设计成两级。那么…...

Android笔记(二十七):自定义Dialog实现居中Toast

背景 记录实现符合项目需求的Toast弹窗 具体实现 class MyTipDialog private constructor(val context: Activity): Dialog(context, R.style.MyTipTheme) {val resId ObservableField(0)private val mainHandler Handler(Looper.getMainLooper())init {setCanceledOnTouc…...

css实现文字的渐变,适合大屏

1 在全局写一个全局样式&#xff0c;文字渐变 2 在组件中使用 CSS3利用-webkit-background-clip: text;实现文字渐变效果_css如何把盒子底部的文字变成透明渐变_I俩月亮的博客-CSDN博客 CSS 如何实现文字渐变色 &#xff1f;_css字体颜色渐变_一个水瓶座程序猿.的博客-CSDN博客…...

软考高级系统架构设计师系列论文八十七:论企业应用集成

软考高级系统架构设计师系列论文八十七:论企业应用集成 一、企业应用集成相关知识点二、摘要三、正文四、总结一、企业应用集成相关知识点 软考高级系统架构设计师系列之:企业集成平台技术的应用和架构设计二、摘要 本文讨论了某公司的应用系统集成项目。某公司为了应对市场变…...

C++设计模式之适配器模式

一、适配器模式 适配器模式&#xff08;Adapter Pattern&#xff09;是一种结构型设计模式&#xff0c;用于将一个类的接口转换成另一个类所期望的接口&#xff0c;以便两个类能够协同工作。 适配器模式可以解决现有类接口与所需接口不匹配的问题&#xff0c;使得原本因接口不…...

山西电力市场日前价格预测【2023-08-24】

日前价格预测 预测明日&#xff08;2023-08-24&#xff09;山西电力市场全天平均日前电价为319.98元/MWh。其中&#xff0c;最高日前电价为370.78元/MWh&#xff0c;预计出现在19: 30。最低日前电价为272.42元/MWh&#xff0c;预计出现在12: 45。 价差方向预测 1&#xff1a; 实…...

一文速学-让神经网络不再神秘,一天速学神经网络基础(一)

前言 思索了很久到底要不要出深度学习内容&#xff0c;毕竟在数学建模专栏里边的机器学习内容还有一大半算法没有更新&#xff0c;很多坑都没有填满&#xff0c;而且现在深度学习的文章和学习课程都十分的多&#xff0c;我考虑了很久决定还是得出神经网络系列文章&#xff0c;…...

百度Q2财报:营收341亿元实现加速增长,净利润高速增长44%,增长强劲全线重构

北京时间8月22日&#xff0c;百度发布了截至2023年6月30日的第二季度未经审计的财务报告。第二季度&#xff0c;百度实现营收341亿元&#xff0c;同比增长15%&#xff1b;归属百度的净利润&#xff08;non-GAAP&#xff09;达到80亿元&#xff0c;同比增长44%。营收和利润双双实…...

ARM DIY(二)配置晶振频率

文章目录 前言串口乱码问题定位内核修改晶振频率uboot 修改晶振频率番外篇 前言 上篇文章《ARM DIY 硬件调试》介绍了 DIY ARM 板的基础硬件焊接&#xff0c;包括电源、SOC、SD 卡座等&#xff0c;板子已经可以跑起来了。 但是发现串口乱码&#xff0c;今天就来解决串口乱码问…...

后进先出(LIFO)详解

LIFO 是 Last In, First Out 的缩写&#xff0c;中文译为后进先出。这是一种数据结构的工作原则&#xff0c;类似于一摞盘子或一叠书本&#xff1a; 最后放进去的元素最先出来 -想象往筒状容器里放盘子&#xff1a; &#xff08;1&#xff09;你放进的最后一个盘子&#xff08…...

使用docker在3台服务器上搭建基于redis 6.x的一主两从三台均是哨兵模式

一、环境及版本说明 如果服务器已经安装了docker,则忽略此步骤,如果没有安装,则可以按照一下方式安装: 1. 在线安装(有互联网环境): 请看我这篇文章 传送阵>> 点我查看 2. 离线安装(内网环境):请看我这篇文章 传送阵>> 点我查看 说明&#xff1a;假设每台服务器已…...

谷歌浏览器插件

项目中有时候会用到插件 sync-cookie-extension1.0.0&#xff1a;开发环境同步测试 cookie 至 localhost&#xff0c;便于本地请求服务携带 cookie 参考地址&#xff1a;https://juejin.cn/post/7139354571712757767 里面有源码下载下来&#xff0c;加在到扩展即可使用FeHelp…...

Java 语言特性(面试系列1)

一、面向对象编程 1. 封装&#xff08;Encapsulation&#xff09; 定义&#xff1a;将数据&#xff08;属性&#xff09;和操作数据的方法绑定在一起&#xff0c;通过访问控制符&#xff08;private、protected、public&#xff09;隐藏内部实现细节。示例&#xff1a; public …...

Java如何权衡是使用无序的数组还是有序的数组

在 Java 中,选择有序数组还是无序数组取决于具体场景的性能需求与操作特点。以下是关键权衡因素及决策指南: ⚖️ 核心权衡维度 维度有序数组无序数组查询性能二分查找 O(log n) ✅线性扫描 O(n) ❌插入/删除需移位维护顺序 O(n) ❌直接操作尾部 O(1) ✅内存开销与无序数组相…...

基础测试工具使用经验

背景 vtune&#xff0c;perf, nsight system等基础测试工具&#xff0c;都是用过的&#xff0c;但是没有记录&#xff0c;都逐渐忘了。所以写这篇博客总结记录一下&#xff0c;只要以后发现新的用法&#xff0c;就记得来编辑补充一下 perf 比较基础的用法&#xff1a; 先改这…...

UR 协作机器人「三剑客」:精密轻量担当(UR7e)、全能协作主力(UR12e)、重型任务专家(UR15)

UR协作机器人正以其卓越性能在现代制造业自动化中扮演重要角色。UR7e、UR12e和UR15通过创新技术和精准设计满足了不同行业的多样化需求。其中&#xff0c;UR15以其速度、精度及人工智能准备能力成为自动化领域的重要突破。UR7e和UR12e则在负载规格和市场定位上不断优化&#xf…...

docker 部署发现spring.profiles.active 问题

报错&#xff1a; org.springframework.boot.context.config.InvalidConfigDataPropertyException: Property spring.profiles.active imported from location class path resource [application-test.yml] is invalid in a profile specific resource [origin: class path re…...

视频行为标注工具BehaviLabel(源码+使用介绍+Windows.Exe版本)

前言&#xff1a; 最近在做行为检测相关的模型&#xff0c;用的是时空图卷积网络&#xff08;STGCN&#xff09;&#xff0c;但原有kinetic-400数据集数据质量较低&#xff0c;需要进行细粒度的标注&#xff0c;同时粗略搜了下已有开源工具基本都集中于图像分割这块&#xff0c…...

多元隐函数 偏导公式

我们来推导隐函数 z z ( x , y ) z z(x, y) zz(x,y) 的偏导公式&#xff0c;给定一个隐函数关系&#xff1a; F ( x , y , z ( x , y ) ) 0 F(x, y, z(x, y)) 0 F(x,y,z(x,y))0 &#x1f9e0; 目标&#xff1a; 求 ∂ z ∂ x \frac{\partial z}{\partial x} ∂x∂z​、 …...